Ditch use of SystemNotificationsListener
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / connection / listener / OpenflowProtocolListenerInitialImplTest.java
index 5601d0cc274910dab1a7ffeb64881aa30dbf0593..7efa4e79561a1b9c3a9ad61b07627af1ac2f90d2 100644 (file)
@@ -5,31 +5,34 @@
  * 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.openflowplugin.impl.connection.listener;
 
-import org.junit.Assert;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.util.concurrent.Futures;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.ArgumentMatchers;
 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.OFConstants;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.connection.HandshakeContext;
 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 /**
  * Test for {@link OpenflowProtocolListenerInitialImpl}.
  */
 @RunWith(MockitoJUnitRunner.class)
 public class OpenflowProtocolListenerInitialImplTest {
-
     @Mock
     private ConnectionContext connectionContext;
     @Mock
@@ -42,39 +45,42 @@ public class OpenflowProtocolListenerInitialImplTest {
     private OpenflowProtocolListenerInitialImpl openflowProtocolListenerInitial;
 
     @Before
-    public void setUp() throws Exception {
-        Mockito.when(connectionAdapter.isAlive()).thenReturn(true);
-        Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
-        Mockito.when(connectionContext.getConnectionState())
+    public void setUp() {
+        when(connectionAdapter.isAlive()).thenReturn(true);
+        when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
+        when(connectionContext.getConnectionState())
                 .thenReturn(null, ConnectionContext.CONNECTION_STATE.HANDSHAKING);
-        Mockito.when(handshakeContext.getHandshakeManager()).thenReturn(handshakeManager);
+        when(handshakeContext.getHandshakeManager()).thenReturn(handshakeManager);
 
         openflowProtocolListenerInitial = new OpenflowProtocolListenerInitialImpl(connectionContext, handshakeContext);
     }
 
     @Test
-    public void testOnEchoRequestMessage() throws Exception {
-        EchoRequestMessageBuilder echoRequestMessageBld = new EchoRequestMessageBuilder()
-                .setXid(42L)
-                .setVersion(OFConstants.OFP_VERSION_1_3);
-        openflowProtocolListenerInitial.onEchoRequestMessage(echoRequestMessageBld.build());
+    public void testOnEchoRequestMessage() {
+        when(connectionAdapter.echoReply(any())).thenReturn(Futures.immediateFuture(null));
+
+        openflowProtocolListenerInitial.onEchoRequestMessage(
+            new EchoRequestMessageBuilder()
+                .setXid(Uint32.valueOf(42))
+                .setVersion(EncodeConstants.OF_VERSION_1_3)
+                .build());
 
-        Mockito.verify(connectionAdapter).echoReply(ArgumentMatchers.any());
+        verify(connectionAdapter).echoReply(any());
     }
 
     @Test
-    public void testOnHelloMessage() throws Exception {
+    public void testOnHelloMessage() {
         HelloMessageBuilder helloMessageBld = new HelloMessageBuilder()
-                .setXid(42L)
-                .setVersion(OFConstants.OFP_VERSION_1_3);
+                .setXid(Uint32.valueOf(42))
+                .setVersion(EncodeConstants.OF_VERSION_1_3);
         openflowProtocolListenerInitial.onHelloMessage(helloMessageBld.build());
 
-        Mockito.verify(handshakeManager).shake(ArgumentMatchers.any());
+        verify(handshakeManager).shake(any());
     }
 
     @Test
-    public void testCheckState() throws Exception {
-        Assert.assertFalse(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));
-        Assert.assertTrue(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));
+    public void testCheckState() {
+        assertFalse(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));
+        assertTrue(openflowProtocolListenerInitial.checkState(ConnectionContext.CONNECTION_STATE.HANDSHAKING));
     }
 }
\ No newline at end of file