Reduce NETCONF device disconnect warnings
[netconf.git] / netconf / netconf-netty-util / src / test / java / org / opendaylight / netconf / nettyutil / AbstractNetconfSessionTest.java
index e978850545723143994c59433012d6447dd4dd5b..f4b64cfc4bb7d066b150a9b87b66bf52c95dd53c 100644 (file)
@@ -5,7 +5,6 @@
  * 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.netconf.nettyutil;
 
 import static org.junit.Assert.assertEquals;
@@ -19,9 +18,7 @@ import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.verifyZeroInteractions;
 
-import com.google.common.base.Optional;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelHandler;
@@ -30,12 +27,14 @@ import io.netty.channel.ChannelPromise;
 import io.netty.channel.EventLoop;
 import io.netty.handler.codec.ByteToMessageDecoder;
 import io.netty.handler.codec.MessageToByteEncoder;
-import io.netty.util.concurrent.GenericFutureListener;
+import java.io.EOFException;
 import java.util.Collections;
+import java.util.Optional;
 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.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfSessionListener;
 import org.opendaylight.netconf.api.NetconfTerminationReason;
@@ -43,6 +42,7 @@ import org.opendaylight.netconf.api.messages.NetconfHelloMessage;
 import org.opendaylight.netconf.nettyutil.handler.exi.EXIParameters;
 import org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class AbstractNetconfSessionTest {
 
     @Mock
@@ -60,20 +60,15 @@ public class AbstractNetconfSessionTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
         doNothing().when(listener).onMessage(any(TestingNetconfSession.class), any(NetconfMessage.class));
         doNothing().when(listener).onSessionUp(any(TestingNetconfSession.class));
         doNothing().when(listener).onSessionDown(any(TestingNetconfSession.class), any(Exception.class));
         doNothing().when(listener).onSessionTerminated(any(TestingNetconfSession.class),
                 any(NetconfTerminationReason.class));
 
-        doReturn(writeFuture).when(writeFuture).addListener(any(GenericFutureListener.class));
-
         doReturn(writeFuture).when(channel).newPromise();
-        doReturn(writeFuture).when(channel).writeAndFlush(any(NetconfMessage.class));
         doReturn(writeFuture).when(channel).writeAndFlush(any(NetconfMessage.class), any(ChannelPromise.class));
         doReturn(pipeline).when(channel).pipeline();
-        doReturn("mockChannel").when(channel).toString();
         doReturn(mock(ChannelFuture.class)).when(channel).close();
 
         doReturn(null).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
@@ -84,7 +79,7 @@ public class AbstractNetconfSessionTest {
             return null;
         }).when(eventLoop).execute(any(Runnable.class));
 
-        clientHello = NetconfHelloMessage.createClientHello(Collections.emptySet(), Optional.absent());
+        clientHello = NetconfHelloMessage.createClientHello(Collections.emptySet(), Optional.empty());
     }
 
     @Test
@@ -115,7 +110,6 @@ public class AbstractNetconfSessionTest {
     public void testReplaceHandlers() throws Exception {
         final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, 1L);
         final ChannelHandler mock = mock(ChannelHandler.class);
-        doReturn("handler").when(mock).toString();
 
         testingNetconfSession.replaceMessageDecoder(mock);
         verify(pipeline).replace(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER,
@@ -144,19 +138,18 @@ public class AbstractNetconfSessionTest {
     public void testEndOfInput() throws Exception {
         final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, 1L);
         testingNetconfSession.endOfInput();
-        verifyZeroInteractions(listener);
+        verifyNoMoreInteractions(listener);
         testingNetconfSession.sessionUp();
         testingNetconfSession.endOfInput();
-        verify(listener).onSessionDown(any(TestingNetconfSession.class), any(Exception.class));
+        verify(listener).onSessionDown(any(TestingNetconfSession.class), any(EOFException.class));
     }
 
     @Test
     public void testSendMessage() throws Exception {
         final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, 1L);
         final NetconfHelloMessage hello = NetconfHelloMessage.createClientHello(Collections.emptySet(),
-            Optional.absent());
+            Optional.empty());
         testingNetconfSession.sendMessage(hello);
         verify(channel).writeAndFlush(hello, writeFuture);
     }
-
 }