Update sal-distributed-datastore tests a bit 61/96761/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 1 Jul 2021 09:30:07 +0000 (11:30 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 1 Jul 2021 10:20:45 +0000 (12:20 +0200)
Use MockitoJUnitRunner and clean up imports/mocking a bit.

Change-Id: I854f95e37e503d28903c8aa83aecafdef4c4c1fa
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
16 files changed:
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/DataTreeNotificationListenerRegistrationActor.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedDataStoreTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedReadWriteTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransactionChainTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedWriteTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHistoryTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistoryTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/DirectTransactionCommitCohortTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohortTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ModuleShardBackendResolverTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/SingleClientHistoryTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapperTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/actors/DataTreeNotificationListenerRegistrationActorTest.java

index 7d9118d..33d2415 100644 (file)
@@ -26,6 +26,7 @@ import scala.concurrent.duration.FiniteDuration;
  * asked to do so via {@link CloseDataTreeNotificationListenerRegistration}.
  */
 public final class DataTreeNotificationListenerRegistrationActor extends AbstractUntypedActor {
+    // FIXME: rework this constant to a duration and its injection
     @VisibleForTesting
     static long killDelay = TimeUnit.MILLISECONDS.convert(5, TimeUnit.SECONDS);
 
index f4a614c..fa8b1ef 100644 (file)
@@ -8,16 +8,15 @@
 package org.opendaylight.controller.cluster.databroker;
 
 import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
 
-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.Mockito;
-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;
@@ -30,13 +29,12 @@ import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransacti
 import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
 import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
-import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ClientBackedDataStoreTest {
 
     private static final ClientIdentifier UNKNOWN_ID = ClientIdentifier.create(
@@ -46,10 +44,8 @@ public class ClientBackedDataStoreTest {
             MemberName.forName("member"), FrontendType.forName("frontend"));
     private static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
 
-    private static final LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0);
-    private static final TransactionIdentifier TRANSACTION_IDENTIFIER = new TransactionIdentifier(HISTORY_ID, 0);
-
-    private static EffectiveModelContext SCHEMA_CONTEXT;
+    private static final TransactionIdentifier TRANSACTION_IDENTIFIER =
+        new TransactionIdentifier(new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0), 0);
 
     @Mock
     private DataStoreClient clientActor;
@@ -66,29 +62,15 @@ public class ClientBackedDataStoreTest {
     @Mock
     private ClientSnapshot clientSnapshot;
 
-    @BeforeClass
-    public static void beforeClass() {
-        SCHEMA_CONTEXT = TestModel.createTestContext();
-    }
-
-    @AfterClass
-    public static void afterClass() {
-        SCHEMA_CONTEXT = null;
-    }
-
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
-        when(actorUtils.getSchemaContext()).thenReturn(SCHEMA_CONTEXT);
-        when(actorUtils.getDatastoreContext()).thenReturn(DatastoreContext.newBuilder().build());
-        when(clientTransaction.getIdentifier()).thenReturn(TRANSACTION_IDENTIFIER);
-        when(clientSnapshot.getIdentifier()).thenReturn(TRANSACTION_IDENTIFIER);
+        doReturn(DatastoreContext.newBuilder().build()).when(actorUtils).getDatastoreContext();
+        doReturn(TRANSACTION_IDENTIFIER).when(clientTransaction).getIdentifier();
+        doReturn(TRANSACTION_IDENTIFIER).when(clientSnapshot).getIdentifier();
 
-        when(clientActor.getIdentifier()).thenReturn(CLIENT_IDENTIFIER);
-        when(clientActor.createTransaction()).thenReturn(clientTransaction);
-        when(clientActor.createLocalHistory()).thenReturn(clientLocalHistory);
-        when(clientActor.createSnapshot()).thenReturn(clientSnapshot);
+        doReturn(clientTransaction).when(clientActor).createTransaction();
+        doReturn(clientLocalHistory).when(clientActor).createLocalHistory();
+        doReturn(clientSnapshot).when(clientActor).createSnapshot();
     }
 
     @Test
@@ -97,7 +79,7 @@ public class ClientBackedDataStoreTest {
                 actorUtils, UNKNOWN_ID, clientActor)) {
             final DOMStoreTransactionChain txChain = clientBackedDataStore.createTransactionChain();
             assertNotNull(txChain);
-            verify(clientActor, Mockito.times(1)).createLocalHistory();
+            verify(clientActor, times(1)).createLocalHistory();
         }
     }
 
@@ -107,7 +89,7 @@ public class ClientBackedDataStoreTest {
                 actorUtils, UNKNOWN_ID, clientActor)) {
             final DOMStoreReadTransaction tx = clientBackedDataStore.newReadOnlyTransaction();
             assertNotNull(tx);
-            verify(clientActor, Mockito.times(1)).createSnapshot();
+            verify(clientActor, times(1)).createSnapshot();
         }
     }
 
@@ -117,7 +99,7 @@ public class ClientBackedDataStoreTest {
                 actorUtils, UNKNOWN_ID, clientActor)) {
             final DOMStoreWriteTransaction tx = clientBackedDataStore.newWriteOnlyTransaction();
             assertNotNull(tx);
-            verify(clientActor, Mockito.times(1)).createTransaction();
+            verify(clientActor, times(1)).createTransaction();
         }
     }
 
@@ -127,7 +109,7 @@ public class ClientBackedDataStoreTest {
                 actorUtils, UNKNOWN_ID, clientActor)) {
             final DOMStoreReadWriteTransaction tx = clientBackedDataStore.newReadWriteTransaction();
             assertNotNull(tx);
-            verify(clientActor, Mockito.times(1)).createTransaction();
+            verify(clientActor, times(1)).createTransaction();
         }
     }
 }
