Run safelyDisconnect() on event loop
[netconf.git] / netconf / netconf-netty-util / src / test / java / org / opendaylight / netconf / nettyutil / handler / ssh / client / AsyncSshHandlerTest.java
index 46bce11599c61a3e525fca8e786fee2b9ed31a32..b3f085b2930d83507eebddde3e26e877400c964d 100644 (file)
@@ -32,6 +32,7 @@ import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelPromise;
 import io.netty.channel.DefaultChannelPromise;
+import io.netty.util.concurrent.EventExecutor;
 import java.io.IOException;
 import java.net.SocketAddress;
 import java.util.concurrent.TimeUnit;
@@ -76,6 +77,8 @@ public class AsyncSshHandlerTest {
     private SocketAddress localAddress;
     @Mock
     private ChannelConfig channelConfig;
+    @Mock
+    private EventExecutor executor;
 
     private AsyncSshHandler asyncSshHandler;
 
@@ -136,6 +139,11 @@ public class AsyncSshHandlerTest {
         doReturn(ctx).when(ctx).fireChannelInactive();
         doReturn(mock(ChannelFuture.class)).when(ctx).disconnect(any(ChannelPromise.class));
         doReturn(getMockedPromise()).when(ctx).newPromise();
+        doReturn(executor).when(ctx).executor();
+        doAnswer(invocation -> {
+            invocation.getArgument(0, Runnable.class).run();
+            return null;
+        }).when(executor).execute(any());
     }
 
     private void stubChannel() {
@@ -334,20 +342,20 @@ public class AsyncSshHandlerTest {
     }
 
     private static OpenFuture getSuccessOpenFuture() {
-        final OpenFuture failedOpenFuture = mock(OpenFuture.class);
-        doReturn(true).when(failedOpenFuture).isOpened();
-        return failedOpenFuture;
+        final OpenFuture openFuture = mock(OpenFuture.class);
+        doReturn(null).when(openFuture).getException();
+        return openFuture;
     }
 
     private static AuthFuture getSuccessAuthFuture() {
         final AuthFuture authFuture = mock(AuthFuture.class);
-        doReturn(true).when(authFuture).isSuccess();
+        doReturn(null).when(authFuture).getException();
         return authFuture;
     }
 
     private static ConnectFuture getSuccessConnectFuture(final ClientSession sshSession) {
         final ConnectFuture connectFuture = mock(ConnectFuture.class);
-        doReturn(true).when(connectFuture).isConnected();
+        doReturn(null).when(connectFuture).getException();
 
         doReturn(sshSession).when(connectFuture).getSession();
         return connectFuture;
@@ -467,16 +475,14 @@ public class AsyncSshHandlerTest {
 
     private static AuthFuture getFailedAuthFuture() {
         final AuthFuture authFuture = mock(AuthFuture.class);
-        doReturn(false).when(authFuture).isSuccess();
         doReturn(new IllegalStateException()).when(authFuture).getException();
         return authFuture;
     }
 
     private static OpenFuture getFailedOpenFuture() {
-        final OpenFuture authFuture = mock(OpenFuture.class);
-        doReturn(false).when(authFuture).isOpened();
-        doReturn(new IllegalStateException()).when(authFuture).getException();
-        return authFuture;
+        final OpenFuture openFuture = mock(OpenFuture.class);
+        doReturn(new IllegalStateException()).when(openFuture).getException();
+        return openFuture;
     }
 
     @Test
@@ -490,7 +496,6 @@ public class AsyncSshHandlerTest {
 
     private static ConnectFuture getFailedConnectFuture() {
         final ConnectFuture connectFuture = mock(ConnectFuture.class);
-        doReturn(false).when(connectFuture).isConnected();
         doReturn(new IllegalStateException()).when(connectFuture).getException();
         return connectFuture;
     }