Skip to content

Commit 540b89e

Browse files
replace Mock annotation usage with method scope local Mockito.mock() invocation
1 parent 2cb640e commit 540b89e

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

driver-core/src/test/unit/com/mongodb/internal/connection/InitialDnsSeedListDiscoveryProseTest.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,24 @@
2828
import com.mongodb.internal.dns.DnsResolver;
2929
import org.junit.jupiter.api.AfterEach;
3030
import org.junit.jupiter.api.Assertions;
31-
import org.junit.jupiter.api.BeforeEach;
3231
import org.junit.jupiter.api.DisplayName;
3332
import org.junit.jupiter.params.ParameterizedTest;
3433
import org.junit.jupiter.params.provider.CsvSource;
35-
import org.mockito.Mock;
3634

3735
import static java.util.Collections.singletonList;
3836
import static org.mockito.ArgumentMatchers.any;
3937
import static org.mockito.ArgumentMatchers.eq;
4038
import static org.mockito.Mockito.mock;
4139
import 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
*/
4744
class 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

Comments
 (0)