index 1d29ed1..a404030 100644 (file)
@@ -17,13 +17,14 @@ import com.google.common.util.concurrent.FluentFuture;
 import java.util.Optional;
 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.databroker.actors.dds.ClientTransaction;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ClientBackedReadWriteTransactionTest
         extends ClientBackedTransactionTest<ClientBackedReadWriteTransaction> {
     private ClientBackedReadWriteTransaction object;
@@ -32,8 +33,6 @@ public class ClientBackedReadWriteTransactionTest
     private ClientTransaction delegate;
     @Mock
     private NormalizedNode data;
-    @Mock
-    private DOMStoreThreePhaseCommitCohort readyCohort;
 
     @Override
     ClientBackedReadWriteTransaction object() {
@@ -42,10 +41,7 @@ public class ClientBackedReadWriteTransactionTest
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
-        doReturn(readyCohort).when(delegate).ready();
 
         doReturn(immediateTrueFluentFuture()).when(delegate).exists(YangInstanceIdentifier.empty());
         doReturn(immediateFluentFuture(Optional.of(data))).when(delegate).read(YangInstanceIdentifier.empty());
index 3bec183..08daa00 100644 (file)
@@ -7,12 +7,16 @@
  */
 package org.opendaylight.controller.cluster.databroker;
 
-import org.junit.Assert;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.Mockito;
-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;
@@ -23,6 +27,7 @@ import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHist
 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ClientBackedTransactionChainTest {
     private ClientBackedTransactionChain chain;
 
@@ -35,47 +40,44 @@ public class ClientBackedTransactionChainTest {
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         final FrontendIdentifier frontendId = FrontendIdentifier.create(
                 MemberName.forName("member"), FrontendType.forName("frontend"));
         final ClientIdentifier clientId = ClientIdentifier.create(frontendId, 0);
         final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(clientId, 0);
         final TransactionIdentifier transactionId = new TransactionIdentifier(historyId, 0);
 
-        Mockito.when(history.getIdentifier()).thenReturn(historyId);
-        Mockito.when(transaction.getIdentifier()).thenReturn(transactionId);
-        Mockito.when(snapshot.getIdentifier()).thenReturn(transactionId);
-        Mockito.when(history.takeSnapshot()).thenReturn(snapshot);
-        Mockito.when(history.createTransaction()).thenReturn(transaction);
+        doReturn(transactionId).when(transaction).getIdentifier();
+        doReturn(transactionId).when(snapshot).getIdentifier();
+        doReturn(snapshot).when(history).takeSnapshot();
+        doReturn(transaction).when(history).createTransaction();
 
         chain = new ClientBackedTransactionChain(history, false);
     }
 
     @Test
     public void testNewReadOnlyTransaction() {
-        Assert.assertNotNull(chain.newReadOnlyTransaction());
-        Mockito.verify(history).takeSnapshot();
+        assertNotNull(chain.newReadOnlyTransaction());
+        verify(history).takeSnapshot();
     }
 
     @Test
     public void testNewReadWriteTransaction() {
-        Assert.assertNotNull(chain.newReadWriteTransaction());
-        Mockito.verify(history).createTransaction();
+        assertNotNull(chain.newReadWriteTransaction());
+        verify(history).createTransaction();
     }
 
     @Test
     public void testNewWriteOnlyTransaction() {
-        Assert.assertNotNull(chain.newWriteOnlyTransaction());
-        Mockito.verify(history).createTransaction();
+        assertNotNull(chain.newWriteOnlyTransaction());
+        verify(history).createTransaction();
     }
 
     @Test
     public void testClose() {
         chain.newReadOnlyTransaction();
         chain.close();
-        Mockito.verify(snapshot).abort();
-        Mockito.verify(history).close();
+        verify(snapshot).abort();
+        verify(history).close();
     }
 
     @Test
@@ -83,7 +85,7 @@ public class ClientBackedTransactionChainTest {
         chain.snapshotClosed(snapshot);
         // snap is removed, so cannot be aborted
         chain.close();
-        Mockito.verify(snapshot, Mockito.never()).abort();
-        Mockito.verify(history).close();
+        verify(snapshot, never()).abort();
+        verify(history).close();
     }
 }
\ No newline at end of file
index be140eb..9573a3e 100644 (file)
@@ -20,11 +20,11 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier
 import org.opendaylight.controller.cluster.databroker.actors.dds.AbstractClientHandle;
 
 public abstract class ClientBackedTransactionTest<T extends ClientBackedTransaction<?>> {
-    private static FrontendIdentifier FRONTEND_ID = FrontendIdentifier.create(
+    private static final FrontendIdentifier FRONTEND_ID = FrontendIdentifier.create(
             MemberName.forName("member"), FrontendType.forName("frontend"));
     protected static final ClientIdentifier CLIENT_ID = ClientIdentifier.create(FRONTEND_ID, 0);
 
-    private static LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(CLIENT_ID, 0);
+    private static final LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(CLIENT_ID, 0);
     protected static final TransactionIdentifier TRANSACTION_ID = new TransactionIdentifier(HISTORY_ID, 0);
 
     abstract T object();
index 75b3660..21ef896 100644 (file)
@@ -7,17 +7,21 @@
  */
 package org.opendaylight.controller.cluster.databroker;
 
-import org.junit.Assert;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ClientBackedWriteTransactionTest extends ClientBackedTransactionTest<ClientBackedWriteTransaction> {
     private ClientBackedWriteTransaction object;
 
@@ -32,10 +36,8 @@ public class ClientBackedWriteTransactionTest extends ClientBackedTransactionTes
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
-        Mockito.doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
-        Mockito.doReturn(readyCohort).when(delegate).ready();
+        doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
+        doReturn(readyCohort).when(delegate).ready();
 
         object = new ClientBackedWriteTransaction(delegate, null);
     }
@@ -48,25 +50,25 @@ public class ClientBackedWriteTransactionTest extends ClientBackedTransactionTes
     @Test
     public void testWrite() {
         object().write(path, data);
-        Mockito.verify(delegate).write(path, data);
+        verify(delegate).write(path, data);
     }
 
     @Test
     public void testMerge() {
         object().merge(path, data);
-        Mockito.verify(delegate).merge(path, data);
+        verify(delegate).merge(path, data);
     }
 
     @Test
     public void testDelete() {
         object().delete(path);
-        Mockito.verify(delegate).delete(path);
+        verify(delegate).delete(path);
     }
 
     @Test
     public void testReady() {
         final DOMStoreThreePhaseCommitCohort result = object().ready();
-        Assert.assertNotNull(result);
-        Mockito.verify(delegate).ready();
+        assertNotNull(result);
+        verify(delegate).ready();
     }
 }
index 48ac348..8b376f2 100644 (file)
@@ -7,22 +7,22 @@
  */
 package org.opendaylight.controller.cluster.databroker.actors.dds;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.CLIENT_ID;
-import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.TRANSACTION_ID;
 
 import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
 import akka.actor.ActorSystem;
 import com.google.common.primitives.UnsignedLong;
 import java.util.Optional;
-import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mock;
-import org.mockito.Mockito;
 import org.opendaylight.controller.cluster.access.ABIVersion;
 import org.opendaylight.controller.cluster.access.client.AccessClientUtil;
 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
@@ -38,7 +38,7 @@ import scala.concurrent.impl.Promise.DefaultPromise;
 public abstract class AbstractClientHistoryTest<T extends AbstractClientHistory> {
     protected static final String SHARD_NAME = "default";
     protected static final String PERSISTENCE_ID = "per-1";
-    protected static final LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(CLIENT_ID, 1L);
+    protected static final LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(TestUtils.CLIENT_ID, 1L);
 
     @Mock
     private DataTree tree;
@@ -70,62 +70,63 @@ public abstract class AbstractClientHistoryTest<T extends AbstractClientHistory>
 
     @Test
     public void testCreateSnapshotProxy() {
-        final AbstractProxyTransaction snapshotProxy = object().createSnapshotProxy(TRANSACTION_ID, 0L);
-        Assert.assertNotNull(snapshotProxy);
-        Assert.assertNotEquals(TRANSACTION_ID, snapshotProxy.getIdentifier());
+        final AbstractProxyTransaction snapshotProxy = object().createSnapshotProxy(TestUtils.TRANSACTION_ID, 0L);
+        assertNotNull(snapshotProxy);
+        assertNotEquals(TestUtils.TRANSACTION_ID, snapshotProxy.getIdentifier());
     }
 
     @Test
     public void testCreateTransactionProxy() {
-        AbstractProxyTransaction transactionProxy = object().createTransactionProxy(TRANSACTION_ID, 0L);
-        Assert.assertNotNull(transactionProxy);
-        Assert.assertNotEquals(TRANSACTION_ID, transactionProxy.getIdentifier());
+        AbstractProxyTransaction transactionProxy = object().createTransactionProxy(TestUtils.TRANSACTION_ID, 0L);
+        assertNotNull(transactionProxy);
+        assertNotEquals(TestUtils.TRANSACTION_ID, transactionProxy.getIdentifier());
     }
 
     @Test
     public void testState() {
-        Assert.assertEquals(AbstractClientHistory.State.IDLE, object().state());
+        assertEquals(AbstractClientHistory.State.IDLE, object().state());
     }
 
     @Test
     public void testUpdateState() {
         object().updateState(AbstractClientHistory.State.IDLE, AbstractClientHistory.State.CLOSED);
-        Assert.assertEquals(AbstractClientHistory.State.CLOSED, object().state());
+        assertEquals(AbstractClientHistory.State.CLOSED, object().state());
     }
 
     @Test
     public void testDoClose() {
-        object().createTransactionProxy(TRANSACTION_ID, 0L);
+        object().createTransactionProxy(TestUtils.TRANSACTION_ID, 0L);
         object().doClose();
-        Assert.assertEquals(AbstractClientHistory.State.CLOSED, object().state());
+        assertEquals(AbstractClientHistory.State.CLOSED, object().state());
     }
 
     @Test
     public void testGetIdentifier() {
-        Assert.assertEquals(HISTORY_ID, object().getIdentifier());
+        assertEquals(HISTORY_ID, object().getIdentifier());
     }
 
     @Test
     public void testNextTx() {
-        Assert.assertTrue(object().nextTx() + 1 == object().nextTx());
+        assertEquals(object().nextTx() + 1, object().nextTx());
     }
 
     @Test
     public void testResolveShardForPath() {
         final Long shardForPath = object().resolveShardForPath(YangInstanceIdentifier.empty());
-        Assert.assertEquals(0L, shardForPath.longValue());
+        assertNotNull(shardForPath);
+        assertEquals(0L, (long) shardForPath);
     }
 
     @Test
     public void testLocalAbort() {
         object().localAbort(new Throwable());
-        Assert.assertEquals(AbstractClientHistory.State.CLOSED, object().state());
+        assertEquals(AbstractClientHistory.State.CLOSED, object().state());
     }
 
     @Test
     public void testOnProxyDestroyed() {
-        final ProxyHistory proxyHistory = Mockito.mock(ProxyHistory.class);
-        when(proxyHistory.getIdentifier()).thenReturn(HISTORY_ID);
+        final ProxyHistory proxyHistory = mock(ProxyHistory.class);
+        doReturn(HISTORY_ID).when(proxyHistory).getIdentifier();
 
         object().onProxyDestroyed(proxyHistory);
         verify(proxyHistory).getIdentifier();
@@ -134,13 +135,13 @@ public abstract class AbstractClientHistoryTest<T extends AbstractClientHistory>
     @Test
     public void testCreateTransaction() {
         final ClientTransaction transaction = object().createTransaction();
-        Assert.assertNotNull(transaction);
+        assertNotNull(transaction);
     }
 
     @Test
     public void testTakeSnapshot() {
         final ClientSnapshot clientSnapshot = object().takeSnapshot();
-        Assert.assertEquals(object().getIdentifier(), clientSnapshot.getIdentifier().getHistoryId());
+        assertEquals(object().getIdentifier(), clientSnapshot.getIdentifier().getHistoryId());
     }
 
     @Test
@@ -153,10 +154,10 @@ public abstract class AbstractClientHistoryTest<T extends AbstractClientHistory>
                 SHARD_NAME, UnsignedLong.ZERO, Optional.of(tree), 10);
         final ConnectedClientConnection<ShardBackendInfo> newConn = AccessClientUtil.createConnectedConnection(
                 clientActorContext(), cookie, info);
-        object().createSnapshotProxy(TRANSACTION_ID, shard);
+        object().createSnapshotProxy(TestUtils.TRANSACTION_ID, shard);
 
         final HistoryReconnectCohort reconnectCohort = object().startReconnect(newConn);
-        Assert.assertNotNull(reconnectCohort);
+        assertNotNull(reconnectCohort);
     }
 
     @Test
@@ -169,10 +170,10 @@ public abstract class AbstractClientHistoryTest<T extends AbstractClientHistory>
                 SHARD_NAME, UnsignedLong.ZERO, Optional.of(tree), 10);
         final ConnectedClientConnection<ShardBackendInfo> newConn = AccessClientUtil.createConnectedConnection(
                 clientActorContext(), cookie, info);
-        object().createSnapshotProxy(TRANSACTION_ID, shard);
+        object().createSnapshotProxy(TestUtils.TRANSACTION_ID, shard);
 
         final HistoryReconnectCohort reconnectCohort = object().startReconnect(newConn);
-        Assert.assertNull(reconnectCohort);
+        assertNull(reconnectCohort);
     }
 
     protected static ActorUtils createActorUtilsMock(final ActorSystem system, final ActorRef actor) {
@@ -181,7 +182,7 @@ public abstract class AbstractClientHistoryTest<T extends AbstractClientHistory>
         final ActorSelection selection = system.actorSelection(actor.path());
         final PrimaryShardInfo shardInfo = new PrimaryShardInfo(selection, (short) 0);
         promise.success(shardInfo);
-        when(mock.findPrimaryShardAsync(any())).thenReturn(promise.future());
+        doReturn(promise.future()).when(mock).findPrimaryShardAsync(any());
         return mock;
     }
 }
