Migrate odlext-parser-support to JUnit5 00/106900/7
authormatus.matok <matus.matok@pantheon.tech>
Thu, 13 Jul 2023 08:03:57 +0000 (10:03 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 21 Jul 2023 11:09:19 +0000 (11:09 +0000)
Migrated all tests to use JUnit5 Assertions, using
openrewrite:rewrite-testing-frameworks. Also modernize the tests a bit
and remove unnecessary initialization.

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

index 097887b5592ca26dd269c561364491854d567811..df42d4543161914b6b422b5ea20683a95a8ca94c 100644 (file)
@@ -7,90 +7,70 @@
  */
 package org.opendaylight.yangtools.odlext.parser;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertSame;
 
-import java.util.List;
-import java.util.stream.Collectors;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.odlext.model.api.ContextInstanceEffectiveStatement;
 import org.opendaylight.yangtools.odlext.model.api.ContextReferenceEffectiveStatement;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 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 ContextReferenceTest {
+class ContextReferenceTest {
     private static final QNameModule FOO = QNameModule.create(XMLNamespace.of("foo"));
     private static final QName LEAF_TYPE = QName.create(FOO, "leaf-type");
     private static final QName LIST_TYPE = QName.create(FOO, "list-type");
 
-    private static CrossSourceStatementReactor reactor;
-
-    @BeforeClass
-    public static void createReactor() {
-        reactor = RFC7950Reactors.vanillaReactorBuilder()
+    @Test
+    void test() throws Exception {
+        final var reactor = RFC7950Reactors.vanillaReactorBuilder()
             .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
                 new ContextInstanceStatementSupport(YangParserConfiguration.DEFAULT))
             .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
                 new ContextReferenceStatementSupport(YangParserConfiguration.DEFAULT))
             .build();
-    }
 
-    @AfterClass
-    public static void freeReactor() {
-        reactor = null;
-    }
-
-    @Test
-    public void test() throws Exception {
-        final ModuleEffectiveStatement foo = reactor.newBuild()
+        final var foo = reactor.newBuild()
             .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/yang-ext.yang")))
             .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/ctxref.yang")))
             .buildEffective()
             .getModuleStatements()
             .get(FOO);
 
-        final DataTreeEffectiveStatement<?> list = foo.findDataTreeNode(QName.create(FOO, "list")).orElseThrow();
-        assertThat(list, instanceOf(ListEffectiveStatement.class));
+        final var list = assertInstanceOf(ListEffectiveStatement.class,
+            foo.findDataTreeNode(QName.create(FOO, "list")).orElseThrow());
 
-        final ContextInstanceEffectiveStatement listType = list
-            .findFirstEffectiveSubstatement(ContextInstanceEffectiveStatement.class).orElseThrow();
+        final var listType = list.findFirstEffectiveSubstatement(ContextInstanceEffectiveStatement.class).orElseThrow();
         assertEquals(LIST_TYPE, listType.argument());
         assertEquals(LIST_TYPE, listType.contextType().argument());
 
-        final ContextInstanceEffectiveStatement leafType = list
+        final var leafType = list
             .findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow()
             .findFirstEffectiveSubstatement(ContextInstanceEffectiveStatement.class).orElseThrow();
         assertEquals(LEAF_TYPE, leafType.argument());
         assertEquals(LEAF_TYPE, leafType.contextType().argument());
 
-        final List<GroupingEffectiveStatement> groupings = foo
-            .streamEffectiveSubstatements(GroupingEffectiveStatement.class).collect(Collectors.toList());
+        final var groupings = foo.streamEffectiveSubstatements(GroupingEffectiveStatement.class).toList();
         assertEquals(2, groupings.size());
 
-        final ContextReferenceEffectiveStatement listRef = groupings.get(1)
+        final var listRef = groupings.get(1)
             .findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow()
             .findFirstEffectiveSubstatement(ContextReferenceEffectiveStatement.class).orElseThrow();
         assertEquals(LIST_TYPE, listType.argument());
         assertSame(listType.contextType(), listRef.contextType());
 
-        final ContextReferenceEffectiveStatement leafRef = groupings.get(0)
+        final var leafRef = groupings.get(0)
             .findFirstEffectiveSubstatement(LeafListEffectiveStatement.class).orElseThrow()
             .findFirstEffectiveSubstatement(ContextReferenceEffectiveStatement.class).orElseThrow();
         assertEquals(LEAF_TYPE, leafType.argument());
index fbaa5cf60687a96d7bb40143652245a0e0d03c0b..68d72b32d2cffa4e42f1363304d1d9cb12cb9eaf 100644 (file)
@@ -7,58 +7,41 @@
  */
 package org.opendaylight.yangtools.odlext.parser;
 
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import java.util.Optional;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.odlext.model.api.MountEffectiveStatement;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 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 MountTest {
+class MountTest {
     private static final QNameModule FOO = QNameModule.create(XMLNamespace.of("foo"));
 
-    private static CrossSourceStatementReactor reactor;
-
-    @BeforeClass
-    public static void createReactor() {
-        reactor = RFC7950Reactors.vanillaReactorBuilder()
+    @Test
+    void test() throws Exception {
+        final var reactor = RFC7950Reactors.vanillaReactorBuilder()
             .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
                 new MountStatementSupport(YangParserConfiguration.DEFAULT))
             .build();
-    }
-
-    @AfterClass
-    public static void freeReactor() {
-        reactor = null;
-    }
-
-    @Test
-    public void test() throws Exception {
-        final ModuleEffectiveStatement foo = reactor.newBuild()
+        final var foo = reactor.newBuild()
             .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/yang-ext.yang")))
             .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/mount.yang")))
             .buildEffective()
             .getModuleStatements()
             .get(FOO);
 
-        final Optional<MountEffectiveStatement> fooMount = foo.findDataTreeNode(QName.create(FOO, "foo")).orElseThrow()
-            .findFirstEffectiveSubstatement(MountEffectiveStatement.class);
-        assertTrue(fooMount.isPresent());
-
-        final Optional<MountEffectiveStatement> barMount = foo.findDataTreeNode(QName.create(FOO, "bar")).orElseThrow()
-            .findFirstEffectiveSubstatement(MountEffectiveStatement.class);
-        assertTrue(barMount.isPresent());
+        assertTrue(foo.findDataTreeNode(QName.create(FOO, "foo")).orElseThrow()
+            .findFirstEffectiveSubstatement(MountEffectiveStatement.class)
+            .isPresent());
 
+        assertTrue(foo.findDataTreeNode(QName.create(FOO, "bar")).orElseThrow()
+            .findFirstEffectiveSubstatement(MountEffectiveStatement.class)
+            .isPresent());
     }
 }