Clean up netconf-client tests 53/102753/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Oct 2022 20:23:01 +0000 (22:23 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Oct 2022 20:26:54 +0000 (22:26 +0200)
Remove unneeded throws declarations and do not use mockito internals.

Change-Id: If25da046270c1e097f9e24c7e43dbad53720a293
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiatorTest.java
netconf/netconf-client/src/test/java/org/opendaylight/netconf/client/SimpleNetconfClientSessionListenerTest.java

index 5714eb4b6cdcaafd16ff8015435956253c790636..b61073d6744c0599edde7abc2c18ed63dd7d622d 100644 (file)
@@ -38,8 +38,6 @@ import java.util.Optional;
 import java.util.Set;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.internal.util.collections.Sets;
-import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.messages.NetconfHelloMessage;
 import org.opendaylight.netconf.api.xml.XmlUtil;
@@ -61,8 +59,8 @@ public class NetconfClientSessionNegotiatorTest {
     private ChannelInboundHandlerAdapter channelInboundHandlerAdapter;
 
     @Before
-    public void setUp() throws Exception {
-        helloMessage = NetconfHelloMessage.createClientHello(Sets.newSet("exi:1.0"), Optional.empty());
+    public void setUp() {
+        helloMessage = NetconfHelloMessage.createClientHello(Set.of("exi:1.0"), Optional.empty());
         pipeline = mockChannelPipeline();
         future = mockChannelFuture();
         channel = mockChannel();
@@ -152,30 +150,25 @@ public class NetconfClientSessionNegotiatorTest {
     }
 
     @Test
-    public void testNetconfClientSessionNegotiator() throws NetconfDocumentedException {
+    public void testNetconfClientSessionNegotiator() throws Exception {
         Promise<NetconfClientSession> promise = mock(Promise.class);
         doReturn(promise).when(promise).setSuccess(any());
         NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, null);
 
         negotiator.channelActive(null);
-        Set<String> caps = Sets.newSet("a", "b");
-        NetconfHelloMessage helloServerMessage = NetconfHelloMessage.createServerHello(caps, 10);
-        negotiator.handleMessage(helloServerMessage);
+        negotiator.handleMessage(NetconfHelloMessage.createServerHello(Set.of("a", "b"), 10));
         verify(promise).setSuccess(any());
     }
 
     @Test
     public void testNegotiatorWhenChannelActiveHappenAfterHandleMessage() throws Exception {
-        Promise promise = mock(Promise.class);
+        Promise<NetconfClientSession> promise = mock(Promise.class);
         doReturn(false).when(promise).isDone();
         doReturn(promise).when(promise).setSuccess(any());
         NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, null);
-        Set<String> caps = Sets.newSet("a", "b");
-        NetconfHelloMessage helloServerMessage = NetconfHelloMessage.createServerHello(caps, 10);
 
-        negotiator.handleMessage(helloServerMessage);
+        negotiator.handleMessage(NetconfHelloMessage.createServerHello(Set.of("a", "b"), 10));
         negotiator.channelActive(null);
-
         verify(promise).setSuccess(any());
     }
 
@@ -187,8 +180,6 @@ public class NetconfClientSessionNegotiatorTest {
         NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, exiMessage);
 
         negotiator.channelActive(null);
-        Set<String> caps = Sets.newSet("exi:1.0");
-        NetconfHelloMessage message = NetconfHelloMessage.createServerHello(caps, 10);
 
         doAnswer(invocationOnMock -> {
             channelInboundHandlerAdapter = invocationOnMock.getArgument(2);
@@ -197,7 +188,7 @@ public class NetconfClientSessionNegotiatorTest {
 
         ChannelHandlerContext handlerContext = mock(ChannelHandlerContext.class);
         doReturn(pipeline).when(handlerContext).pipeline();
-        negotiator.handleMessage(message);
+        negotiator.handleMessage(NetconfHelloMessage.createServerHello(Set.of("exi:1.0"), 10));
         Document expectedResult = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc-reply_ok.xml");
         channelInboundHandlerAdapter.channelRead(handlerContext, new NetconfMessage(expectedResult));
 
@@ -209,7 +200,7 @@ public class NetconfClientSessionNegotiatorTest {
 
     @Test
     public void testNetconfClientSessionNegotiatorGetCached() throws Exception {
-        Promise promise = mock(Promise.class);
+        Promise<NetconfClientSession> promise = mock(Promise.class);
         doReturn(promise).when(promise).setSuccess(any());
         NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
         NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, null);
index 60f3ad89e1a29fb9acfea45265e3dc4da8243351..65e1c8e109f280bbd3f37b67a453d51c6fedb218 100644 (file)
@@ -24,23 +24,19 @@ import io.netty.util.concurrent.GenericFutureListener;
 import java.util.Set;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.internal.util.collections.Sets;
-import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.messages.NetconfHelloMessage;
 
 public class SimpleNetconfClientSessionListenerTest {
-
     private Channel channel;
     private ChannelPromise channelFuture;
-    Set<String> caps;
     private NetconfHelloMessage helloMessage;
     private NetconfMessage message;
     private NetconfClientSessionListener sessionListener;
     private NetconfClientSession clientSession;
 
     @Before
-    public void setUp() throws NetconfDocumentedException {
+    public void setUp() {
         channel = mock(Channel.class);
         channelFuture = mock(ChannelPromise.class);
         mockEventLoop();
@@ -48,7 +44,7 @@ public class SimpleNetconfClientSessionListenerTest {
         doReturn(channelFuture).when(channel).writeAndFlush(any());
         doReturn(channelFuture).when(channel).writeAndFlush(any(), any(ChannelPromise.class));
         doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
-        caps = Sets.newSet("a", "b");
+        final var caps = Set.of("a", "b");
         helloMessage = NetconfHelloMessage.createServerHello(caps, 10);
         message = new NetconfMessage(helloMessage.getDocument());
         sessionListener = mock(NetconfClientSessionListener.class);
@@ -65,7 +61,7 @@ public class SimpleNetconfClientSessionListenerTest {
     }
 
     @Test
-    public void testSessionDown() throws Exception {
+    public void testSessionDown() {
         SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
         final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
         simpleListener.onSessionUp(clientSession);