From 00c7530b9b2a3508594f679dc250c763e1a2de19 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 5 Sep 2022 18:14:55 +0200 Subject: [PATCH] Remove TestableContext Use a simple spy() instead of a subclass here. Change-Id: Ib714741641b125697984b1559e2f84d25ebeb309 Signed-off-by: Robert Varga --- .../protocol/CallHomeSessionContextTest.java | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java index 49f7f7dce3..1be02d6563 100644 --- a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java +++ b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java @@ -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 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; - } - } } -- 2.36.6