Cleanup Local*ProxyTransactionTest 76/100776/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 24 Apr 2022 16:26:06 +0000 (18:26 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 24 Apr 2022 16:42:31 +0000 (18:42 +0200)
Do not use expected exceptions and use static imports for asserts.

Change-Id: Ib7838b36683b9e1d2042f1832272b88a0195cef6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalProxyTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadOnlyProxyTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransactionTest.java

index 283913f..58f05fd 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.cluster.databroker.actors.dds;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
@@ -17,7 +19,6 @@ import akka.testkit.TestProbe;
 import com.google.common.base.Ticker;
 import java.util.Optional;
 import java.util.function.Consumer;
-import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.mockito.invocation.InvocationOnMock;
@@ -64,7 +65,7 @@ public abstract class LocalProxyTransactionTest<T extends LocalProxyTransaction>
     @SuppressWarnings("unchecked")
     private void setupExecuteInActor() {
         doAnswer(inv -> {
-            inv.<InternalCommand<?>>getArgument(0).execute(mock(ClientActorBehavior.class));
+            inv.getArgument(0, InternalCommand.class).execute(mock(ClientActorBehavior.class));
             return null;
         }).when(context).executeInActor(any(InternalCommand.class));
     }
@@ -81,10 +82,10 @@ public abstract class LocalProxyTransactionTest<T extends LocalProxyTransaction>
         final ArgumentCaptor<Response<?, ?>> captor = ArgumentCaptor.forClass(Response.class);
         verify(callback).accept(captor.capture());
         final Response<?, ?> value = captor.getValue();
-        Assert.assertTrue(value instanceof ReadTransactionSuccess);
+        assertTrue(value instanceof ReadTransactionSuccess);
         final ReadTransactionSuccess success = (ReadTransactionSuccess) value;
-        Assert.assertTrue(success.getData().isPresent());
-        Assert.assertEquals(DATA_1, success.getData().get());
+        assertTrue(success.getData().isPresent());
+        assertEquals(DATA_1, success.getData().get());
     }
 
     @Test
@@ -99,16 +100,15 @@ public abstract class LocalProxyTransactionTest<T extends LocalProxyTransaction>
         final ArgumentCaptor<Response<?, ?>> captor = ArgumentCaptor.forClass(Response.class);
         verify(callback).accept(captor.capture());
         final Response<?, ?> value = captor.getValue();
-        Assert.assertTrue(value instanceof ExistsTransactionSuccess);
+        assertTrue(value instanceof ExistsTransactionSuccess);
         final ExistsTransactionSuccess success = (ExistsTransactionSuccess) value;
-        Assert.assertTrue(success.getExists());
+        assertTrue(success.getExists());
     }
 
     @Test
     public void testHandleForwardedRemotePurgeRequest() {
         final TestProbe probe = createProbe();
-        final TransactionPurgeRequest request =
-                new TransactionPurgeRequest(TRANSACTION_ID, 0L, probe.ref());
+        final TransactionPurgeRequest request = new TransactionPurgeRequest(TRANSACTION_ID, 0L, probe.ref());
         testHandleForwardedRemoteRequest(request);
     }
 
@@ -118,8 +118,8 @@ public abstract class LocalProxyTransactionTest<T extends LocalProxyTransaction>
         final TestProbe probe = createProbe();
         final AbortLocalTransactionRequest request = new AbortLocalTransactionRequest(TRANSACTION_ID, probe.ref());
         final ModifyTransactionRequest modifyRequest = testForwardToRemote(request, ModifyTransactionRequest.class);
-        Assert.assertTrue(modifyRequest.getPersistenceProtocol().isPresent());
-        Assert.assertEquals(PersistenceProtocol.ABORT, modifyRequest.getPersistenceProtocol().get());
+        assertTrue(modifyRequest.getPersistenceProtocol().isPresent());
+        assertEquals(PersistenceProtocol.ABORT, modifyRequest.getPersistenceProtocol().get());
     }
 
     @Override
@@ -132,8 +132,8 @@ public abstract class LocalProxyTransactionTest<T extends LocalProxyTransaction>
         doAnswer(LocalProxyTransactionTest::applyToCursorAnswer).when(modification).applyToCursor(any());
         final ModifyTransactionRequest modifyRequest = testForwardToRemote(request, ModifyTransactionRequest.class);
         verify(modification).applyToCursor(any());
-        Assert.assertTrue(modifyRequest.getPersistenceProtocol().isPresent());
-        Assert.assertEquals(PersistenceProtocol.THREE_PHASE, modifyRequest.getPersistenceProtocol().get());
+        assertTrue(modifyRequest.getPersistenceProtocol().isPresent());
+        assertEquals(PersistenceProtocol.THREE_PHASE, modifyRequest.getPersistenceProtocol().get());
         checkModifications(modifyRequest);
     }
 
