Migrate netconf-server/api tests to JUnit5 73/111773/1
authorlubos-cicut <lubos.cicut@pantheon.tech>
Mon, 20 May 2024 12:34:38 +0000 (14:34 +0200)
committerlubos-cicut <lubos.cicut@pantheon.tech>
Mon, 20 May 2024 12:34:38 +0000 (14:34 +0200)
Migrate tests in protocol/netconf-server/api from JUnit4 to JUnit5.

JIRA: NETCONF-1310
Change-Id: Ie99729cc76a6a88f29665e9f3b3790f51c055b5f
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
protocol/netconf-server/src/test/java/org/opendaylight/netconf/server/api/monitoring/SessionEventTest.java
protocol/netconf-server/src/test/java/org/opendaylight/netconf/server/api/operations/AbstractLastNetconfOperationTest.java
protocol/netconf-server/src/test/java/org/opendaylight/netconf/server/api/operations/AbstractNetconfOperationTest.java
protocol/netconf-server/src/test/java/org/opendaylight/netconf/server/api/operations/AbstractSingletonNetconfOperationTest.java
protocol/netconf-server/src/test/java/org/opendaylight/netconf/server/api/operations/HandlingPriorityTest.java

index 0714a132ae3cdb51474cb4e0e6d9b0b042dd389d..a772baf102b69dd133d6e5627be2c0e17c882605 100644 (file)
@@ -7,20 +7,20 @@
  */
 package org.opendaylight.netconf.server.api.monitoring;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
-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 SessionEventTest {
+@ExtendWith(MockitoExtension.class)
+class SessionEventTest {
     @Mock
     private NetconfManagementSession session;
 
     @Test
-    public void test() {
+    void test() {
         assertEquals(SessionEvent.Type.IN_RPC_FAIL, SessionEvent.inRpcFail(session).getType());
         assertEquals(SessionEvent.Type.IN_RPC_SUCCESS, SessionEvent.inRpcSuccess(session).getType());
         assertEquals(SessionEvent.Type.NOTIFICATION, SessionEvent.notification(session).getType());
index 8234d0e172480f888186c4ad834e3e73f63d6825..a7486f370db8691231e50c2d801ead8f862de9c5 100644 (file)
@@ -7,13 +7,14 @@
  */
 package org.opendaylight.netconf.server.api.operations;
 
-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 static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
-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.DocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
@@ -21,7 +22,7 @@ import org.opendaylight.yangtools.yang.common.Uint32;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-public class AbstractLastNetconfOperationTest {
+class AbstractLastNetconfOperationTest {
     private static final class LastNetconfOperationImplTest extends AbstractLastNetconfOperation {
         boolean handleWithNoSubsequentOperationsRun;
 
@@ -45,24 +46,24 @@ public class AbstractLastNetconfOperationTest {
 
     LastNetconfOperationImplTest netconfOperation;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() {
         netconfOperation = new LastNetconfOperationImplTest(new SessionIdType(Uint32.ONE));
     }
 
     @Test
-    public void testNetconfOperation() throws Exception {
+    void testNetconfOperation() throws Exception {
         netconfOperation.handleWithNoSubsequentOperations(null, null);
         assertTrue(netconfOperation.handleWithNoSubsequentOperationsRun);
         assertEquals(HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY, netconfOperation.getHandlingPriority());
     }
 
-    @Test(expected = DocumentedException.class)
-    public void testHandle() throws Exception {
+    @Test
+    void testHandle() {
         NetconfOperationChainedExecution operation = mock(NetconfOperationChainedExecution.class);
         doReturn("").when(operation).toString();
 
         doReturn(false).when(operation).isExecutionTermination();
-        netconfOperation.handle(null, null, operation);
+        assertThrows(DocumentedException.class, () -> netconfOperation.handle(null, null, operation));
     }
 }
index 490f93e9c4bfd3e6c078a4c56fd1974e43dfa5db..e408dba674fc1b4349569bf08bfaa9f6bcee4ae9 100644 (file)
@@ -7,13 +7,13 @@
  */
 package org.opendaylight.netconf.server.api.operations;
 
-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.assertTrue;
 import static org.mockito.Mockito.mock;
 
 import java.io.IOException;
-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.DocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlUtil;
@@ -24,7 +24,7 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
-public class AbstractNetconfOperationTest {
+class AbstractNetconfOperationTest {
     private static class NetconfOperationImpl extends AbstractNetconfOperation {
         public boolean handleRun;
 
@@ -52,13 +52,13 @@ public class AbstractNetconfOperationTest {
     private final NetconfOperationImpl netconfOperation = new NetconfOperationImpl(new SessionIdType(Uint32.ONE));
     private NetconfOperationChainedExecution operation;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() {
         operation = mock(NetconfOperationChainedExecution.class);
     }
 
     @Test
-    public void testAbstractNetconfOperation() throws Exception {
+    void testAbstractNetconfOperation() throws Exception {
         Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/edit_config.xml");
         assertEquals(new SessionIdType(Uint32.ONE), netconfOperation.sessionId());
         assertEquals(HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY, netconfOperation.canHandle(helloMessage));
index 55bf315fbf2f8363bf2df950b1c332a1d2f96b99..95e0f0642e5f13290e82382b2d623bcb9594c3fa 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.netconf.server.api.operations;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
@@ -17,7 +17,7 @@ import org.opendaylight.yangtools.yang.common.Uint32;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-public class AbstractSingletonNetconfOperationTest {
+class AbstractSingletonNetconfOperationTest {
     private static final class SingletonNCOperationImpl extends AbstractSingletonNetconfOperation {
         SingletonNCOperationImpl(final SessionIdType sessionId) {
             super(sessionId);
@@ -36,7 +36,7 @@ public class AbstractSingletonNetconfOperationTest {
     }
 
     @Test
-    public void testAbstractSingletonNetconfOperation() throws Exception {
+    void testAbstractSingletonNetconfOperation() {
         SingletonNCOperationImpl operation = new SingletonNCOperationImpl(new SessionIdType(Uint32.TEN));
         assertEquals(HandlingPriority.HANDLE_WITH_MAX_PRIORITY, operation.getHandlingPriority());
     }
index ac75de18c53414ba5564e01790db540329480500..bfda1ab6da9dd1b1fb6b496db75603821764bd21 100644 (file)
@@ -7,15 +7,15 @@
  */
 package org.opendaylight.netconf.server.api.operations;
 
-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.assertTrue;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class HandlingPriorityTest {
+class HandlingPriorityTest {
     @Test
-    public void testHandlingPriority() {
+    void testHandlingPriority() {
         assertEquals(0,
             HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.compareTo(HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY));