Use a simple spy() instead of a subclass here.
Change-Id: Ib714741641b125697984b1559e2f84d25ebeb309
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
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.times;
import static org.mockito.Mockito.verify;
import org.opendaylight.netconf.shaded.sshd.client.channel.ChannelSubsystem;
import org.opendaylight.netconf.shaded.sshd.client.channel.ClientChannel;
import org.opendaylight.netconf.shaded.sshd.client.future.OpenFuture;
import org.opendaylight.netconf.shaded.sshd.client.channel.ChannelSubsystem;
import org.opendaylight.netconf.shaded.sshd.client.channel.ClientChannel;
import org.opendaylight.netconf.shaded.sshd.client.future.OpenFuture;
-import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
import org.opendaylight.netconf.shaded.sshd.client.session.ClientSessionImpl;
import org.opendaylight.netconf.shaded.sshd.common.AttributeRepository.AttributeKey;
import org.opendaylight.netconf.shaded.sshd.common.channel.StreamingChannel;
import org.opendaylight.netconf.shaded.sshd.client.session.ClientSessionImpl;
import org.opendaylight.netconf.shaded.sshd.common.AttributeRepository.AttributeKey;
import org.opendaylight.netconf.shaded.sshd.common.channel.StreamingChannel;
OpenFuture mockFuture = mock(OpenFuture.class);
doReturn(true).when(mockFuture).isOpened();
OpenFuture mockFuture = mock(OpenFuture.class);
doReturn(true).when(mockFuture).isOpened();
- instance = new TestableContext(mockSession, mockAuth, mockFactory, mockMinaChannel);
+ instance = spy(new CallHomeSessionContext(mockSession, mockAuth, mockFactory));
+ doReturn(mockMinaChannel).when(instance).newMinaSshNettyChannel(any());
SshFutureListener<OpenFuture> listener = instance.newSshFutureListener(mockChannel);
// when
listener.operationComplete(mockFuture);
SshFutureListener<OpenFuture> listener = instance.newSshFutureListener(mockChannel);
// when
listener.operationComplete(mockFuture);
verify(mockSession, times(0)).setAttribute(any(), any());
assertNull(CallHomeSessionContext.getFrom(mockSession));
}
verify(mockSession, times(0)).setAttribute(any(), any());
assertNull(CallHomeSessionContext.getFrom(mockSession));
}
-
- static class TestableContext extends CallHomeSessionContext {
- MinaSshNettyChannel minaMock;
-
- TestableContext(final ClientSession sshSession, final CallHomeAuthorization authorization,
- final CallHomeSessionContext.Factory factory, final MinaSshNettyChannel minaMock) {
- super(sshSession, authorization, factory);
- this.minaMock = minaMock;
- }
-
- @Override
- protected MinaSshNettyChannel newMinaSshNettyChannel(final ClientChannel netconfChannel) {
- return minaMock;
- }
- }