X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-netty-util%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fnettyutil%2Fhandler%2Fssh%2Fclient%2FAsyncSshHandlerTest.java;h=dfca1b80c41afd3d855216babc3a3ad6e8d45db4;hp=b4c9e1e95083dd94b21d57318ef989dca355bdd2;hb=5a9588f96084e84c7faf93788ee02f2e00849f8b;hpb=0d318e4be80c368269172e915b2a193b6f0a8f09 diff --git a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java index b4c9e1e950..dfca1b80c4 100644 --- a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java +++ b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.netconf.nettyutil.handler.ssh.client; -import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyObject; @@ -18,10 +17,11 @@ import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +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.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -29,8 +29,10 @@ import com.google.common.util.concurrent.SettableFuture; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; +import io.netty.channel.DefaultChannelPromise; import java.io.IOException; import java.net.SocketAddress; import org.apache.sshd.ClientChannel; @@ -142,6 +144,7 @@ public class AsyncSshHandlerTest { doReturn(ctx).when(ctx).fireChannelActive(); doReturn(ctx).when(ctx).fireChannelInactive(); doReturn(ctx).when(ctx).fireChannelRead(anyObject()); + doReturn(mock(ChannelFuture.class)).when(ctx).disconnect(any(ChannelPromise.class)); doReturn(getMockedPromise()).when(ctx).newPromise(); } @@ -178,7 +181,6 @@ public class AsyncSshHandlerTest { verify(subsystemChannel).setStreaming(ClientChannel.Streaming.Async); verify(promise).setSuccess(); - verifyNoMoreInteractions(promise); verify(ctx).fireChannelActive(); } @@ -532,14 +534,8 @@ public class AsyncSshHandlerTest { verify(subsystemChannel).setStreaming(ClientChannel.Streaming.Async); - try { - sshChannelOpenListener.operationComplete(getFailedOpenFuture()); - fail("Exception expected"); - } catch (final Exception e) { - verify(promise).setFailure(any(Throwable.class)); - verifyNoMoreInteractions(promise); - // TODO should ctx.channelInactive be called if we throw exception ? - } + sshChannelOpenListener.operationComplete(getFailedOpenFuture()); + verify(promise).setFailure(any(Throwable.class)); } @Test @@ -554,14 +550,8 @@ public class AsyncSshHandlerTest { final AuthFuture authFuture = getFailedAuthFuture(); - try { - sshAuthListener.operationComplete(authFuture); - fail("Exception expected"); - } catch (final Exception e) { - verify(promise).setFailure(any(Throwable.class)); - verifyNoMoreInteractions(promise); - // TODO should ctx.channelInactive be called ? - } + sshAuthListener.operationComplete(authFuture); + verify(promise).setFailure(any(Throwable.class)); } private AuthFuture getFailedAuthFuture() { @@ -583,14 +573,8 @@ public class AsyncSshHandlerTest { asyncSshHandler.connect(ctx, remoteAddress, localAddress, promise); final ConnectFuture connectFuture = getFailedConnectFuture(); - try { - sshConnectListener.operationComplete(connectFuture); - fail("Exception expected"); - } catch (final Exception e) { - verify(promise).setFailure(any(Throwable.class)); - verifyNoMoreInteractions(promise); - // TODO should ctx.channelInactive be called ? - } + sshConnectListener.operationComplete(connectFuture); + verify(promise).setFailure(any(Throwable.class)); } private ConnectFuture getFailedConnectFuture() { @@ -601,10 +585,7 @@ public class AsyncSshHandlerTest { } private ChannelPromise getMockedPromise() { - final ChannelPromise promise = mock(ChannelPromise.class); - doReturn(promise).when(promise).setSuccess(); - doReturn(promise).when(promise).setFailure(any(Throwable.class)); - return promise; + return spy(new DefaultChannelPromise(channel)); } private static abstract class SuccessFutureListener> implements FutureCallback> {