\ No newline at end of file
index 2b23430..2984700 100644 (file)
@@ -7,23 +7,29 @@
  */
 package org.opendaylight.controller.cluster.databroker.actors.dds;
 
-import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.CLIENT_ID;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.endsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
 
 import akka.actor.ActorSystem;
 import akka.testkit.TestProbe;
 import akka.testkit.javadsl.TestKit;
 import org.junit.After;
-import org.junit.Assert;
 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.client.AbstractClientConnection;
 import org.opendaylight.controller.cluster.access.client.AccessClientUtil;
 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ClientLocalHistoryTest extends AbstractClientHistoryTest<ClientLocalHistory> {
     private ActorSystem system;
     private AbstractDataStoreClientBehavior behavior;
@@ -37,14 +43,12 @@ public class ClientLocalHistoryTest extends AbstractClientHistoryTest<ClientLoca
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         system = ActorSystem.apply();
 
         final TestProbe clientContextProbe = new TestProbe(system, "client");
         final TestProbe actorContextProbe = new TestProbe(system, "actor-context");
         clientActorContext = AccessClientUtil.createClientActorContext(
-                system, clientContextProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
+                system, clientContextProbe.ref(), TestUtils.CLIENT_ID, PERSISTENCE_ID);
         final ActorUtils actorUtilsMock = createActorUtilsMock(system, actorContextProbe.ref());
         behavior = new SimpleDataStoreClientBehavior(clientActorContext, actorUtilsMock, SHARD_NAME);
 
@@ -69,21 +73,21 @@ public class ClientLocalHistoryTest extends AbstractClientHistoryTest<ClientLoca
     @Test
     public void testClose() {
         object().close();
-        Assert.assertEquals(AbstractClientHistory.State.CLOSED, object().state());
+        assertEquals(AbstractClientHistory.State.CLOSED, object().state());
     }
 
     @Override
     @Test
     public void testDoCreateTransaction() {
         final ClientTransaction clientTransaction = object().doCreateTransaction();
-        Assert.assertEquals(object().getIdentifier(), clientTransaction.getIdentifier().getHistoryId());
+        assertEquals(object().getIdentifier(), clientTransaction.getIdentifier().getHistoryId());
     }
 
     @Override
     @Test
     public void testOnTransactionAbort() {
         final ClientSnapshot clientSnapshot = object().doCreateSnapshot();
-        Assert.assertTrue(clientSnapshot.abort());
+        assertTrue(clientSnapshot.abort());
     }
 
     @Override
@@ -91,14 +95,14 @@ public class ClientLocalHistoryTest extends AbstractClientHistoryTest<ClientLoca
     public void testCreateHistoryProxy() {
         final AbstractClientConnection<ShardBackendInfo> clientConnection = behavior.getConnection(0L);
         final ProxyHistory historyProxy = object().createHistoryProxy(HISTORY_ID, clientConnection);
-        Assert.assertEquals(object().getIdentifier(), historyProxy.getIdentifier());
+        assertEquals(object().getIdentifier(), historyProxy.getIdentifier());
     }
 
     @Override
     @Test
     public void testDoCreateSnapshot() {
         final ClientSnapshot clientSnapshot = object().doCreateSnapshot();
-        Assert.assertEquals(new TransactionIdentifier(object().getIdentifier(), object().nextTx()).getHistoryId(),
+        assertEquals(new TransactionIdentifier(object().getIdentifier(), object().nextTx()).getHistoryId(),
                 clientSnapshot.getIdentifier().getHistoryId());
     }
 
@@ -110,28 +114,30 @@ public class ClientLocalHistoryTest extends AbstractClientHistoryTest<ClientLoca
         // make transaction ready
         object().onTransactionReady(tx, cohort);
         // state should be set to IDLE
-        Assert.assertEquals(AbstractClientHistory.State.IDLE, object.state());
+        assertEquals(AbstractClientHistory.State.IDLE, object.state());
 
         // complete transaction
         object().onTransactionComplete(tx.getIdentifier());
         // state is still IDLE
-        Assert.assertEquals(AbstractClientHistory.State.IDLE, object.state());
+        assertEquals(AbstractClientHistory.State.IDLE, object.state());
     }
 
     @Override
     @Test
     public void testOnTransactionReady() {
-        final AbstractTransactionCommitCohort result = object().onTransactionReady(
-                object().createTransaction(), cohort);
-        Assert.assertEquals(result, cohort);
+        final AbstractTransactionCommitCohort result = object().onTransactionReady(object().createTransaction(),
+            cohort);
+        assertEquals(result, cohort);
     }
 
     @Override
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void testOnTransactionReadyDuplicate() {
         final ClientTransaction tx = object().createTransaction();
         object().onTransactionReady(tx, cohort);
-        object().onTransactionReady(tx, cohort);
+        final IllegalStateException ise = assertThrows(IllegalStateException.class,
+            () -> object().onTransactionReady(tx, cohort));
+        assertThat(ise.getMessage(), containsString(" is idle when readying transaction "));
     }
 
     @Test
@@ -139,7 +145,7 @@ public class ClientLocalHistoryTest extends AbstractClientHistoryTest<ClientLoca
         object().updateState(AbstractClientHistory.State.IDLE, AbstractClientHistory.State.TX_OPEN);
         final AbstractTransactionCommitCohort transactionCommitCohort =
                 object().onTransactionReady(transaction, cohort);
-        Assert.assertEquals(cohort, transactionCommitCohort);
+        assertEquals(cohort, transactionCommitCohort);
     }
 
     @Test
