Modernize TransactionRateLimitingCallbackTest 85/98485/3
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 13 Nov 2021 18:05:06 +0000 (19:05 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 13 Nov 2021 19:19:33 +0000 (20:19 +0100)
Use assertThrows() and mockito runner.

Change-Id: I8cda7b267ebc923304e5b1b60c42d78a70d17d19
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionRateLimitingCallbackTest.java

index de3a780..1478344 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.Mockito.doReturn;
@@ -19,8 +19,9 @@ import com.google.common.base.Ticker;
 import java.util.concurrent.TimeUnit;
 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;
 
 /**
@@ -28,14 +29,12 @@ import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
  *
  * @author Thomas Pantelis
  */
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class TransactionRateLimitingCallbackTest {
-
     @Mock
     ActorUtils mockContext;
-
     @Mock
     Timer mockTimer;
-
     @Mock
     Ticker mockTicker;
 
@@ -43,7 +42,6 @@ public class TransactionRateLimitingCallbackTest {
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
         doReturn(mockTimer).when(mockContext).getOperationTimer(ActorUtils.COMMIT);
         callback = new TransactionRateLimitingCallback(mockContext);
         TransactionRateLimitingCallback.setTicker(mockTicker);
@@ -85,12 +83,7 @@ public class TransactionRateLimitingCallbackTest {
 
     @Test
     public void testSuccessWithoutRun() {
-        try {
-            callback.success();
-            fail("Expected IllegalStateException");
-        } catch (IllegalStateException e) {
-            // expected
-        }
+        final var ex = assertThrows(IllegalStateException.class, callback::success);
 
         verify(mockTimer, never()).update(anyLong(), any(TimeUnit.class));
     }