Migrate netconf/netconf-netty-util 01/111701/6
authorSamuel Schneider <samuel.schneider@pantheon.tech>
Wed, 15 May 2024 12:52:55 +0000 (14:52 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 11 Jun 2024 08:31:06 +0000 (08:31 +0000)
Migrate netconf/netconf-netty-util to JUnit5.

JIRA: NETCONF-1310
Change-Id: Ic68bca28f642dc689fe4036117da87e07b063665
Signed-off-by: Samuel Schneider <samuel.schneider@pantheon.tech>
16 files changed:
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/AbstractChannelInitializerTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiatorTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/Netconf539Test.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/ChunkedFramingMechanismEncoderTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/EOMFramingMechanismEncoderTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/NetconfChunkAggregatorTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/NetconfEOMAggregatorTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/NetconfEXIHandlersTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/NetconfHelloMessageToXMLEncoderTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/NetconfMessageFactoryTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/NetconfXMLToHelloMessageDecoderTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/NetconfXMLToMessageDecoderTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/ThreadLocalTransformersTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/exi/EXIParametersTest.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/exi/NetconfStartExiMessageTest.java

index d4de8db4e5ce5a4a12dc0b8964eed4d6a38b6fa0..aeb54fae7d9845bd4db38fd53aba778a3f8f30b6 100644 (file)
@@ -18,15 +18,15 @@ import io.netty.channel.Channel;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelPipeline;
 import io.netty.util.concurrent.Promise;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.netconf.api.NetconfSession;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class AbstractChannelInitializerTest {
+@ExtendWith(MockitoExtension.class)
+class AbstractChannelInitializerTest {
 
     @Mock
     private Channel channel;
@@ -35,14 +35,14 @@ public class AbstractChannelInitializerTest {
     @Mock
     private Promise<NetconfSession> sessionPromise;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() {
         doReturn(pipeline).when(channel).pipeline();
         doReturn(pipeline).when(pipeline).addLast(anyString(), any(ChannelHandler.class));
     }
 
     @Test
-    public void testInit() throws Exception {
+    void testInit() {
         final TestingInitializer testingInitializer = new TestingInitializer();
         testingInitializer.initialize(channel, sessionPromise);
         verify(pipeline, times(4)).addLast(anyString(), any(ChannelHandler.class));
@@ -55,4 +55,4 @@ public class AbstractChannelInitializerTest {
         }
     }
 
-}
\ No newline at end of file
+}
index 323c6aa056311ad51d62d7663758c381f72e785f..71dd1e03f42abdfbe41b9936954c06515e8b343d 100644 (file)
@@ -7,10 +7,9 @@
  */
 package org.opendaylight.netconf.nettyutil;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doNothing;
@@ -40,12 +39,12 @@ import java.util.List;
 import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.netconf.api.CapabilityURN;
 import org.opendaylight.netconf.api.NetconfSessionListener;
 import org.opendaylight.netconf.api.messages.HelloMessage;
@@ -57,8 +56,8 @@ import org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator;
 import org.opendaylight.netconf.nettyutil.handler.NetconfEOMAggregator;
 import org.opendaylight.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class AbstractNetconfSessionNegotiatorTest {
+@ExtendWith(MockitoExtension.class)
+class AbstractNetconfSessionNegotiatorTest {
     @Mock
     private NetconfSessionListener<TestingNetconfSession> listener;
     @Mock
@@ -75,8 +74,8 @@ public class AbstractNetconfSessionNegotiatorTest {
     private HelloMessage helloBase11;
     private NetconfXMLToHelloMessageDecoder xmlToHello;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         channel = new EmbeddedChannel();
         xmlToHello = new NetconfXMLToHelloMessageDecoder();
         channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER,
@@ -86,19 +85,18 @@ public class AbstractNetconfSessionNegotiatorTest {
         channel.pipeline().addLast(NETCONF_MESSAGE_AGGREGATOR, new NetconfEOMAggregator());
         hello = HelloMessage.createClientHello(Set.of(), Optional.empty());
         helloBase11 = HelloMessage.createClientHello(Set.of(CapabilityURN.BASE_1_1), Optional.empty());
-        doReturn(promise).when(promise).setFailure(any());
         negotiator = new TestSessionNegotiator(helloBase11, promise, channel, timer, listener, 100L);
     }
 
     @Test
-    public void testStartNegotiation() {
+    void testStartNegotiation() {
         enableTimerTask();
         negotiator.startNegotiation();
         assertEquals(helloBase11, channel.readOutbound());
     }
 
     @Test
-    public void testStartNegotiationSsl() throws Exception {
+    void testStartNegotiationSsl() throws Exception {
         doReturn(true).when(sslHandler).isSharable();
         doNothing().when(sslHandler).handlerAdded(any());
         doNothing().when(sslHandler).write(any(), any(), any());
@@ -113,7 +111,7 @@ public class AbstractNetconfSessionNegotiatorTest {
     }
 
     @Test
-    public void testStartNegotiationNotEstablished() throws Exception {
+    void testStartNegotiationNotEstablished() throws Exception {
         final ChannelOutboundHandler closedDetector = spy(new CloseDetector());
         channel.pipeline().addLast("closedDetector", closedDetector);
         doReturn(false).when(promise).isDone();
@@ -129,28 +127,27 @@ public class AbstractNetconfSessionNegotiatorTest {
     }
 
     @Test
-    public void testGetSessionForHelloMessage() throws Exception {
+    void testGetSessionForHelloMessage() throws Exception {
         enableTimerTask();
         negotiator.startNegotiation();
         final TestingNetconfSession session = negotiator.getSessionForHelloMessage(hello);
         assertNotNull(session);
-        assertThat(channel.pipeline().get(NETCONF_MESSAGE_AGGREGATOR), instanceOf(NetconfEOMAggregator.class));
-        assertThat(channel.pipeline().get(NETCONF_MESSAGE_FRAME_ENCODER), instanceOf(EOMFramingMechanismEncoder.class));
+        assertInstanceOf(NetconfEOMAggregator.class, channel.pipeline().get(NETCONF_MESSAGE_AGGREGATOR));
+        assertInstanceOf(EOMFramingMechanismEncoder.class, channel.pipeline().get(NETCONF_MESSAGE_FRAME_ENCODER));
     }
 
     @Test
-    public void testGetSessionForHelloMessageBase11() throws Exception {
+    void testGetSessionForHelloMessageBase11() throws Exception {
         enableTimerTask();
         negotiator.startNegotiation();
         final TestingNetconfSession session = negotiator.getSessionForHelloMessage(helloBase11);
         assertNotNull(session);
-        assertThat(channel.pipeline().get(NETCONF_MESSAGE_AGGREGATOR), instanceOf(NetconfChunkAggregator.class));
-        assertThat(channel.pipeline().get(NETCONF_MESSAGE_FRAME_ENCODER),
-            instanceOf(ChunkedFramingMechanismEncoder.class));
+        assertInstanceOf(NetconfChunkAggregator.class, channel.pipeline().get(NETCONF_MESSAGE_AGGREGATOR));
+        assertInstanceOf(ChunkedFramingMechanismEncoder.class, channel.pipeline().get(NETCONF_MESSAGE_FRAME_ENCODER));
     }
 
     @Test
-    public void testReplaceHelloMessageInboundHandler() throws Exception {
+    void testReplaceHelloMessageInboundHandler() throws Exception {
         final List<Object> out = new ArrayList<>();
         final byte[] msg = "<rpc/>".getBytes();
         final ByteBuf msgBuf = Unpooled.wrappedBuffer(msg);
@@ -168,7 +165,9 @@ public class AbstractNetconfSessionNegotiatorTest {
     }
 
     @Test
-    public void testNegotiationFail() {
+    void testNegotiationFail() {
+        doReturn(promise).when(promise).setFailure(any());
+
         enableTimerTask();
         doReturn(true).when(timeout).cancel();
         negotiator.startNegotiation();
index 803a974fc99e4f5508d9fdd7178eecf0b72323f9..c2934fa57203407288f817c6fedd6746a54a6a0a 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.netconf.nettyutil;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.doAnswer;
@@ -30,11 +30,11 @@ import io.netty.handler.codec.MessageToByteEncoder;
 import java.io.EOFException;
 import java.util.Optional;
 import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.netconf.api.NetconfSessionListener;
 import org.opendaylight.netconf.api.NetconfTerminationReason;
 import org.opendaylight.netconf.api.messages.HelloMessage;
@@ -44,8 +44,8 @@ import org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessageProv
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
 import org.opendaylight.yangtools.yang.common.Uint32;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class AbstractNetconfSessionTest {
+@ExtendWith(MockitoExtension.class)
+class AbstractNetconfSessionTest {
     private static final SessionIdType SESSION_ID = new SessionIdType(Uint32.ONE);
 
     @Mock
@@ -61,39 +61,24 @@ public class AbstractNetconfSessionTest {
 
     private HelloMessage clientHello;
 
-    @Before
-    public void setUp() throws Exception {
-        doNothing().when(listener).onMessage(any(TestingNetconfSession.class), any(NetconfMessage.class));
-        doNothing().when(listener).onSessionUp(any(TestingNetconfSession.class));
-        doNothing().when(listener).onSessionDown(any(TestingNetconfSession.class), any(Exception.class));
-        doNothing().when(listener).onSessionTerminated(any(TestingNetconfSession.class),
-                any(NetconfTerminationReason.class));
-
-        doReturn(writeFuture).when(channel).newPromise();
-        doReturn(writeFuture).when(channel).writeAndFlush(any(NetconfMessage.class), any(ChannelPromise.class));
-        doReturn(pipeline).when(channel).pipeline();
-        doReturn(mock(ChannelFuture.class)).when(channel).close();
-
-        doReturn(null).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
-
-        doReturn(eventLoop).when(channel).eventLoop();
-        doAnswer(invocation -> {
-            invocation.<Runnable>getArgument(0).run();
-            return null;
-        }).when(eventLoop).execute(any(Runnable.class));
-
+    @BeforeEach
+    void setUp() {
         clientHello = HelloMessage.createClientHello(Set.of(), Optional.empty());
     }
 
     @Test
-    public void testHandleMessage() throws Exception {
+    void testHandleMessage() {
+        doNothing().when(listener).onMessage(any(TestingNetconfSession.class), any(NetconfMessage.class));
+
         final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, SESSION_ID);
         testingNetconfSession.handleMessage(clientHello);
         verify(listener).onMessage(testingNetconfSession, clientHello);
     }
 
     @Test
-    public void testSessionUp() throws Exception {
+    void testSessionUp() {
+        doNothing().when(listener).onSessionUp(any(TestingNetconfSession.class));
+
         final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, SESSION_ID);
         testingNetconfSession.sessionUp();
         verify(listener).onSessionUp(testingNetconfSession);
@@ -101,7 +86,12 @@ public class AbstractNetconfSessionTest {
     }
 
     @Test
-    public void testClose() throws Exception {
+    void testClose() {
+        doReturn(mock(ChannelFuture.class)).when(channel).close();
+        doNothing().when(listener).onSessionUp(any(TestingNetconfSession.class));
+        doNothing().when(listener).onSessionTerminated(any(TestingNetconfSession.class),
+            any(NetconfTerminationReason.class));
+
         final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, SESSION_ID);
         testingNetconfSession.sessionUp();
         testingNetconfSession.close();
@@ -110,7 +100,17 @@ public class AbstractNetconfSessionTest {
     }
 
     @Test
-    public void testReplaceHandlers() throws Exception {
+    void testReplaceHandlers() {
+        doReturn(writeFuture).when(channel).newPromise();
+        doReturn(writeFuture).when(channel).writeAndFlush(any(NetconfMessage.class), any(ChannelPromise.class));
+        doReturn(pipeline).when(channel).pipeline();
+        doReturn(null).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
+        doReturn(eventLoop).when(channel).eventLoop();
+        doAnswer(invocation -> {
+            invocation.<Runnable>getArgument(0).run();
+            return null;
+        }).when(eventLoop).execute(any(Runnable.class));
+
         final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, SESSION_ID);
         final ChannelHandler mock = mock(ChannelHandler.class);
 
@@ -129,7 +129,7 @@ public class AbstractNetconfSessionTest {
     }
 
     @Test
-    public void testStartExi() throws Exception {
+    void testStartExi() {
         TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, SESSION_ID);
         testingNetconfSession = spy(testingNetconfSession);
 
@@ -138,7 +138,10 @@ public class AbstractNetconfSessionTest {
     }
 
     @Test
-    public void testEndOfInput() throws Exception {
+    void testEndOfInput() {
+        doNothing().when(listener).onSessionUp(any(TestingNetconfSession.class));
+        doNothing().when(listener).onSessionDown(any(TestingNetconfSession.class), any(Exception.class));
+
         final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, SESSION_ID);
         testingNetconfSession.endOfInput();
         verifyNoMoreInteractions(listener);
@@ -148,7 +151,15 @@ public class AbstractNetconfSessionTest {
     }
 
     @Test
-    public void testSendMessage() throws Exception {
+    void testSendMessage() {
+        doReturn(writeFuture).when(channel).newPromise();
+        doReturn(writeFuture).when(channel).writeAndFlush(any(NetconfMessage.class), any(ChannelPromise.class));
+        doReturn(eventLoop).when(channel).eventLoop();
+        doAnswer(invocation -> {
+            invocation.<Runnable>getArgument(0).run();
+            return null;
+        }).when(eventLoop).execute(any(Runnable.class));
+
         final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, SESSION_ID);
         final HelloMessage hello = HelloMessage.createClientHello(Set.of(), Optional.empty());
         testingNetconfSession.sendMessage(hello);
index 20690f7fad804f03d0d368f8d9facbf35d68d55b..ac7725d7331ba32e21640154f561b15df87cfa6d 100644 (file)
@@ -7,8 +7,8 @@
  */
 package org.opendaylight.netconf.nettyutil;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.opendaylight.netconf.nettyutil.AbstractChannelInitializer.NETCONF_MESSAGE_AGGREGATOR;
 import static org.opendaylight.netconf.nettyutil.AbstractChannelInitializer.NETCONF_MESSAGE_FRAME_ENCODER;
 
@@ -17,11 +17,11 @@ import io.netty.channel.embedded.EmbeddedChannel;
 import io.netty.util.concurrent.Promise;
 import java.util.Optional;
 import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.netconf.api.CapabilityURN;
 import org.opendaylight.netconf.api.NetconfSessionListener;
 import org.opendaylight.netconf.api.messages.HelloMessage;
@@ -34,8 +34,8 @@ import org.opendaylight.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecode
 import org.opendaylight.netconf.test.util.XmlFileLoader;
 import org.w3c.dom.Document;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class Netconf539Test {
+@ExtendWith(MockitoExtension.class)
+class Netconf539Test {
     @Mock
     private NetconfSessionListener<TestingNetconfSession> listener;
     @Mock
@@ -44,8 +44,8 @@ public class Netconf539Test {
     private EmbeddedChannel channel;
     private TestSessionNegotiator negotiator;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() {
         channel = new EmbeddedChannel();
         channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER,
             new ChannelInboundHandlerAdapter());
@@ -60,12 +60,12 @@ public class Netconf539Test {
     }
 
     @Test
-    public void testGetSessionForHelloMessageDefaultNs() throws Exception {
+    void testGetSessionForHelloMessageDefaultNs() throws Exception {
         testGetSessionForHelloMessage("netconf539/client_hello_1.1.xml");
     }
 
     @Test
-    public void testGetSessionForHelloMessageNsPrefix() throws Exception {
+    void testGetSessionForHelloMessageNsPrefix() throws Exception {
         testGetSessionForHelloMessage("netconf539/client_hello_1.1_ns.xml");
     }
 
@@ -75,9 +75,9 @@ public class Netconf539Test {
         final HelloMessage helloMessage = new HelloMessage(helloDocument);
         final TestingNetconfSession session = negotiator.getSessionForHelloMessage(helloMessage);
         assertNotNull(session);
-        assertTrue("NetconfChunkAggregator was not installed in the Netconf pipeline",
-            channel.pipeline().get(NETCONF_MESSAGE_AGGREGATOR) instanceof NetconfChunkAggregator);
-        assertTrue("ChunkedFramingMechanismEncoder was not installed in the Netconf pipeline",
-            channel.pipeline().get(NETCONF_MESSAGE_FRAME_ENCODER) instanceof ChunkedFramingMechanismEncoder);
+        assertInstanceOf(NetconfChunkAggregator.class, channel.pipeline().get(NETCONF_MESSAGE_AGGREGATOR),
+            "NetconfChunkAggregator was not installed in the Netconf pipeline");
+        assertInstanceOf(ChunkedFramingMechanismEncoder.class, channel.pipeline().get(NETCONF_MESSAGE_FRAME_ENCODER),
+            "ChunkedFramingMechanismEncoder was not installed in the Netconf pipeline");
     }
 }
index c6f096675ba8a38b934a3da38f7b20cf7ab3f344..e641ed9981184caaa237465db997e5627d09529f 100644 (file)
@@ -8,47 +8,42 @@
 
 package org.opendaylight.netconf.nettyutil.handler;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelHandlerContext;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class ChunkedFramingMechanismEncoderTest {
+@ExtendWith(MockitoExtension.class)
+class ChunkedFramingMechanismEncoderTest {
 
-    private int chunkSize;
+    private static final int CHUNK_SIZE = 256;
     @Mock
     private ChannelHandlerContext ctx;
 
-    @Before
-    public void setUp() {
-        chunkSize = 256;
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testIllegalSize() throws Exception {
-        new ChunkedFramingMechanismEncoder(10);
+    @Test
+    void testIllegalSize() {
+        assertThrows(IllegalArgumentException.class, () -> new ChunkedFramingMechanismEncoder(10));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testIllegalSizeMax() throws Exception {
-        new ChunkedFramingMechanismEncoder(Integer.MAX_VALUE);
+    @Test
+    void testIllegalSizeMax() {
+        assertThrows(IllegalArgumentException.class, () -> new ChunkedFramingMechanismEncoder(Integer.MAX_VALUE));
     }
 
     @Test
-    public void testEncode() throws Exception {
-        final ChunkedFramingMechanismEncoder encoder = new ChunkedFramingMechanismEncoder(chunkSize);
+    void testEncode() {
+        final ChunkedFramingMechanismEncoder encoder = new ChunkedFramingMechanismEncoder(CHUNK_SIZE);
         final int lastChunkSize = 20;
-        final ByteBuf src = Unpooled.wrappedBuffer(getByteArray(chunkSize * 4 + lastChunkSize));
+        final ByteBuf src = Unpooled.wrappedBuffer(getByteArray(CHUNK_SIZE * 4 + lastChunkSize));
         final ByteBuf destination = Unpooled.buffer();
         encoder.encode(ctx, src, destination);
 
index b00de8ad5f0b9d8413b4865eb4117238a2d79c2e..bf3a2200e16b9615f368c2f714593311b8a219a1 100644 (file)
@@ -8,16 +8,16 @@
 
 package org.opendaylight.netconf.nettyutil.handler;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class EOMFramingMechanismEncoderTest {
+class EOMFramingMechanismEncoderTest {
 
     @Test
-    public void testEncode() throws Exception {
+    void testEncode() {
         final byte[] content = new byte[50];
         final ByteBuf source = Unpooled.wrappedBuffer(content);
         final ByteBuf destination = Unpooled.buffer();
index 9c5a83e625919a64f15dbd7ebf903fc7c5e67435..b2a728942affc6ab9e1bdad3552e8916c0b6f65e 100644 (file)
@@ -7,15 +7,15 @@
  */
 package org.opendaylight.netconf.nettyutil.handler;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class NetconfChunkAggregatorTest {
+class NetconfChunkAggregatorTest {
     private static final String CHUNKED_MESSAGE = "\n#4\n"
             + "<rpc"
             + "\n#18\n"
@@ -36,7 +36,7 @@ public class NetconfChunkAggregatorTest {
     private final NetconfChunkAggregator agr = new NetconfChunkAggregator(4096);
 
     @Test
-    public void testMultipleChunks() throws Exception {
+    void testMultipleChunks() {
         final var output = new ArrayList<>();
         final var input = Unpooled.copiedBuffer(CHUNKED_MESSAGE.getBytes(StandardCharsets.UTF_8));
         agr.decode(null, input, output);
@@ -48,7 +48,7 @@ public class NetconfChunkAggregatorTest {
     }
 
     @Test
-    public void testOneChunks() throws Exception {
+    void testOneChunks() {
         final var output = new ArrayList<>();
         final var input = Unpooled.copiedBuffer(CHUNKED_MESSAGE_ONE.getBytes(StandardCharsets.UTF_8));
         agr.decode(null, input, output);
index f9a156732f6102b88ae4473d9aeadca5a3c15eb1..fde6f2603f6f53d57fbbbdd57fc621881f6f4565 100644 (file)
@@ -7,17 +7,17 @@
  */
 package org.opendaylight.netconf.nettyutil.handler;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.nio.charset.Charset;
 import java.util.LinkedList;
 import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class NetconfEOMAggregatorTest {
+class NetconfEOMAggregatorTest {
     private static final String COMM_1 = """
         <?xml version="1.0" encoding="UTF-8"?>
         <rpc-reply message-id="105"
@@ -157,13 +157,13 @@ public class NetconfEOMAggregatorTest {
 
     private static NetconfEOMAggregator aggregator;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() throws Exception {
         aggregator = new NetconfEOMAggregator();
     }
 
     @Test
-    public void testDecodeMessagesReadAtOnce() {
+    void testDecodeMessagesReadAtOnce() {
         final ByteBuf in = Unpooled.copiedBuffer(COMM_1.getBytes());
         final List<Object> out = new LinkedList<>();
 
@@ -174,7 +174,7 @@ public class NetconfEOMAggregatorTest {
     }
 
     @Test
-    public void testDecodeMessagesReadByteByByte() {
+    void testDecodeMessagesReadByteByByte() {
         final ByteBuf in = Unpooled.buffer();
         final List<Object> out = new LinkedList<>();
 
@@ -189,7 +189,7 @@ public class NetconfEOMAggregatorTest {
     }
 
     @Test
-    public void testDecodeMultipleStreams() {
+    void testDecodeMultipleStreams() {
         final ByteBuf in = Unpooled.copiedBuffer(COMM_1.getBytes());
         final List<Object> out = new LinkedList<>();
 
@@ -205,7 +205,7 @@ public class NetconfEOMAggregatorTest {
     }
 
     @Test
-    public void testDecodeBufferReset() {
+    void testDecodeBufferReset() {
         final ByteBuf in = Unpooled.buffer();
         final List<Object> out = new LinkedList<>();
 
@@ -227,7 +227,7 @@ public class NetconfEOMAggregatorTest {
     }
 
     @Test
-    public void testDecodeEmptyMessage() {
+    void testDecodeEmptyMessage() {
         final ByteBuf in = Unpooled.buffer();
         final List<Object> out = new LinkedList<>();
 
index 2bdca15596c5da64ebcd7ede52f01bd024add39e..7e251e7ae76ce9d2185d3e222ae5a1e08242210b 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.netconf.nettyutil.handler;
 
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 
 import io.netty.buffer.Unpooled;
 import java.io.ByteArrayOutputStream;
@@ -17,14 +17,14 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXResult;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.netconf.api.messages.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.nettyutil.handler.exi.EXIParameters;
 import org.xmlunit.builder.DiffBuilder;
 
-public class NetconfEXIHandlersTest {
+class NetconfEXIHandlersTest {
     private final String msgAsString = "<netconf-message/>";
 
     private NetconfMessageToEXIEncoder netconfMessageToEXIEncoder;
@@ -32,8 +32,8 @@ public class NetconfEXIHandlersTest {
     private NetconfMessage msg;
     private byte[] msgAsExi;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() throws Exception {
         final var codec = NetconfEXICodec.forParameters(EXIParameters.empty());
         netconfMessageToEXIEncoder = NetconfMessageToEXIEncoder.create(codec);
         netconfEXIToMessageDecoder = NetconfEXIToMessageDecoder.create(codec);
@@ -52,7 +52,7 @@ public class NetconfEXIHandlersTest {
     }
 
     @Test
-    public void testEncodeDecode() throws Exception {
+    void testEncodeDecode() throws Exception {
         final var buffer = Unpooled.buffer();
         netconfMessageToEXIEncoder.encode(null, msg, buffer);
         final int exiLength = msgAsExi.length;
@@ -71,6 +71,6 @@ public class NetconfEXIHandlersTest {
             .withTest(((NetconfMessage) out.get(0)).getDocument())
             .checkForIdentical()
             .build();
-        assertFalse(diff.toString(), diff.hasDifferences());
+        assertFalse(diff.hasDifferences(), diff.toString());
     }
 }
index 3eb29f46b09bc04c6a05d3e85361679fbb7b2b43..00e84a27fa286229d59d694dbdf82ca6dc086aa9 100644 (file)
@@ -15,23 +15,23 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelHandlerContext;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.netconf.api.messages.HelloMessage;
 import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
 import org.opendaylight.netconf.api.messages.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfHelloMessageToXMLEncoderTest {
+@ExtendWith(MockitoExtension.class)
+class NetconfHelloMessageToXMLEncoderTest {
 
     @Mock
     private ChannelHandlerContext ctx;
 
     @Test
-    public void testEncode() throws Exception {
+    void testEncode() throws Exception {
         final NetconfMessage msg = new HelloMessage(XmlUtil.readXmlToDocument(
                 "<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"),
                 NetconfHelloMessageAdditionalHeader.fromString("[tomas;10.0.0.0:10000;tcp;client;]"));
@@ -44,7 +44,7 @@ public class NetconfHelloMessageToXMLEncoderTest {
     }
 
     @Test
-    public void testEncodeNoHeader() throws Exception {
+    void testEncodeNoHeader() throws Exception {
         final NetconfMessage msg = new HelloMessage(XmlUtil.readXmlToDocument(
                 "<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
         final ByteBuf destination = Unpooled.buffer();
@@ -56,7 +56,7 @@ public class NetconfHelloMessageToXMLEncoderTest {
     }
 
     @Test
-    public void testEncodeNotHello() throws Exception {
+    void testEncodeNotHello() throws Exception {
         final NetconfMessage msg = new NetconfMessage(XmlUtil.readXmlToDocument(
                 "<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
         assertThrows(IllegalStateException.class, () -> new NetconfHelloMessageToXMLEncoder().encode(ctx, msg, null));
index eae85439bff24c1239b0d55ea0a895031d553f49..4e28b4da0a6a972b1134c0ad8dd6bd2264aa2fa8 100644 (file)
@@ -7,18 +7,18 @@
  */
 package org.opendaylight.netconf.nettyutil.handler;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import io.netty.buffer.Unpooled;
 import java.io.File;
 import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class NetconfMessageFactoryTest {
+class NetconfMessageFactoryTest {
     @Test
-    public void testAuth() throws Exception {
+    void testAuth() throws Exception {
         NetconfXMLToHelloMessageDecoder parser = new NetconfXMLToHelloMessageDecoder();
         File authHelloFile = new File(getClass().getResource("/netconfMessages/client_hello_with_auth.xml").getFile());
 
index b9f0d18daf70570e773abe387503eb5039f91971..55b9369258513e96b2f9e19e43e5ad3d5cd3f004 100644 (file)
@@ -8,9 +8,11 @@
 package org.opendaylight.netconf.nettyutil.handler;
 
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import com.google.common.collect.Iterables;
 import io.netty.buffer.ByteBuf;
@@ -18,14 +20,14 @@ import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
 import java.util.List;
 import org.hamcrest.CoreMatchers;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.netconf.api.messages.HelloMessage;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 
-public class NetconfXMLToHelloMessageDecoderTest {
+class NetconfXMLToHelloMessageDecoderTest {
 
     @Test
-    public void testDecodeWithHeader() throws Exception {
+    void testDecodeWithHeader() throws Exception {
         final ByteBuf src = Unpooled.wrappedBuffer(String.format("%s\n%s",
                 "[tomas;10.0.0.0:10000;tcp;client;]",
                 "<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>").getBytes());
@@ -33,8 +35,7 @@ public class NetconfXMLToHelloMessageDecoderTest {
         new NetconfXMLToHelloMessageDecoder().decode(null, src, out);
 
         assertEquals(1, out.size());
-        assertThat(out.get(0), CoreMatchers.instanceOf(HelloMessage.class));
-        final HelloMessage hello = (HelloMessage) out.get(0);
+        final HelloMessage hello = assertInstanceOf(HelloMessage.class, out.get(0));
         assertTrue(hello.getAdditionalHeader().isPresent());
         assertEquals("[tomas;10.0.0.0:10000;tcp;client;]" + System.lineSeparator(),
                 hello.getAdditionalHeader().orElseThrow().toFormattedString());
@@ -43,20 +44,19 @@ public class NetconfXMLToHelloMessageDecoderTest {
     }
 
     @Test
-    public void testDecodeNoHeader() throws Exception {
+    void testDecodeNoHeader() throws Exception {
         final ByteBuf src =
                 Unpooled.wrappedBuffer("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>".getBytes());
         final List<Object> out = new ArrayList<>();
         new NetconfXMLToHelloMessageDecoder().decode(null, src, out);
 
         assertEquals(1, out.size());
-        assertThat(out.get(0), CoreMatchers.instanceOf(HelloMessage.class));
-        final HelloMessage hello = (HelloMessage) out.get(0);
+        final HelloMessage hello = assertInstanceOf(HelloMessage.class, out.get(0));
         assertFalse(hello.getAdditionalHeader().isPresent());
     }
 
     @Test
-    public void testDecodeCaching() throws Exception {
+    void testDecodeCaching() throws Exception {
         final ByteBuf msg1 =
                 Unpooled.wrappedBuffer("<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>".getBytes());
         final ByteBuf msg2 =
@@ -74,12 +74,12 @@ public class NetconfXMLToHelloMessageDecoderTest {
         assertEquals(2, Iterables.size(decoder.getPostHelloNetconfMessages()));
     }
 
-    @Test(expected = IllegalStateException.class)
-    public void testDecodeNotHelloReceived() throws Exception {
+    @Test
+    void testDecodeNotHelloReceived() {
         final ByteBuf msg1 =
                 Unpooled.wrappedBuffer("<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>".getBytes());
         final List<Object> out = new ArrayList<>();
         NetconfXMLToHelloMessageDecoder decoder = new NetconfXMLToHelloMessageDecoder();
-        decoder.decode(null, msg1, out);
+        assertThrows(IllegalStateException.class, () -> decoder.decode(null, msg1, out));
     }
 }
index 6a0d79f0d07d282017c59325e1f070a3c887f5d7..020713a24324c66e6aaf4c09b3dfa80ffda21f3d 100644 (file)
@@ -7,35 +7,33 @@
  */
 package org.opendaylight.netconf.nettyutil.handler;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.netconf.api.messages.NetconfMessage;
 import org.xml.sax.SAXParseException;
 
-public class NetconfXMLToMessageDecoderTest {
+class NetconfXMLToMessageDecoderTest {
 
     @Test
-    public void testDecodeNoMoreContent() throws Exception {
+    void testDecodeNoMoreContent() throws Exception {
         final ArrayList<Object> out = new ArrayList<>();
         new NetconfXMLToMessageDecoder().decode(null, Unpooled.buffer(), out);
         assertEquals(0, out.size());
     }
 
     @Test
-    public void testDecode() throws Exception {
+    void testDecode() throws Exception {
         final ArrayList<Object> out = new ArrayList<>();
         new NetconfXMLToMessageDecoder().decode(null, Unpooled.wrappedBuffer("<msg/>".getBytes()), out);
         assertEquals(1, out.size());
     }
 
     @Test
-    public void testDecodeWithLeadingLFAndXmlDecl() throws Exception {
+    void testDecodeWithLeadingLFAndXmlDecl() throws Exception {
         /* Test that we accept XML documents with a line feed (0x0a) before the
          * XML declaration in the XML prologue.
          * A leading LF is the case reported in BUG-2838.
@@ -47,7 +45,7 @@ public class NetconfXMLToMessageDecoderTest {
     }
 
     @Test
-    public void testDecodeWithLeadingCRLFAndXmlDecl() throws Exception {
+    void testDecodeWithLeadingCRLFAndXmlDecl() throws Exception {
         /* Test that we accept XML documents with both a carriage return and
          * line feed (0x0d 0x0a) before the XML declaration in the XML prologue.
          * Leading CRLF can be seen with some Cisco routers
@@ -60,16 +58,16 @@ public class NetconfXMLToMessageDecoderTest {
     }
 
     @Test
-    public void testDecodeGibberish() throws Exception {
+    void testDecodeGibberish() throws Exception {
         /* Test that we reject inputs where we cannot find the xml start '<' character */
         final ArrayList<Object> out = new ArrayList<>();
         new NetconfXMLToMessageDecoder().decode(null, Unpooled.wrappedBuffer("\r\n?xml version>".getBytes()), out);
         assertEquals(1, out.size());
-        assertTrue((out.get(0) instanceof SAXParseException));
+        assertInstanceOf(SAXParseException.class, out.get(0));
     }
 
     @Test
-    public void testDecodeOnlyWhitespaces() throws Exception {
+    void testDecodeOnlyWhitespaces() throws Exception {
         /* Test that we handle properly a bunch of whitespaces.
          */
         final ArrayList<Object> out = new ArrayList<>();
@@ -78,7 +76,7 @@ public class NetconfXMLToMessageDecoderTest {
     }
 
     @Test
-    public void testDecodeWithAllWhitespaces() throws Exception {
+    void testDecodeWithAllWhitespaces() throws Exception {
         /* Test that every whitespace we want to skip is actually skipped.
          */
 
@@ -94,7 +92,7 @@ public class NetconfXMLToMessageDecoderTest {
     }
 
     @Test
-    public void testDecodeAfterInvalidXml() throws Exception {
+    void testDecodeAfterInvalidXml() throws Exception {
         /* Test that decoding of the next message after an invalid XML is successful.
         */
         final var out = new ArrayList<>();
@@ -104,11 +102,11 @@ public class NetconfXMLToMessageDecoderTest {
         buffer.writeBytes("<?xml version=\"1.0\"\u0006 encoding=\"UTF-8\"?><msg/>".getBytes());
         decoder.decode(null, buffer, out);
         assertEquals(1, out.size());
-        assertThat(out.get(0), instanceOf(SAXParseException.class));
+        assertInstanceOf(SAXParseException.class, out.get(0));
 
         buffer.writeBytes("<msg/>".getBytes());
         decoder.decode(null, buffer, out);
         assertEquals(2, out.size());
-        assertThat(out.get(1), instanceOf(NetconfMessage.class));
+        assertInstanceOf(NetconfMessage.class, out.get(1));
     }
 }
index 456663b3b96e285768a5636b60de9aa94659dbd2..66fc12916b23611e938b726dd331ea1dccc75d5c 100644 (file)
@@ -8,44 +8,46 @@
 
 package org.opendaylight.netconf.nettyutil.handler;
 
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import javax.xml.transform.Transformer;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class ThreadLocalTransformersTest {
+class ThreadLocalTransformersTest {
 
     private ExecutorService executorService;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() {
         executorService = Executors.newSingleThreadExecutor();
     }
 
     @Test
-    public void testGetDefaultTransformer() throws Exception {
+    void testGetDefaultTransformer() throws Exception {
         final Transformer t1 = ThreadLocalTransformers.getDefaultTransformer();
         final Transformer t2 = ThreadLocalTransformers.getDefaultTransformer();
-        Assert.assertSame(t1, t2);
+        assertSame(t1, t2);
         final Future<Transformer> future = executorService.submit(ThreadLocalTransformers::getDefaultTransformer);
-        Assert.assertNotSame(t1, future.get());
+        assertNotSame(t1, future.get());
     }
 
     @Test
-    public void testGetPrettyTransformer() throws Exception {
+    void testGetPrettyTransformer() throws Exception {
         final Transformer t1 = ThreadLocalTransformers.getPrettyTransformer();
         final Transformer t2 = ThreadLocalTransformers.getPrettyTransformer();
-        Assert.assertSame(t1, t2);
+        assertSame(t1, t2);
         final Future<Transformer> future = executorService.submit(ThreadLocalTransformers::getPrettyTransformer);
-        Assert.assertNotSame(t1, future.get());
+        assertNotSame(t1, future.get());
     }
 
-    @After
-    public void tearDown() throws Exception {
+    @AfterEach
+    void tearDown() {
         executorService.shutdown();
     }
-}
\ No newline at end of file
+}
index 407615f78969df7927df4261f5f35d466089766c..462b7844c2c51de90b5836addcf0b7b75b54fc58 100644 (file)
@@ -8,73 +8,62 @@
 
 package org.opendaylight.netconf.nettyutil.handler.exi;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
-import java.util.Arrays;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import java.util.stream.Stream;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.shaded.exificient.core.CodingMode;
-import org.opendaylight.netconf.shaded.exificient.core.EXIFactory;
 import org.opendaylight.netconf.shaded.exificient.core.FidelityOptions;
 
-@RunWith(Parameterized.class)
-public class EXIParametersTest {
+class EXIParametersTest {
 
-    @Parameterized.Parameters
-    public static Iterable<Object[]> data() throws Exception {
-        final String noChangeXml =
-                "<start-exi xmlns=\"urn:ietf:params:xml:ns:netconf:exi:1.0\">\n"
-                + "<alignment>bit-packed</alignment>\n"
-                + "</start-exi>\n";
+    @ParameterizedTest
+    @MethodSource("getData")
+    void testFromXmlElement(final String sourceXml, final CodingMode coding, final FidelityOptions fidelity)
+            throws Exception {
+        final var opts =
+            EXIParameters.fromXmlElement(
+                XmlElement.fromDomElement(
+                    XmlUtil.readXmlToElement(sourceXml)));
 
+        final var factory = opts.getFactory();
+        assertEquals(fidelity, factory.getFidelityOptions());
+        assertEquals(coding, factory.getCodingMode());
+    }
+
+    static Stream<Arguments> getData() throws Exception {
+        final var noChangeXml =
+            "<start-exi xmlns=\"urn:ietf:params:xml:ns:netconf:exi:1.0\">\n"
+            + "<alignment>bit-packed</alignment>\n"
+            + "</start-exi>\n";
 
-        final String fullOptionsXml =
-                "<start-exi xmlns=\"urn:ietf:params:xml:ns:netconf:exi:1.0\">\n"
-                + "<alignment>byte-aligned</alignment>\n"
-                + "<fidelity>\n"
-                + "<comments/>\n"
-                + "<dtd/>\n"
-                + "<lexical-values/>\n"
-                + "<pis/>\n"
-                + "<prefixes/>\n"
-                + "</fidelity>\n"
-                + "</start-exi>\n";
 
-        final FidelityOptions fullOptions = FidelityOptions.createDefault();
+        final var fullOptionsXml =
+            "<start-exi xmlns=\"urn:ietf:params:xml:ns:netconf:exi:1.0\">\n"
+            + "<alignment>byte-aligned</alignment>\n"
+            + "<fidelity>\n"
+            + "<comments/>\n"
+            + "<dtd/>\n"
+            + "<lexical-values/>\n"
+            + "<pis/>\n"
+            + "<prefixes/>\n"
+            + "</fidelity>\n"
+            + "</start-exi>\n";
+
+        final var fullOptions = FidelityOptions.createDefault();
         fullOptions.setFidelity(FidelityOptions.FEATURE_LEXICAL_VALUE, true);
         fullOptions.setFidelity(FidelityOptions.FEATURE_DTD, true);
         fullOptions.setFidelity(FidelityOptions.FEATURE_COMMENT, true);
         fullOptions.setFidelity(FidelityOptions.FEATURE_PREFIX, true);
         fullOptions.setFidelity(FidelityOptions.FEATURE_PI, true);
 
-        return Arrays.asList(new Object[][]{
-            {noChangeXml, CodingMode.BIT_PACKED, FidelityOptions.createDefault()},
-            {fullOptionsXml, CodingMode.BYTE_PACKED, fullOptions},
-        });
-    }
-
-    private final String sourceXml;
-    private final CodingMode coding;
-    private final FidelityOptions fidelity;
-
-    public EXIParametersTest(final String sourceXml, final CodingMode coding, final FidelityOptions fidelity) {
-        this.sourceXml = sourceXml;
-        this.coding = coding;
-        this.fidelity = fidelity;
-    }
-
-    @Test
-    public void testFromXmlElement() throws Exception {
-        final EXIParameters opts =
-                EXIParameters.fromXmlElement(
-                        XmlElement.fromDomElement(
-                                XmlUtil.readXmlToElement(sourceXml)));
-
-        final EXIFactory factory = opts.getFactory();
-        assertEquals(fidelity, factory.getFidelityOptions());
-        assertEquals(coding, factory.getCodingMode());
+        return Stream.of(
+            Arguments.of(noChangeXml, CodingMode.BIT_PACKED, FidelityOptions.createDefault()),
+            Arguments.of(fullOptionsXml, CodingMode.BYTE_PACKED, fullOptions)
+        );
     }
 }
index 68ae7947c564826818ed08334edddfcd3d8e9735..de94715b27b41e01008c2bbde431ad98e8ade4f1 100644 (file)
@@ -7,16 +7,16 @@
  */
 package org.opendaylight.netconf.nettyutil.handler.exi;
 
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.netconf.shaded.exificient.core.CodingMode;
 import org.opendaylight.netconf.shaded.exificient.core.FidelityOptions;
 import org.xmlunit.builder.DiffBuilder;
 
-public class NetconfStartExiMessageTest {
+class NetconfStartExiMessageTest {
     @Test
-    public void testCreateEmpty() {
+    void testCreateEmpty() {
         assertCreate("""
               <rpc message-id="id" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
               <start-exi xmlns="urn:ietf:params:xml:ns:netconf:exi:1.0">
@@ -26,7 +26,7 @@ public class NetconfStartExiMessageTest {
     }
 
     @Test
-    public void testCreateFull() throws Exception {
+    void testCreateFull() throws Exception {
         final var fullOptions = FidelityOptions.createDefault();
         fullOptions.setFidelity(FidelityOptions.FEATURE_LEXICAL_VALUE, true);
         fullOptions.setFidelity(FidelityOptions.FEATURE_DTD, true);
@@ -57,7 +57,7 @@ public class NetconfStartExiMessageTest {
             .ignoreWhitespace()
             .checkForIdentical()
             .build();
-        assertFalse(diff.toString(), diff.hasDifferences());
+        assertFalse(diff.hasDifferences(), diff.toString());
     }
 
-}
\ No newline at end of file
+}