Migrate rfc8528-parser-support to JUnit5 06/106906/4
authormatus.matok <matus.matok@pantheon.tech>
Thu, 13 Jul 2023 08:34:52 +0000 (10:34 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 21 Jul 2023 13:41:43 +0000 (13:41 +0000)
Migrated all tests to use JUnit5 Assertions, using
openrewrite:rewrite-testing-frameworks. Also modernize the test by
taking advantage of assertInstanceOf's return.

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

index 2dcbc529a795499d8169454372c3bdb83d1315db..8231b916418870d6c0161f4a5408e5a6d821c4dc 100644 (file)
@@ -7,13 +7,10 @@
  */
 package org.opendaylight.yangtools.rfc8528.parser;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchemaNode;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -25,9 +22,8 @@ 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 MountPointTest {
+class MountPointTest {
     private static final QNameModule EXAMPLE_USES =
         QNameModule.create(XMLNamespace.of("http://example.org/example-uses"));
     private static final QName EXAMPLE_CONT = QName.create(EXAMPLE_USES, "cont");
@@ -35,54 +31,39 @@ public class MountPointTest {
     private static final QName EXAMPLE_GRP_CONT = QName.create(EXAMPLE_USES, "grp-cont");
     private static final QName EXAMPLE_LIST = QName.create(EXAMPLE_USES, "list");
 
-    private static CrossSourceStatementReactor reactor;
-
-    @BeforeClass
-    public static void createReactor() {
-        reactor = RFC7950Reactors.vanillaReactorBuilder()
-                .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
-                    new MountPointStatementSupport(YangParserConfiguration.DEFAULT))
-                .build();
-    }
-
-    @AfterClass
-    public static void freeReactor() {
-        reactor = null;
-    }
-
     @Test
-    public void testMountPointResolution() throws Exception {
+    void testMountPointResolution() throws Exception {
+        final var reactor = RFC7950Reactors.vanillaReactorBuilder()
+            .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
+                new MountPointStatementSupport(YangParserConfiguration.DEFAULT))
+            .build();
+
         final var context = reactor.newBuild()
-                .addLibSources(
-                    YangStatementStreamSource.create(YangTextSchemaSource.forResource(
-                            "/ietf-inet-types@2013-07-15.yang")),
-                    YangStatementStreamSource.create(YangTextSchemaSource.forResource(
-                            "/ietf-yang-schema-mount@2019-01-14.yang")),
-                    YangStatementStreamSource.create(YangTextSchemaSource.forResource(
-                            "/ietf-yang-types@2013-07-15.yang")))
-                .addSources(
-                    YangStatementStreamSource.create(YangTextSchemaSource.forResource("/example-grp.yang")),
-                    YangStatementStreamSource.create(YangTextSchemaSource.forResource("/example-uses.yang")))
-                .buildEffective();
+            .addLibSources(
+                YangStatementStreamSource.create(YangTextSchemaSource.forResource("/ietf-inet-types@2013-07-15.yang")),
+                YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+                    "/ietf-yang-schema-mount@2019-01-14.yang")),
+                YangStatementStreamSource.create(YangTextSchemaSource.forResource("/ietf-yang-types@2013-07-15.yang")))
+            .addSources(
+                YangStatementStreamSource.create(YangTextSchemaSource.forResource("/example-grp.yang")),
+                YangStatementStreamSource.create(YangTextSchemaSource.forResource("/example-uses.yang")))
+            .buildEffective();
 
         assertEquals(5, context.getModules().size());
 
         var child = context.findDataTreeChild(EXAMPLE_CONT).orElseThrow();
-        assertThat(child, instanceOf(ContainerSchemaNode.class));
-        var mps = MountPointSchemaNode.streamAll((ContainerSchemaNode) child).toList();
+        var mps = MountPointSchemaNode.streamAll(assertInstanceOf(ContainerSchemaNode.class, child)).toList();
         assertEquals(2, mps.size());
         assertEquals(EXAMPLE_CONT, mps.get(0).getQName());
         assertEquals(EXAMPLE_CONT, mps.get(1).getQName());
 
         child = context.findDataTreeChild(EXAMPLE_GRP_CONT).orElseThrow();
-        assertThat(child, instanceOf(ContainerSchemaNode.class));
-        mps = MountPointSchemaNode.streamAll((ContainerSchemaNode) child).toList();
+        mps = MountPointSchemaNode.streamAll(assertInstanceOf(ContainerSchemaNode.class, child)).toList();
         assertEquals(1, mps.size());
         assertEquals(EXAMPLE_GRP, mps.get(0).getQName());
 
         child = context.findDataTreeChild(EXAMPLE_LIST).orElseThrow();
-        assertThat(child, instanceOf(ListSchemaNode.class));
-        mps = MountPointSchemaNode.streamAll((ListSchemaNode) child).toList();
+        mps = MountPointSchemaNode.streamAll(assertInstanceOf(ListSchemaNode.class, child)).toList();
         assertEquals(1, mps.size());
         assertEquals(EXAMPLE_LIST, mps.get(0).getQName());
     }