OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / connection / listener / SystemNotificationsListenerImplTest.java
index fad4b579821cb4ee74d57d618ae75b6c06f63055..2abf175a02beb836ef7c27001739294d09b07012 100644 (file)
@@ -8,21 +8,21 @@
 
 package org.opendaylight.openflowplugin.impl.connection.listener;
 
+import static org.mockito.ArgumentMatchers.any;
+
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.net.InetSocketAddress;
-import java.util.concurrent.Future;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.TimeUnit;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Matchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.impl.connection.ConnectionContextImpl;
@@ -93,8 +93,6 @@ public class SystemNotificationsListenerImplTest {
      */
     @Test
     public void testOnDisconnectEvent1() throws Exception {
-        Mockito.when(connectionAdapter.isAlive()).thenReturn(true);
-        Mockito.when(connectionAdapter.disconnect()).thenReturn(Futures.immediateFuture(Boolean.TRUE));
 
         DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
         systemNotificationsListener.onDisconnectEvent(disconnectNotification);
@@ -110,8 +108,6 @@ public class SystemNotificationsListenerImplTest {
      */
     @Test
     public void testOnDisconnectEvent2() throws Exception {
-        Mockito.when(connectionAdapter.isAlive()).thenReturn(true);
-        Mockito.when(connectionAdapter.disconnect()).thenReturn(Futures.immediateFuture(Boolean.FALSE));
 
         DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
         systemNotificationsListener.onDisconnectEvent(disconnectNotification);
@@ -129,10 +125,6 @@ public class SystemNotificationsListenerImplTest {
     public void testOnDisconnectEvent3() throws Exception {
         connectionContextGolem.changeStateToTimeouting();
 
-        Mockito.when(connectionAdapter.isAlive()).thenReturn(true);
-        Mockito.when(connectionAdapter.disconnect())
-                .thenReturn(Futures.<Boolean>immediateFailedFuture(new Exception("unit exception")));
-
         DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
         systemNotificationsListener.onDisconnectEvent(disconnectNotification);
 
@@ -148,7 +140,6 @@ public class SystemNotificationsListenerImplTest {
     @Test
     public void testOnDisconnectEvent4() throws Exception {
         Mockito.when(connectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.RIP);
-        Mockito.when(connectionAdapter.isAlive()).thenReturn(false);
 
         DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
         systemNotificationsListener.onDisconnectEvent(disconnectNotification);
@@ -164,10 +155,10 @@ public class SystemNotificationsListenerImplTest {
      */
     @Test
     public void testOnSwitchIdleEvent1() throws Exception {
-        final Future<RpcResult<EchoOutput>> echoReply =
+        final ListenableFuture<RpcResult<EchoOutput>> echoReply =
                 Futures.immediateFuture(RpcResultBuilder.success(new EchoOutputBuilder().setXid(0L).build()).build());
 
-        Mockito.when(connectionAdapter.echo(Matchers.any(EchoInput.class))).thenReturn(echoReply);
+        Mockito.when(connectionAdapter.echo(any(EchoInput.class))).thenReturn(echoReply);
 
         SwitchIdleEvent notification = new SwitchIdleEventBuilder().setInfo("wake up, device sleeps").build();
         systemNotificationsListener.onSwitchIdleEvent(notification);
@@ -176,7 +167,7 @@ public class SystemNotificationsListenerImplTest {
         Thread.sleep(SAFE_TIMEOUT);
 
         verifyCommonInvocations();
-        Mockito.verify(connectionAdapter, Mockito.timeout(SAFE_TIMEOUT)).echo(Matchers.any(EchoInput.class));
+        Mockito.verify(connectionAdapter, Mockito.timeout(SAFE_TIMEOUT)).echo(any(EchoInput.class));
         Mockito.verify(connectionAdapter, Mockito.never()).disconnect();
         Mockito.verify(connectionContext).changeStateToTimeouting();
         Mockito.verify(connectionContext).changeStateToWorking();
@@ -188,7 +179,7 @@ public class SystemNotificationsListenerImplTest {
     @Test
     public void testOnSwitchIdleEvent2() throws Exception {
         final SettableFuture<RpcResult<EchoOutput>> echoReply = SettableFuture.create();
-        Mockito.when(connectionAdapter.echo(Matchers.any(EchoInput.class))).thenReturn(echoReply);
+        Mockito.when(connectionAdapter.echo(any(EchoInput.class))).thenReturn(echoReply);
         Mockito.when(connectionAdapter.isAlive()).thenReturn(true);
         Mockito.when(connectionAdapter.disconnect())
                 .thenReturn(Futures.<Boolean>immediateFailedFuture(new Exception("unit exception")));
@@ -199,7 +190,7 @@ public class SystemNotificationsListenerImplTest {
         Thread.sleep(SystemNotificationsListenerImpl.MAX_ECHO_REPLY_TIMEOUT + SAFE_TIMEOUT);
 
         verifyCommonInvocations();
-        Mockito.verify(connectionAdapter, Mockito.timeout(SAFE_TIMEOUT)).echo(Matchers.any(EchoInput.class));
+        Mockito.verify(connectionAdapter, Mockito.timeout(SAFE_TIMEOUT)).echo(any(EchoInput.class));
         Mockito.verify(connectionAdapter).disconnect();
         Mockito.verify(connectionContext).changeStateToTimeouting();
         Mockito.verify(connectionContext).closeConnection(true);
@@ -216,4 +207,4 @@ public class SystemNotificationsListenerImplTest {
         Mockito.verify(connectionContext, Mockito.timeout(SAFE_TIMEOUT).atLeastOnce()).getConnectionState();
         Mockito.verify(connectionContext, Mockito.timeout(SAFE_TIMEOUT).atLeastOnce()).getFeatures();
     }
-}
\ No newline at end of file
+}