Migrate rfc6241-parser-support to JUnit5 01/106901/4
authormatus.matok <matus.matok@pantheon.tech>
Thu, 13 Jul 2023 08:10:49 +0000 (10:10 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 21 Jul 2023 11:10:08 +0000 (11:10 +0000)
Migrated all tests to use JUnit5 Assertions, using
openrewrite:rewrite-testing-frameworks, and also modernizing the test.

JIRA: YANGTOOLS-1521
Change-Id: I7a87deb0d57c664b219e96258cb7254e80c30318
Signed-off-by: matus.matok <matus.matok@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
parser/rfc6241-parser-support/src/test/java/org/opendaylight/yangtools/rfc6241/parser/NetconfTest.java

index eba84fa2f68d0556e85e00aae87044cb3d38f8fa..450fc51ce79c54ba27ae118c7fb141d882fc2bfc 100644 (file)
@@ -7,15 +7,11 @@
  */
 package org.opendaylight.yangtools.rfc6241.parser;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-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 static org.junit.jupiter.api.Assertions.assertTrue;
 
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.rfc6241.model.api.GetFilterElementAttributesSchemaNode;
 import org.opendaylight.yangtools.rfc6241.model.api.NetconfConstants;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -26,34 +22,22 @@ import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 
-public class NetconfTest {
+class NetconfTest {
     private static final QName FILTER = QName.create(NetconfConstants.RFC6241_MODULE, "filter");
 
-    private static CrossSourceStatementReactor reactor;
-
-    @BeforeClass
-    public static void createReactor() {
-        reactor = RFC7950Reactors.defaultReactorBuilder()
-                .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
-                    new GetFilterElementAttributesStatementSupport(YangParserConfiguration.DEFAULT))
-                .build();
-    }
-
-    @AfterClass
-    public static void freeReactor() {
-        reactor = null;
-    }
-
     @Test
-    public void testResolution() throws Exception {
+    void testResolution() throws Exception {
+        final var reactor = RFC7950Reactors.defaultReactorBuilder()
+            .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
+                new GetFilterElementAttributesStatementSupport(YangParserConfiguration.DEFAULT))
+            .build();
         final var context = reactor.newBuild()
-                .addLibSources(YangStatementStreamSource.create(
-                    YangTextSchemaSource.forResource("/ietf-inet-types@2013-07-15.yang")))
-                .addSource(YangStatementStreamSource.create(
-                    YangTextSchemaSource.forResource("/ietf-netconf@2011-06-01.yang")))
-                .buildEffective();
+            .addLibSources(YangStatementStreamSource.create(
+                YangTextSchemaSource.forResource("/ietf-inet-types@2013-07-15.yang")))
+            .addSource(YangStatementStreamSource.create(
+                YangTextSchemaSource.forResource("/ietf-netconf@2011-06-01.yang")))
+            .buildEffective();
 
         final var module = context.findModule(NetconfConstants.RFC6241_MODULE).orElseThrow();
         final var rpcs = module.getRpcs();
@@ -75,8 +59,8 @@ public class NetconfTest {
         final var optFilter = def.getInput().findDataTreeChild(FILTER);
         assertEquals(expected, optFilter.isPresent());
         optFilter.ifPresent(filter -> {
-            assertThat(filter, is(instanceOf(AnyxmlSchemaNode.class)));
-            assertTrue(GetFilterElementAttributesSchemaNode.findIn((AnyxmlSchemaNode) filter).isPresent());
+            final var anyxmlFilter = assertInstanceOf(AnyxmlSchemaNode.class, filter);
+            assertTrue(GetFilterElementAttributesSchemaNode.findIn(anyxmlFilter).isPresent());
         });
     }
 }