2828import com .mongodb .internal .dns .DnsResolver ;
2929import org .junit .jupiter .api .AfterEach ;
3030import org .junit .jupiter .api .Assertions ;
31- import org .junit .jupiter .api .BeforeEach ;
3231import org .junit .jupiter .api .DisplayName ;
3332import org .junit .jupiter .params .ParameterizedTest ;
3433import org .junit .jupiter .params .provider .CsvSource ;
35- import org .mockito .Mock ;
3634
3735import static java .util .Collections .singletonList ;
3836import static org .mockito .ArgumentMatchers .any ;
3937import static org .mockito .ArgumentMatchers .eq ;
4038import static org .mockito .Mockito .mock ;
4139import static org .mockito .Mockito .when ;
42- import static org .mockito .MockitoAnnotations .openMocks ;
4340
4441/**
4542 * See https://github.com/mongodb/specifications/blob/master/source/initial-dns-seedlist-discovery/tests/README.md
4643 */
4744class InitialDnsSeedListDiscoveryProseTest {
4845 private static final String SRV_SERVICE_NAME = "mongodb" ;
4946
50- @ Mock
51- private ClusterableServerFactory serverFactory ;
52-
53- @ Mock
54- private DnsSrvRecordMonitorFactory dnsSrvRecordMonitorFactory ;
55-
5647 private DnsMultiServerCluster cluster ;
5748
58- @ BeforeEach
59- void setUp () throws Exception {
60- try (AutoCloseable ignored = openMocks (this )) {
61- when (serverFactory .getSettings ()).thenReturn (ServerSettings .builder ().build ());
62- when (serverFactory .create (any (Cluster .class ), any (ServerAddress .class ))).thenReturn (mock (ClusterableServer .class ));
63- }
64- }
65-
6649 @ AfterEach
6750 void tearDown () {
6851 if (cluster != null ) {
@@ -118,6 +101,7 @@ private void doTest(final String srvHost, final String resolvedHost, final boole
118101 final DnsResolver dnsResolver = new DefaultDnsResolver ((name , type ) -> singletonList (String .format ("10 5 27017 %s" ,
119102 resolvedHost )));
120103
104+ final DnsSrvRecordMonitorFactory dnsSrvRecordMonitorFactory = mock (DnsSrvRecordMonitorFactory .class );
121105 when (dnsSrvRecordMonitorFactory .create (eq (srvHost ), eq (SRV_SERVICE_NAME ), any (DnsSrvRecordInitializer .class ))).thenAnswer (
122106 invocation -> new DefaultDnsSrvRecordMonitor (srvHost , SRV_SERVICE_NAME , 10 , 10 ,
123107 invocation .getArgument (2 ), clusterId , dnsResolver ));
@@ -127,6 +111,10 @@ private void doTest(final String srvHost, final String resolvedHost, final boole
127111 .requiredClusterType (ClusterType .SHARDED )
128112 .srvHost (srvHost );
129113
114+ final ClusterableServerFactory serverFactory = mock (ClusterableServerFactory .class );
115+ when (serverFactory .getSettings ()).thenReturn (ServerSettings .builder ().build ());
116+ when (serverFactory .create (any (Cluster .class ), any (ServerAddress .class ))).thenReturn (mock (ClusterableServer .class ));
117+
130118 cluster = new DnsMultiServerCluster (clusterId , settingsBuilder .build (),
131119 serverFactory ,
132120 dnsSrvRecordMonitorFactory );
0 commit comments