@@ -152,7 +152,7 @@ public abstract class LocalProxyTransactionTest<T extends LocalProxyTransaction>
     }
 
     protected <R extends TransactionRequest<R>> R testForwardToLocal(final TransactionRequest<?> toForward,
-                                                                  final Class<R> expectedMessageClass) {
+                                                                     final Class<R> expectedMessageClass) {
         final Consumer<Response<?, ?>> callback = createCallbackMock();
         final TransactionTester<LocalReadWriteProxyTransaction> transactionTester = createLocalProxy();
         final LocalReadWriteProxyTransaction successor = transactionTester.getTransaction();
index 5f33439..651c7d2 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.controller.cluster.databroker.actors.dds;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.when;
 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.assertOperationThrowsException;
 
@@ -14,7 +17,6 @@ import akka.testkit.TestProbe;
 import com.google.common.base.Ticker;
 import com.google.common.base.VerifyException;
 import java.util.Optional;
-import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest;
 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest;
@@ -38,74 +40,76 @@ public class LocalReadOnlyProxyTransactionTest extends LocalProxyTransactionTest
 
     @Test
     public void testIsSnapshotOnly() {
-        Assert.assertTrue(transaction.isSnapshotOnly());
+        assertTrue(transaction.isSnapshotOnly());
     }
 
     @Test
     public void testReadOnlyView() {
-        Assert.assertEquals(snapshot, transaction.readOnlyView());
+        assertEquals(snapshot, transaction.readOnlyView());
     }
 
+    @Test
     @Override
-    @Test(expected = UnsupportedOperationException.class)
     public void testDirectCommit() {
-        transaction.directCommit();
+        assertThrows(UnsupportedOperationException.class, () -> transaction.directCommit());
     }
 
+    @Test
     @Override
-    @Test(expected = UnsupportedOperationException.class)
     public void testCanCommit() {
-        transaction.canCommit(new VotingFuture<>(new Object(), 1));
+        assertThrows(UnsupportedOperationException.class,
+            () -> transaction.canCommit(new VotingFuture<>(new Object(), 1)));
     }
 
+    @Test
     @Override
-    @Test(expected = UnsupportedOperationException.class)
     public void testPreCommit() {
-        transaction.preCommit(new VotingFuture<>(new Object(), 1));
+        assertThrows(UnsupportedOperationException.class,
+            () -> transaction.preCommit(new VotingFuture<>(new Object(), 1)));
     }
 
+    @Test
     @Override
-    @Test(expected = UnsupportedOperationException.class)
     public void testDoCommit() {
-        transaction.doCommit(new VotingFuture<>(new Object(), 1));
+        assertThrows(UnsupportedOperationException.class,
+            () -> transaction.doCommit(new VotingFuture<>(new Object(), 1)));
     }
 
+    @Test
     @Override
-    @Test(expected = UnsupportedOperationException.class)
     public void testDelete() {
-        transaction.delete(PATH_1);
+        assertThrows(UnsupportedOperationException.class, () -> transaction.delete(PATH_1));
     }
 
     @Override
-    @Test(expected = UnsupportedOperationException.class)
     public void testMerge() {
-        transaction.merge(PATH_1, DATA_1);
+        assertThrows(UnsupportedOperationException.class, () -> transaction.merge(PATH_1, DATA_1));
     }
 
+    @Test
     @Override
-    @Test(expected = UnsupportedOperationException.class)
     public void testWrite() {
-        transaction.write(PATH_1, DATA_1);
+        assertThrows(UnsupportedOperationException.class, () -> transaction.write(PATH_1, DATA_1));
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void testDoDelete() {
-        transaction.doDelete(PATH_1);
+        assertThrows(UnsupportedOperationException.class, () -> transaction.doDelete(PATH_1));
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void testDoMerge() {
-        transaction.doMerge(PATH_1, DATA_1);
+        assertThrows(UnsupportedOperationException.class, () -> transaction.doMerge(PATH_1, DATA_1));
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void testDoWrite() {
-        transaction.doWrite(PATH_1, DATA_1);
+        assertThrows(UnsupportedOperationException.class, () -> transaction.doWrite(PATH_1, DATA_1));
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void testCommitRequest() {
-        transaction.commitRequest(true);
+        assertThrows(UnsupportedOperationException.class, () -> transaction.commitRequest(true));
     }
 
     @Test
index 349e227..dbcdd59 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.cluster.databroker.actors.dds;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
@@ -20,7 +22,6 @@ import com.google.common.base.Ticker;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Optional;
 import java.util.function.Consumer;
-import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest;
@@ -60,12 +61,12 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes
 
     @Test
     public void testIsSnapshotOnly() {
-        Assert.assertFalse(transaction.isSnapshotOnly());
+        assertFalse(transaction.isSnapshotOnly());
     }
 
     @Test
     public void testReadOnlyView() {
-        Assert.assertEquals(modification, transaction.readOnlyView());
+        assertEquals(modification, transaction.readOnlyView());
     }
 
     @Test
@@ -125,8 +126,8 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes
         transaction.doWrite(PATH_1, DATA_1);
         final boolean coordinated = true;
         final CommitLocalTransactionRequest request = transaction.commitRequest(coordinated);
-        Assert.assertEquals(coordinated, request.isCoordinated());
-        Assert.assertEquals(modification, request.getModification());
+        assertEquals(coordinated, request.isCoordinated());
+        assertEquals(modification, request.getModification());
     }
 
     @Test
@@ -141,7 +142,7 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes
     public void testSealOnly() throws Exception {
         assertOperationThrowsException(() -> transaction.getSnapshot(), IllegalStateException.class);
         transaction.sealOnly();
-        Assert.assertEquals(modification, transaction.getSnapshot());
+        assertEquals(modification, transaction.getSnapshot());
     }
 
     @Test
@@ -244,8 +245,8 @@ public class LocalReadWriteProxyTransactionTest extends LocalProxyTransactionTes
         verify(modification).delete(PATH_3);
         final CommitLocalTransactionRequest commitRequest =
                 getTester().expectTransactionRequest(CommitLocalTransactionRequest.class);
-        Assert.assertEquals(modification, commitRequest.getModification());
-        Assert.assertEquals(coordinated, commitRequest.isCoordinated());
+        assertEquals(modification, commitRequest.getModification());
+        assertEquals(coordinated, commitRequest.isCoordinated());
     }
 
 }