Clean up use of MockitoAnnotations.initMocks
[controller.git] / opendaylight / md-sal / cds-access-client / src / test / java / org / opendaylight / controller / cluster / access / client / ConnectingClientConnectionTest.java
index 88e50e2f48f526f003f00bf2a48ea010bc22750d..d566e0ec3b4f515903fa8894862bae9bb978a33e 100644 (file)
@@ -13,7 +13,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -24,7 +24,7 @@ import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.testkit.TestProbe;
 import com.google.common.testing.FakeTicker;
-import java.util.Optional;
+import java.util.OptionalLong;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
@@ -33,9 +33,10 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.controller.cluster.access.ABIVersion;
 import org.opendaylight.controller.cluster.access.concepts.AbstractRequestFailureProxy;
 import org.opendaylight.controller.cluster.access.concepts.AbstractRequestProxy;
@@ -52,9 +53,8 @@ import scala.concurrent.duration.FiniteDuration;
 /**
  * Test suite covering logic contained in {@link ConnectingClientConnection}. It assumes {@link ConnectionEntryTest}
  * passes.
- *
- * @author Robert Varga
  */
+@RunWith(MockitoJUnitRunner.class)
 public class ConnectingClientConnectionTest {
     private static class MockFailure extends RequestFailure<WritableIdentifier, MockFailure> {
         private static final long serialVersionUID = 1L;
@@ -136,8 +136,6 @@ public class ConnectingClientConnectionTest {
 
     @Before
     public void setup() {
-        MockitoAnnotations.initMocks(this);
-
         doNothing().when(mockCallback).accept(any(MockFailure.class));
 
         ticker = new FakeTicker();
@@ -150,14 +148,14 @@ public class ConnectingClientConnectionTest {
         doReturn(mock(MessageSlicer.class)).when(mockContext).messageSlicer();
 
         mockActor = TestProbe.apply(actorSystem);
-        mockBackendInfo = new BackendInfo(mockActor.ref(), 0, ABIVersion.current(), 5);
+        mockBackendInfo = new BackendInfo(mockActor.ref(), "test", 0, ABIVersion.current(), 5);
         mockRequest = new MockRequest(mockIdentifier, mockReplyTo);
         mockRequest2 = new MockRequest(mockIdentifier, mockReplyTo);
         mockResponse = mockRequest.toRequestFailure(mockCause);
         mockResponseEnvelope = new FailureEnvelope(mockResponse, 0, 0, 0);
         mockCookie = ThreadLocalRandom.current().nextLong();
 
-        queue = new ConnectingClientConnection<>(mockContext, mockCookie);
+        queue = new ConnectingClientConnection<>(mockContext, mockCookie, mockBackendInfo.getName());
     }
 
     @After
@@ -198,7 +196,7 @@ public class ConnectingClientConnectionTest {
     @Test
     public void testSendRequestNeedsBackend() {
         queue.sendRequest(mockRequest, mockCallback);
-        final Optional<Long> ret = queue.checkTimeout(ticker.read());
+        final OptionalLong ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertTrue(ret.isPresent());
     }
@@ -214,64 +212,63 @@ public class ConnectingClientConnectionTest {
         setupBackend();
 
         queue.sendRequest(mockRequest, mockCallback);
-        final Optional<Long> ret = queue.checkTimeout(ticker.read());
+        final OptionalLong ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertTrue(ret.isPresent());
         assertTransmit(mockRequest, 0);
     }
 
     @Test
-    public void testRunTimeoutEmpty() throws NoProgressException {
-        Optional<Long> ret = queue.checkTimeout(ticker.read());
+    public void testRunTimeoutEmpty() {
+        OptionalLong ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertFalse(ret.isPresent());
     }
 
     @Test
-    public void testRunTimeoutWithoutShift() throws NoProgressException {
+    public void testRunTimeoutWithoutShift() {
         queue.sendRequest(mockRequest, mockCallback);
-        Optional<Long> ret = queue.checkTimeout(ticker.read());
+        OptionalLong ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertTrue(ret.isPresent());
     }
 
     @Test
-    public void testRunTimeoutWithTimeoutLess() throws NoProgressException {
+    public void testRunTimeoutWithTimeoutLess() {
         queue.sendRequest(mockRequest, mockCallback);
 
         ticker.advance(AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS - 1);
 
-        Optional<Long> ret = queue.checkTimeout(ticker.read());
+        OptionalLong ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertTrue(ret.isPresent());
     }
 
     @Test
-    public void testRunTimeoutWithTimeoutExact() throws NoProgressException {
+    public void testRunTimeoutWithTimeoutExact() {
         setupBackend();
 
         queue.sendRequest(mockRequest, mockCallback);
 
         ticker.advance(AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS);
 
-        Optional<Long> ret = queue.checkTimeout(ticker.read());
+        OptionalLong ret = queue.checkTimeout(ticker.read());
         assertNull(ret);
     }
 
     @Test
-    public void testRunTimeoutWithTimeoutMore() throws NoProgressException {
+    public void testRunTimeoutWithTimeoutMore() {
         setupBackend();
 
         queue.sendRequest(mockRequest, mockCallback);
 
         ticker.advance(AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS + 1);
 
-        Optional<Long> ret = queue.checkTimeout(ticker.read());
-        assertNull(ret);
+        assertNull(queue.checkTimeout(ticker.read()));
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    public void testRunTimeoutWithoutProgressExact() throws NoProgressException {
+    public void testRunTimeoutWithoutProgressExact() {
         queue.sendRequest(mockRequest, mockCallback);
 
         ticker.advance(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS);
@@ -282,7 +279,7 @@ public class ConnectingClientConnectionTest {
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    public void testRunTimeoutWithoutProgressMore() throws NoProgressException {
+    public void testRunTimeoutWithoutProgressMore() {
         queue.sendRequest(mockRequest, mockCallback);
 
         ticker.advance(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS + 1);
@@ -293,23 +290,19 @@ public class ConnectingClientConnectionTest {
     }
 
     @Test
-    public void testRunTimeoutEmptyWithoutProgressExact() throws NoProgressException {
+    public void testRunTimeoutEmptyWithoutProgressExact() {
         ticker.advance(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS);
 
         // No problem
-        Optional<Long> ret = queue.checkTimeout(ticker.read());
-        assertNotNull(ret);
-        assertFalse(ret.isPresent());
+        assertEquals(OptionalLong.empty(), queue.checkTimeout(ticker.read()));
     }
 
     @Test
-    public void testRunTimeoutEmptyWithoutProgressMore() throws NoProgressException {
+    public void testRunTimeoutEmptyWithoutProgressMore() {
         ticker.advance(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS + 1);
 
         // No problem
-        Optional<Long> ret = queue.checkTimeout(ticker.read());
-        assertNotNull(ret);
-        assertFalse(ret.isPresent());
+        assertEquals(OptionalLong.empty(), queue.checkTimeout(ticker.read()));
     }
 
     @Test
@@ -344,7 +337,7 @@ public class ConnectingClientConnectionTest {
     }
 
     @Test
-    public void testProgressRecord() throws NoProgressException {
+    public void testProgressRecord() {
         setupBackend();
 
         queue.sendRequest(mockRequest, mockCallback);
@@ -355,13 +348,12 @@ public class ConnectingClientConnectionTest {
 
         ticker.advance(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS - 11);
 
-        Optional<Long> ret = queue.checkTimeout(ticker.read());
-        assertNull(ret);
+        assertNull(queue.checkTimeout(ticker.read()));
     }
 
     private void setupBackend() {
         final ConnectingClientConnection<BackendInfo> connectingConn =
-                new ConnectingClientConnection<>(mockContext, mockCookie);
+                new ConnectingClientConnection<>(mockContext, mockCookie, "test");
         final ConnectedClientConnection<BackendInfo> connectedConn =
                 new ConnectedClientConnection<>(connectingConn, mockBackendInfo);
         queue.setForwarder(new SimpleReconnectForwarder(connectedConn));