Clean up use of MockitoAnnotations.initMocks 31/95531/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 19 Mar 2021 08:26:28 +0000 (09:26 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 19 Mar 2021 08:54:48 +0000 (09:54 +0100)
Using MockitoAnnotations.initMocks() is deprecated, use JUnitRunner
in cds-access-client and sal-clustering-commons.

Change-Id: I10b52bfd0a989f722538e3983352c4465f918950
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/AbstractClientActorTest.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/AbstractClientConnectionTest.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/AccessClientUtil.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/ClientActorContextTest.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/ConnectingClientConnectionTest.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/ConnectionEntryTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/QuarantinedMonitorActorTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStoreTest.java

index 889bd58..699e621 100644 (file)
@@ -21,8 +21,6 @@ import org.opendaylight.controller.cluster.access.concepts.MemberName;
 
 /**
  * Abstract base class for client actors and their components.
- *
- * @author Robert Varga
  */
 public abstract class AbstractClientActorTest {
     private static final MemberName MEMBER_NAME = MemberName.forName("member-1");
index 36d97a1..403ecbd 100644 (file)
@@ -28,7 +28,6 @@ import java.util.function.Consumer;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest;
 import org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess;
 import org.opendaylight.controller.cluster.access.commands.TransactionFailure;
@@ -64,7 +63,6 @@ public abstract class AbstractClientConnectionTest<T extends AbstractClientConne
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
         system = ActorSystem.apply();
         backendProbe = new TestProbe(system);
         contextProbe = new TestProbe(system);
index 7521ed6..a19fbfe 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.controller.cluster.access.client;
 
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 
@@ -35,13 +36,13 @@ public final class AccessClientUtil {
 
     public static ClientActorConfig newMockClientActorConfig() {
         ClientActorConfig mockConfig = mock(ClientActorConfig.class);
-        doReturn(2_000_000).when(mockConfig).getMaximumMessageSliceSize();
-        doReturn(1_000_000_000).when(mockConfig).getFileBackedStreamingThreshold();
-        doReturn(AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS)
-                .when(mockConfig).getBackendAlivenessTimerInterval();
+        lenient().doReturn(2_000_000).when(mockConfig).getMaximumMessageSliceSize();
+        lenient().doReturn(1_000_000_000).when(mockConfig).getFileBackedStreamingThreshold();
         doReturn(AbstractClientConnection.DEFAULT_REQUEST_TIMEOUT_NANOS).when(mockConfig).getRequestTimeout();
-        doReturn(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS)
-                 .when(mockConfig).getNoProgressTimeout();
+        lenient().doReturn(AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS)
+            .when(mockConfig).getBackendAlivenessTimerInterval();
+        lenient().doReturn(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS)
+            .when(mockConfig).getNoProgressTimeout();
         return mockConfig;
     }
 
index 7df1c2f..1eca0b5 100644 (file)
@@ -17,14 +17,16 @@ import java.util.concurrent.TimeUnit;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
 import scala.concurrent.duration.FiniteDuration;
 
+@RunWith(MockitoJUnitRunner.class)
 public class ClientActorContextTest {
     private static final MemberName MEMBER_NAME = MemberName.forName("member-1");
     private static final FrontendType FRONTEND_TYPE =
@@ -41,7 +43,6 @@ public class ClientActorContextTest {
 
     @Before
     public void setup() {
-        MockitoAnnotations.initMocks(this);
         system = ActorSystem.apply();
         probe = new TestProbe(system);
         ctx = new ClientActorContext(probe.ref(), PERSISTENCE_ID, system,
index d0ffa02..d566e0e 100644 (file)
@@ -33,9 +33,10 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.controller.cluster.access.ABIVersion;
 import org.opendaylight.controller.cluster.access.concepts.AbstractRequestFailureProxy;
 import org.opendaylight.controller.cluster.access.concepts.AbstractRequestProxy;
@@ -52,9 +53,8 @@ import scala.concurrent.duration.FiniteDuration;
 /**
  * Test suite covering logic contained in {@link ConnectingClientConnection}. It assumes {@link ConnectionEntryTest}
  * passes.
- *
- * @author Robert Varga
  */
+@RunWith(MockitoJUnitRunner.class)
 public class ConnectingClientConnectionTest {
     private static class MockFailure extends RequestFailure<WritableIdentifier, MockFailure> {
         private static final long serialVersionUID = 1L;
@@ -136,8 +136,6 @@ public class ConnectingClientConnectionTest {
 
     @Before
     public void setup() {
-        MockitoAnnotations.initMocks(this);
-
         doNothing().when(mockCallback).accept(any(MockFailure.class));
 
         ticker = new FakeTicker();
index 1bb921c..2d1afb8 100644 (file)
@@ -22,8 +22,9 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.controller.cluster.access.ABIVersion;
 import org.opendaylight.controller.cluster.access.concepts.AbstractRequestFailureProxy;
 import org.opendaylight.controller.cluster.access.concepts.AbstractRequestProxy;
@@ -35,9 +36,8 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier;
 
 /**
  * Test suite covering logic contained in {@link ConnectionEntry}.
- *
- * @author Robert Varga
  */
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ConnectionEntryTest {
     private static class MockFailure extends RequestFailure<WritableIdentifier, MockFailure> {
         private static final long serialVersionUID = 1L;
@@ -113,8 +113,6 @@ public class ConnectionEntryTest {
 
     @Before
     public void setup() {
-        MockitoAnnotations.initMocks(this);
-
         doNothing().when(mockCallback).accept(any(MockFailure.class));
 
         ticker = new FakeTicker();
index caffa69..fd223e2 100644 (file)
@@ -23,10 +23,12 @@ import akka.testkit.javadsl.TestKit;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import scala.Option;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class QuarantinedMonitorActorTest {
 
     private static final Address LOCAL = Address.apply("http", "local");
@@ -39,7 +41,6 @@ public class QuarantinedMonitorActorTest {
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
         system = ActorSystem.apply();
         actor = system.actorOf(QuarantinedMonitorActor.props(callback));
     }
@@ -90,5 +91,4 @@ public class QuarantinedMonitorActorTest {
         actor.tell(event, ActorRef.noSender());
         verify(callback, never()).apply();
     }
-
 }
\ No newline at end of file
index 7115dd8..8531501 100644 (file)
@@ -42,7 +42,8 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.mockito.MockitoAnnotations;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
 import scala.Option;
 
 /**
@@ -51,6 +52,7 @@ import scala.Option;
  *
  * @author Thomas Pantelis
  */
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class LocalSnapshotStoreTest {
     private static final String PERSISTENCE_ID = "member-1-shard-default-config";
     private static final String PREFIX_BASED_SHARD_PERSISTENCE_ID = "member-1-shard-id-ints!-config";
@@ -74,7 +76,6 @@ public class LocalSnapshotStoreTest {
 
     @Before
     public void setup() {
-        MockitoAnnotations.initMocks(this);
         cleanSnapshotDir();
     }
 

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.