@@ -147,11 +153,13 @@ public class ClientLocalHistoryTest extends AbstractClientHistoryTest<ClientLoca
         object().updateState(AbstractClientHistory.State.IDLE, AbstractClientHistory.State.CLOSED);
         final AbstractTransactionCommitCohort transactionCommitCohort =
                 object().onTransactionReady(transaction, cohort);
-        Assert.assertEquals(cohort, transactionCommitCohort);
+        assertEquals(cohort, transactionCommitCohort);
     }
 
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void testOnTransactionReadyAndCompleteIdleFail() {
-        object().onTransactionReady(transaction, cohort);
+        final IllegalStateException ise = assertThrows(IllegalStateException.class,
+            () -> object().onTransactionReady(transaction, cohort));
+        assertThat(ise.getMessage(), endsWith(" is idle when readying transaction null"));
     }
 }
index 481c7d7..8b58e15 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.cluster.databroker.actors.dds;
 
+import static org.junit.Assert.assertEquals;
 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.CLIENT_ID;
 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.HISTORY_ID;
 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.TRANSACTION_ID;
@@ -27,11 +28,11 @@ import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import org.junit.After;
-import org.junit.Assert;
 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.ABIVersion;
 import org.opendaylight.controller.cluster.access.client.AbstractClientConnection;
 import org.opendaylight.controller.cluster.access.client.AccessClientUtil;
