From 514df5b3d350482fee8ee8f1f5b257c229f7e61a Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 1 Jul 2021 11:30:07 +0200 Subject: [PATCH] Update sal-distributed-datastore tests a bit Use MockitoJUnitRunner and clean up imports/mocking a bit. Change-Id: I854f95e37e503d28903c8aa83aecafdef4c4c1fa Signed-off-by: Robert Varga --- ...NotificationListenerRegistrationActor.java | 1 + .../databroker/ClientBackedDataStoreTest.java | 52 ++++++---------- .../ClientBackedReadWriteTransactionTest.java | 10 +--- .../ClientBackedTransactionChainTest.java | 42 ++++++------- .../ClientBackedTransactionTest.java | 4 +- .../ClientBackedWriteTransactionTest.java | 26 ++++---- .../actors/dds/AbstractClientHistoryTest.java | 59 ++++++++++--------- .../actors/dds/ClientLocalHistoryTest.java | 52 +++++++++------- .../ClientTransactionCommitCohortTest.java | 14 ++--- .../DirectTransactionCommitCohortTest.java | 5 +- .../dds/EmptyTransactionCommitCohortTest.java | 9 ++- .../dds/ModuleShardBackendResolverTest.java | 50 ++++++++-------- .../actors/dds/SingleClientHistoryTest.java | 33 ++++++----- .../LocalTransactionContextTest.java | 5 +- .../TransactionContextWrapperTest.java | 6 +- ...ficationListenerRegistrationActorTest.java | 5 +- 16 files changed, 186 insertions(+), 187 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/DataTreeNotificationListenerRegistrationActor.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/DataTreeNotificationListenerRegistrationActor.java index 7d9118dfbe..33d2415682 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/DataTreeNotificationListenerRegistrationActor.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/DataTreeNotificationListenerRegistrationActor.java @@ -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); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedDataStoreTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedDataStoreTest.java index f4a614c030..fa8b1ef993 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedDataStoreTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedDataStoreTest.java @@ -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(); } } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedReadWriteTransactionTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedReadWriteTransactionTest.java index 1d29ed1b80..a404030f0e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedReadWriteTransactionTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedReadWriteTransactionTest.java @@ -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 { 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()); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransactionChainTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransactionChainTest.java index 3bec183574..08daa004f2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransactionChainTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransactionChainTest.java @@ -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 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransactionTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransactionTest.java index be140eb625..9573a3ed30 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransactionTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedTransactionTest.java @@ -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> { - 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(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedWriteTransactionTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedWriteTransactionTest.java index 75b36602e7..21ef8967ae 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedWriteTransactionTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedWriteTransactionTest.java @@ -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 { 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(); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHistoryTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHistoryTest.java index 48ac3484f7..8b376f2dd0 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHistoryTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHistoryTest.java @@ -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 { 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 @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 @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 SHARD_NAME, UnsignedLong.ZERO, Optional.of(tree), 10); final ConnectedClientConnection 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 SHARD_NAME, UnsignedLong.ZERO, Optional.of(tree), 10); final ConnectedClientConnection 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 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 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistoryTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistoryTest.java index 2b23430400..298470021e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistoryTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientLocalHistoryTest.java @@ -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 { private ActorSystem system; private AbstractDataStoreClientBehavior behavior; @@ -37,14 +43,12 @@ public class ClientLocalHistoryTest extends AbstractClientHistoryTest 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 object().onTransactionReady(tx, cohort)); + assertThat(ise.getMessage(), containsString(" is idle when readying transaction ")); } @Test @@ -139,7 +145,7 @@ public class ClientLocalHistoryTest extends AbstractClientHistoryTest object().onTransactionReady(transaction, cohort)); + assertThat(ise.getMessage(), endsWith(" is idle when readying transaction null")); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java index 481c7d7531..8b58e15877 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java @@ -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 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 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()); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/DirectTransactionCommitCohortTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/DirectTransactionCommitCohortTest.java index b543d77221..1dd86b0028 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/DirectTransactionCommitCohortTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/DirectTransactionCommitCohortTest.java @@ -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 = diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohortTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohortTest.java index f68fce4e23..60408ae149 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohortTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohortTest.java @@ -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 commit = cohort.commit(); verify(history).onTransactionComplete(TRANSACTION_ID); - Assert.assertNull(getWithTimeout(commit)); + assertNull(getWithTimeout(commit)); } } \ No newline at end of file diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ModuleShardBackendResolverTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ModuleShardBackendResolverTest.java index 971330d0c5..ebd96c9741 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ModuleShardBackendResolverTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ModuleShardBackendResolverTest.java @@ -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 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; } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/SingleClientHistoryTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/SingleClientHistoryTest.java index 361c9267e0..1d68e979db 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/SingleClientHistoryTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/SingleClientHistoryTest.java @@ -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 { private ActorSystem system; private AbstractDataStoreClientBehavior behavior; @@ -35,14 +40,12 @@ public class SingleClientHistoryTest extends AbstractClientHistoryTest 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 object().onTransactionReady(transaction, cohort)); + assertThat(ise.getMessage(), startsWith("Duplicate cohort ")); } } \ No newline at end of file diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java index 56713c4cf2..128d08a4d9 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java @@ -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 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapperTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapperTest.java index e899ad0f28..2683bf7e25 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapperTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapperTest.java @@ -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"); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/actors/DataTreeNotificationListenerRegistrationActorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/actors/DataTreeNotificationListenerRegistrationActorTest.java index 00ad155425..0b45d595c0 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/actors/DataTreeNotificationListenerRegistrationActorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/actors/DataTreeNotificationListenerRegistrationActorTest.java @@ -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()); } -- 2.36.6