Fix unstable test for NetconfDeviceCommunicator
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / listener / NetconfDeviceCommunicatorTest.java
index 942c31d25c66cdb7e77e21ac906407634d1aa54d..cd3dae30af1c73e93c33ab03595bb9689f74ac7f 100644 (file)
@@ -47,9 +47,10 @@ import java.util.concurrent.TimeoutException;
 import javax.xml.parsers.ParserConfigurationException;
 import org.junit.Before;
 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.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfTerminationReason;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
@@ -73,6 +74,7 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class NetconfDeviceCommunicatorTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceCommunicatorTest.class);
@@ -87,8 +89,6 @@ public class NetconfDeviceCommunicatorTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
         communicator = new NetconfDeviceCommunicator(
                 new RemoteDeviceId("test", InetSocketAddress.createUnresolved("localhost", 22)), mockDevice, 10);
     }
@@ -228,7 +228,6 @@ public class NetconfDeviceCommunicatorTest {
         verify(mockChannelFuture).addListener(futureListener.capture());
         Future<Void> operationFuture = mock(Future.class);
         doReturn(true).when(operationFuture).isSuccess();
-        doReturn(true).when(operationFuture).isDone();
         futureListener.getValue().operationComplete(operationFuture);
 
         try {
@@ -290,7 +289,6 @@ public class NetconfDeviceCommunicatorTest {
 
         Future<Void> operationFuture = mock(Future.class);
         doReturn(false).when(operationFuture).isSuccess();
-        doReturn(true).when(operationFuture).isDone();
         doReturn(new Exception("mock error")).when(operationFuture).cause();
         futureListener.getValue().operationComplete(operationFuture);
 
@@ -386,7 +384,7 @@ public class NetconfDeviceCommunicatorTest {
      * Test whether reconnect is scheduled properly.
      */
     @Test
-    public void testNetconfDeviceReconnectInCommunicator() throws Exception {
+    public void testNetconfDeviceReconnectInCommunicator() {
         final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device =
                 mock(RemoteDevice.class);
 
@@ -394,16 +392,19 @@ public class NetconfDeviceCommunicatorTest {
                 new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, 10000, 0, 1.0, null, 100L, null);
         final ReconnectStrategy reconnectStrategy = spy(new ReconnectStrategy() {
             @Override
+            @Deprecated
             public int getConnectTimeout() throws Exception {
                 return timedReconnectStrategy.getConnectTimeout();
             }
 
             @Override
+            @Deprecated
             public Future<Void> scheduleReconnect(final Throwable cause) {
                 return timedReconnectStrategy.scheduleReconnect(cause);
             }
 
             @Override
+            @Deprecated
             public void reconnectSuccessful() {
                 timedReconnectStrategy.reconnectSuccessful();
             }
@@ -427,7 +428,7 @@ public class NetconfDeviceCommunicatorTest {
             listener.initializeRemoteConnection(new NetconfClientDispatcherImpl(group, group, time), cfg);
 
             verify(reconnectStrategy,
-                    timeout((int) TimeUnit.MINUTES.toMillis(3)).times(101)).scheduleReconnect(any(Throwable.class));
+                    timeout(TimeUnit.MINUTES.toMillis(4)).times(101)).scheduleReconnect(any(Throwable.class));
         } finally {
             time.stop();
             group.shutdownGracefully();