@@ -48,6 +49,7 @@ import org.opendaylight.controller.cluster.access.commands.TransactionPreCommitS
 import org.opendaylight.controller.cluster.access.concepts.RequestSuccess;
 import org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ClientTransactionCommitCohortTest {
 
     private static final String PERSISTENCE_ID = "per-1";
@@ -61,7 +63,6 @@ public class ClientTransactionCommitCohortTest {
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
         system = ActorSystem.apply();
         final TestProbe clientContextProbe = new TestProbe(system, "clientContext");
         final ClientActorContext context =
@@ -126,8 +127,7 @@ public class ClientTransactionCommitCohortTest {
 
     private void expectCanCommit(final TransactionTester<RemoteProxyTransaction> tester) {
         final ModifyTransactionRequest request = tester.expectTransactionRequest(ModifyTransactionRequest.class);
-        Assert.assertTrue(request.getPersistenceProtocol().isPresent());
-        Assert.assertEquals(PersistenceProtocol.THREE_PHASE, request.getPersistenceProtocol().get());
+        assertEquals(Optional.of(PersistenceProtocol.THREE_PHASE), request.getPersistenceProtocol());
     }
 
     void expectPreCommit(final TransactionTester<?> tester) {
@@ -205,7 +205,7 @@ public class ClientTransactionCommitCohortTest {
                                    final T expectedResult) throws Exception {
         final ListenableFuture<T> result = operation.apply(cohort);
         replySuccess(transactions, expectFunction, replyFunction);
-        Assert.assertEquals(expectedResult, getWithTimeout(result));
+        assertEquals(expectedResult, getWithTimeout(result));
     }
 
     /**
@@ -234,7 +234,7 @@ public class ClientTransactionCommitCohortTest {
         //check future fail
         final ExecutionException exception =
                 assertOperationThrowsException(() -> getWithTimeout(canCommit), ExecutionException.class);
-        Assert.assertEquals(e, exception.getCause());
+        assertEquals(e, exception.getCause());
     }
 
 }
index b543d77..1dd86b0 100644 (file)
@@ -25,8 +25,9 @@ import java.util.Optional;
 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.ABIVersion;
 import org.opendaylight.controller.cluster.access.client.AbstractClientConnection;
 import org.opendaylight.controller.cluster.access.client.AccessClientUtil;
@@ -36,6 +37,7 @@ import org.opendaylight.controller.cluster.access.commands.PersistenceProtocol;
 import org.opendaylight.controller.cluster.access.commands.TransactionCommitSuccess;
 import org.opendaylight.controller.cluster.access.concepts.RequestSuccess;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class DirectTransactionCommitCohortTest {
 
     private static final String PERSISTENCE_ID = "per-1";
@@ -48,7 +50,6 @@ public class DirectTransactionCommitCohortTest {
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
         system = ActorSystem.apply();
         final TestProbe clientContextProbe = new TestProbe(system, "clientContext");
         final ClientActorContext context =
index f68fce4..60408ae 100644 (file)
@@ -14,14 +14,14 @@ import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtil
 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.getWithTimeout;
 
 import com.google.common.util.concurrent.ListenableFuture;
-import org.junit.Assert;
 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;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class EmptyTransactionCommitCohortTest {
-
     @Mock
     private AbstractClientHistory history;
 
@@ -29,7 +29,6 @@ public class EmptyTransactionCommitCohortTest {
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
         cohort = new EmptyTransactionCommitCohort(history, TRANSACTION_ID);
     }
 
@@ -56,7 +55,7 @@ public class EmptyTransactionCommitCohortTest {
     public void testCommit() throws Exception {
         final ListenableFuture<Void> commit = cohort.commit();
         verify(history).onTransactionComplete(TRANSACTION_ID);
-        Assert.assertNull(getWithTimeout(commit));
+        assertNull(getWithTimeout(commit));
     }
 
 }
\ No newline at end of file
index 971330d..ebd96c9 100644 (file)
@@ -7,12 +7,13 @@
  */
 package org.opendaylight.controller.cluster.databroker.actors.dds;
 
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
 
 import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
@@ -21,17 +22,17 @@ import akka.actor.Status;
 import akka.testkit.TestProbe;
 import akka.testkit.javadsl.TestKit;
 import com.google.common.util.concurrent.Uninterruptibles;
-import java.util.Collections;
+import java.util.List;
 import java.util.concurrent.CompletionStage;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
 import org.junit.After;
-import org.junit.Assert;
 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.commands.ConnectClientFailure;
 import org.opendaylight.controller.cluster.access.commands.ConnectClientRequest;
 import org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess;
@@ -52,6 +53,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import scala.concurrent.Promise;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ModuleShardBackendResolverTest {
 
     private static final MemberName MEMBER_NAME = MemberName.forName("member-1");
@@ -73,20 +75,19 @@ public class ModuleShardBackendResolverTest {
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
         system = ActorSystem.apply();
         contextProbe = new TestProbe(system, "context");
 
         shardManagerProbe = new TestProbe(system, "ShardManager");
 
         final ActorUtils actorUtils = createActorUtilsMock(system, contextProbe.ref());
-        when(actorUtils.getShardManager()).thenReturn(shardManagerProbe.ref());
+        doReturn(shardManagerProbe.ref()).when(actorUtils).getShardManager();
 
         moduleShardBackendResolver = new ModuleShardBackendResolver(CLIENT_ID, actorUtils);
-        when(actorUtils.getShardStrategyFactory()).thenReturn(shardStrategyFactory);
-        when(shardStrategyFactory.getStrategy(YangInstanceIdentifier.empty())).thenReturn(shardStrategy);
+        doReturn(shardStrategyFactory).when(actorUtils).getShardStrategyFactory();
+        doReturn(shardStrategy).when(shardStrategyFactory).getStrategy(YangInstanceIdentifier.empty());
         final PrimaryShardInfoFutureCache cache = new PrimaryShardInfoFutureCache();
-        when(actorUtils.getPrimaryShardInfoCache()).thenReturn(cache);
+        doReturn(cache).when(actorUtils).getPrimaryShardInfoCache();
     }
 
     @After
@@ -96,16 +97,16 @@ public class ModuleShardBackendResolverTest {
 
     @Test
     public void testResolveShardForPathNonNullCookie() {
-        when(shardStrategy.findShard(YangInstanceIdentifier.empty())).thenReturn(DefaultShardStrategy.DEFAULT_SHARD);
+        doReturn(DefaultShardStrategy.DEFAULT_SHARD).when(shardStrategy).findShard(YangInstanceIdentifier.empty());
         final Long cookie = moduleShardBackendResolver.resolveShardForPath(YangInstanceIdentifier.empty());
-        Assert.assertEquals(0L, cookie.longValue());
+        assertEquals(0L, (long) cookie);
     }
 
     @Test
     public void testResolveShardForPathNullCookie() {
-        when(shardStrategy.findShard(YangInstanceIdentifier.empty())).thenReturn("foo");
+        doReturn("foo").when(shardStrategy).findShard(YangInstanceIdentifier.empty());
         final Long cookie = moduleShardBackendResolver.resolveShardForPath(YangInstanceIdentifier.empty());
-        Assert.assertEquals(1L, cookie.longValue());
+        assertEquals(1L, (long) cookie);
     }
 
     @Test
@@ -114,13 +115,13 @@ public class ModuleShardBackendResolverTest {
         contextProbe.expectMsgClass(ConnectClientRequest.class);
         final TestProbe backendProbe = new TestProbe(system, "backend");
         final ConnectClientSuccess msg = new ConnectClientSuccess(CLIENT_ID, 0L, backendProbe.ref(),
-                Collections.emptyList(), dataTree, 3);
+                List.of(), dataTree, 3);
         contextProbe.reply(msg);
         final CompletionStage<ShardBackendInfo> stage = moduleShardBackendResolver.getBackendInfo(0L);
         final ShardBackendInfo shardBackendInfo = TestUtils.getWithTimeout(stage.toCompletableFuture());
-        Assert.assertEquals(0L, shardBackendInfo.getCookie().longValue());
-        Assert.assertEquals(dataTree, shardBackendInfo.getDataTree().get());
-        Assert.assertEquals(DefaultShardStrategy.DEFAULT_SHARD, shardBackendInfo.getName());
+        assertEquals(0L, shardBackendInfo.getCookie().longValue());
+        assertEquals(dataTree, shardBackendInfo.getDataTree().get());
+        assertEquals(DefaultShardStrategy.DEFAULT_SHARD, shardBackendInfo.getName());
     }
 
     @Test
@@ -134,7 +135,7 @@ public class ModuleShardBackendResolverTest {
         final ExecutionException caught =
                 TestUtils.assertOperationThrowsException(() -> TestUtils.getWithTimeout(stage.toCompletableFuture()),
                         ExecutionException.class);
-        Assert.assertEquals(cause, caught.getCause());
+        assertEquals(cause, caught.getCause());
     }
 
     @Test
@@ -144,7 +145,7 @@ public class ModuleShardBackendResolverTest {
         contextProbe.expectMsgClass(ConnectClientRequest.class);
         final TestProbe staleBackendProbe = new TestProbe(system, "staleBackend");
         final ConnectClientSuccess msg = new ConnectClientSuccess(CLIENT_ID, 0L, staleBackendProbe.ref(),
-                Collections.emptyList(), dataTree, 3);
+                List.of(), dataTree, 3);
         contextProbe.reply(msg);
         //get backend info
         final ShardBackendInfo staleBackendInfo = TestUtils.getWithTimeout(backendInfo.toCompletableFuture());
@@ -155,11 +156,11 @@ public class ModuleShardBackendResolverTest {
         contextProbe.expectMsgClass(ConnectClientRequest.class);
         final TestProbe refreshedBackendProbe = new TestProbe(system, "refreshedBackend");
         final ConnectClientSuccess msg2 = new ConnectClientSuccess(CLIENT_ID, 1L, refreshedBackendProbe.ref(),
-                Collections.emptyList(), dataTree, 3);
+                List.of(), dataTree, 3);
         contextProbe.reply(msg2);
         final ShardBackendInfo refreshedBackendInfo = TestUtils.getWithTimeout(refreshed.toCompletableFuture());
-        Assert.assertEquals(staleBackendInfo.getCookie(), refreshedBackendInfo.getCookie());
-        Assert.assertEquals(refreshedBackendProbe.ref(), refreshedBackendInfo.getActor());
+        assertEquals(staleBackendInfo.getCookie(), refreshedBackendInfo.getCookie());
+        assertEquals(refreshedBackendProbe.ref(), refreshedBackendInfo.getActor());
     }
 
     @SuppressWarnings("unchecked")
@@ -174,7 +175,7 @@ public class ModuleShardBackendResolverTest {
         final Registration callbackReg = moduleShardBackendResolver.notifyWhenBackendInfoIsStale(mockCallback);
 
         regMessage.getCallback().accept(DefaultShardStrategy.DEFAULT_SHARD);
-        verify(mockCallback, timeout(5000)).accept(Long.valueOf(0));
+        verify(mockCallback, timeout(5000)).accept((long) 0);
 
         reset(mockCallback);
         callbackReg.close();
@@ -190,8 +191,7 @@ public class ModuleShardBackendResolverTest {
         final ActorSelection selection = system.actorSelection(actor.path());
         final PrimaryShardInfo shardInfo = new PrimaryShardInfo(selection, (short) 0);
         promise.success(shardInfo);
-        when(mock.findPrimaryShardAsync(DefaultShardStrategy.DEFAULT_SHARD)).thenReturn(promise.future());
-        when(mock.getClientDispatcher()).thenReturn(system.dispatchers().defaultGlobalDispatcher());
+        doReturn(promise.future()).when(mock).findPrimaryShardAsync(DefaultShardStrategy.DEFAULT_SHARD);
         return mock;
     }
 }
index 361c926..1d68e97 100644 (file)
@@ -7,23 +7,28 @@
  */
 package org.opendaylight.controller.cluster.databroker.actors.dds;
 
-import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.CLIENT_ID;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
 
 import akka.actor.ActorSystem;
 import akka.testkit.TestProbe;
 import akka.testkit.javadsl.TestKit;
 import org.junit.After;
-import org.junit.Assert;
 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.client.AbstractClientConnection;
 import org.opendaylight.controller.cluster.access.client.AccessClientUtil;
 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class SingleClientHistoryTest extends AbstractClientHistoryTest<SingleClientHistory> {
     private ActorSystem system;
     private AbstractDataStoreClientBehavior behavior;
@@ -35,14 +40,12 @@ public class SingleClientHistoryTest extends AbstractClientHistoryTest<SingleCli
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         system = ActorSystem.apply();
 
         final TestProbe clientContextProbe = new TestProbe(system, "client");
         final TestProbe actorContextProbe = new TestProbe(system, "actor-context");
         clientActorContext = AccessClientUtil.createClientActorContext(
-                system, clientContextProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
+                system, clientContextProbe.ref(), TestUtils.CLIENT_ID, PERSISTENCE_ID);
         final ActorUtils actorUtilsMock = createActorUtilsMock(system, actorContextProbe.ref());
         behavior = new SimpleDataStoreClientBehavior(clientActorContext, actorUtilsMock, SHARD_NAME);
 
@@ -68,7 +71,7 @@ public class SingleClientHistoryTest extends AbstractClientHistoryTest<SingleCli
     @Test
     public void testDoCreateTransaction() {
         final ClientTransaction clientTransaction = object().doCreateTransaction();
-        Assert.assertEquals(object().getIdentifier(), clientTransaction.getIdentifier().getHistoryId());
+        assertEquals(object().getIdentifier(), clientTransaction.getIdentifier().getHistoryId());
     }
 
     @Override
@@ -76,14 +79,14 @@ public class SingleClientHistoryTest extends AbstractClientHistoryTest<SingleCli
     public void testCreateHistoryProxy() {
         final AbstractClientConnection<ShardBackendInfo> clientConnection = behavior.getConnection(0L);
         final ProxyHistory historyProxy = object().createHistoryProxy(HISTORY_ID, clientConnection);
-        Assert.assertEquals(object().getIdentifier(), historyProxy.getIdentifier());
+        assertEquals(object().getIdentifier(), historyProxy.getIdentifier());
     }
 
     @Override
     @Test
     public void testDoCreateSnapshot() {
         final ClientSnapshot clientSnapshot = object().doCreateSnapshot();
-        Assert.assertEquals(new TransactionIdentifier(object().getIdentifier(), object().nextTx()).getHistoryId(),
+        assertEquals(new TransactionIdentifier(object().getIdentifier(), object().nextTx()).getHistoryId(),
                 clientSnapshot.getIdentifier().getHistoryId());
     }
 
@@ -97,14 +100,14 @@ public class SingleClientHistoryTest extends AbstractClientHistoryTest<SingleCli
         object().onTransactionComplete(transaction.getIdentifier());
         // it is possible to make transaction ready again
         final AbstractTransactionCommitCohort result = object().onTransactionReady(transaction, cohort);
-        Assert.assertEquals(result, cohort);
+        assertEquals(result, cohort);
     }
 
     @Override
     @Test
     public void testOnTransactionAbort() {
         final ClientSnapshot clientSnapshot = object().doCreateSnapshot();
-        Assert.assertTrue(clientSnapshot.abort());
+        assertTrue(clientSnapshot.abort());
     }
 
     @Override
@@ -112,14 +115,16 @@ public class SingleClientHistoryTest extends AbstractClientHistoryTest<SingleCli
     public void testOnTransactionReady() {
         final AbstractTransactionCommitCohort result = object().onTransactionReady(
                 object().createTransaction(), cohort);
-        Assert.assertEquals(result, cohort);
+        assertEquals(result, cohort);
     }
 
     @Override
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void testOnTransactionReadyDuplicate() {
         final ClientTransaction transaction = object().createTransaction();
         object().onTransactionReady(transaction, cohort);
-        object().onTransactionReady(transaction, cohort);
+        final IllegalStateException ise = assertThrows(IllegalStateException.class,
+            () -> object().onTransactionReady(transaction, cohort));
+        assertThat(ise.getMessage(), startsWith("Duplicate cohort "));
     }
 }
\ No newline at end of file
index 56713c4..128d08a 100644 (file)
@@ -18,8 +18,9 @@ import com.google.common.util.concurrent.SettableFuture;
 import java.util.Optional;
 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.datastore.messages.DataExists;
 import org.opendaylight.controller.cluster.datastore.messages.ReadData;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
@@ -30,6 +31,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import scala.concurrent.Future;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class LocalTransactionContextTest {
 
     @Mock
@@ -45,7 +47,6 @@ public class LocalTransactionContextTest {
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
         localTransactionContext = new LocalTransactionContext(readWriteTransaction, limiter.getIdentifier(),
                 mockReadySupport) {
             @Override
index e899ad0..2683bf7 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.cluster.datastore;
 
 import static org.junit.Assert.assertEquals;
@@ -14,10 +13,12 @@ import static org.mockito.Mockito.mock;
 
 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.datastore.utils.ActorUtils;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class TransactionContextWrapperTest {
     @Mock
     private ActorUtils actorUtils;
@@ -29,7 +30,6 @@ public class TransactionContextWrapperTest {
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
         doReturn(DatastoreContext.newBuilder().build()).when(actorUtils).getDatastoreContext();
         transactionContextWrapper = new TransactionContextWrapper(MockIdentifiers.transactionIdentifier(
             TransactionContextWrapperTest.class, "mock"), actorUtils, "mock");
index 00ad155..0b45d59 100644 (file)
@@ -16,13 +16,15 @@ import akka.testkit.javadsl.TestKit;
 import java.time.Duration;
 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.datastore.AbstractActorTest;
 import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeNotificationListenerRegistration;
 import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeNotificationListenerRegistrationReply;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class DataTreeNotificationListenerRegistrationActorTest extends AbstractActorTest {
     @Mock
     private ListenerRegistration<?> mockListenerReg;
@@ -34,7 +36,6 @@ public class DataTreeNotificationListenerRegistrationActorTest extends AbstractA
 
     @Before
     public void setup() {
-        MockitoAnnotations.initMocks(this);
         DataTreeNotificationListenerRegistrationActor.killDelay = 100;
         kit = new TestKit(getSystem());
     }