Remove TestableContext 93/102293/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Sep 2022 16:14:55 +0000 (18:14 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Sep 2022 16:14:55 +0000 (18:14 +0200)
Use a simple spy() instead of a subclass here.

Change-Id: Ib714741641b125697984b1559e2f84d25ebeb309
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java

index 49f7f7dce34b03bf54c02a9172cad120b0c6e034..1be02d6563ac3a1b7a47797d428b7856719989b9 100644 (file)
@@ -15,6 +15,7 @@ import static org.mockito.ArgumentMatchers.anyString;
 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;
 
@@ -32,7 +33,6 @@ import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
 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;
@@ -162,7 +162,8 @@ public class CallHomeSessionContextTest {
         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);
@@ -195,19 +196,4 @@ public class CallHomeSessionContextTest {
         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;
-        }
-    }
 }