Modernize yang-parser-rfc7950 a bit 22/115122/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 6 Feb 2025 12:46:01 +0000 (13:46 +0100)
committerRobert Varga <nite@hq.sk>
Thu, 6 Feb 2025 13:15:13 +0000 (13:15 +0000)
Use AssertJ instead of the more obvious uses of Hamcrest.

Change-Id: I7ad281229f71132a60dc64b2f59c7cc5db502987
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
16 files changed:
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6868Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6878Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentArgumentParsingTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4410Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6240Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7146Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7480Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug8307Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationResolutionTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveIdentityTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludeResolutionTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/TypesResolutionTest.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1133Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1339Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1410Test.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1471Test.java

index 286723c2150dac86ea8d286e1071480b39572f4b..db711df7530b47f55ad92fab83873d4eb4dfdc7f 100644 (file)
@@ -7,10 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
 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 com.google.common.collect.Sets;
@@ -54,9 +53,8 @@ class Bug6868Test extends AbstractYangTest {
         assertNotNull(schemaContext);
 
         for (var expectedContainer : expectedContainers) {
-            assertThat(String.format("Expected container %s not found.", expectedContainer),
-                schemaContext.findDataTreeChild(QName.create(FOO_NS, expectedContainer)).orElseThrow(),
-                instanceOf(ContainerSchemaNode.class));
+            assertInstanceOf(ContainerSchemaNode.class,
+                schemaContext.findDataTreeChild(QName.create(FOO_NS, expectedContainer)).orElseThrow());
         }
 
         for (var unexpectedContainer : Sets.difference(ALL_CONTAINERS, expectedContainers)) {
index aae250daf4156e19d08602501eb2d5c2dea3bff7..acf8f1fa20bf9e69fd3b5eee2ffb1e618faf3d0a 100644 (file)
@@ -7,9 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
@@ -18,31 +16,30 @@ import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
 class Bug6878Test extends AbstractYangTest {
-
     @Test
     void testParsingXPathWithYang11Functions() {
-        final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo.yang");
-        assertFalse(testLog.contains("Could not find function: "));
+        final var testLog = parseAndcaptureLog("/rfc7950/bug6878/foo.yang");
+        assertThat(testLog).doesNotContain("Could not find function: ");
     }
 
     @Test
     void shouldLogInvalidYang10XPath() {
-        final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid.yang");
-        assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
+        final var testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid.yang");
+        assertThat(testLog).contains("RFC7950 features required in RFC6020 context to parse expression ");
     }
 
     @Test
     void shouldLogInvalidYang10XPath2() {
-        final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid-2.yang");
-        assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
+        final var testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid-2.yang");
+        assertThat(testLog).contains("RFC7950 features required in RFC6020 context to parse expression ");
     }
 
     @SuppressWarnings("checkstyle:regexpSinglelineJava")
     private static String parseAndcaptureLog(final String yangFile) {
-        final PrintStream stdout = System.out;
-        final ByteArrayOutputStream output = new ByteArrayOutputStream();
+        final var stdout = System.out;
+        final var output = new ByteArrayOutputStream();
 
-        try (PrintStream out = new PrintStream(output, true, StandardCharsets.UTF_8)) {
+        try (var out = new PrintStream(output, true, StandardCharsets.UTF_8)) {
             System.setOut(out);
             assertEffectiveModel(yangFile);
         } finally {
index d508ccc92ed6aa42ffd5b128b243c293b21cd677..fb0201db5270588641534d9fb19f84645dffd8b3 100644 (file)
@@ -7,8 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -19,7 +18,6 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.ReactorDeclaredModel;
 
 class AugmentArgumentParsingTest {
@@ -72,32 +70,28 @@ class AugmentArgumentParsingTest {
 
     @Test
     void invalidAugEmptyTest() {
-        final ReactorException ex = assertReactorThrows(INVALID_EMPTY);
-        final Throwable cause = ex.getCause();
-        assertInstanceOf(SourceException.class, cause);
-        assertThat(cause.getMessage(), startsWith("Schema node identifier must not be empty"));
+        final var ex = assertReactorThrows(INVALID_EMPTY);
+        final var cause = assertInstanceOf(SourceException.class, ex.getCause());
+        assertThat(cause.getMessage()).startsWith("Schema node identifier must not be empty");
     }
 
     @Test
     void invalidAugXPathTest() {
-        final ReactorException ex = assertReactorThrows(INVALID_XPATH);
-        final Throwable cause = ex.getCause();
-        assertInstanceOf(SourceException.class, cause);
-        assertThat(cause.getMessage(), startsWith("Failed to parse node '-' in path '/aug1/-'"));
+        final var ex = assertReactorThrows(INVALID_XPATH);
+        final var cause = assertInstanceOf(SourceException.class, ex.getCause());
+        assertThat(cause.getMessage()).startsWith("Failed to parse node '-' in path '/aug1/-'");
 
-        final Throwable nested = cause.getCause();
-        assertInstanceOf(SourceException.class, nested);
-        assertThat(nested.getMessage(), startsWith("Invalid identifier '-'"));
+        final var nested = assertInstanceOf(SourceException.class, cause.getCause());
+        assertThat(nested.getMessage()).startsWith("Invalid identifier '-'");
     }
 
     private static ReactorException assertReactorThrows(final StatementStreamSource source) {
-        final BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(source);
+        final var reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(source);
         return assertThrows(ReactorException.class, () -> reactor.build());
     }
 
     private static void assertSourceExceptionCause(final Throwable exception, final String start) {
-        final Throwable cause = exception.getCause();
-        assertInstanceOf(SourceException.class, cause);
-        assertThat(cause.getMessage(), startsWith(start));
+        final var cause = assertInstanceOf(SourceException.class, exception.getCause());
+        assertThat(cause.getMessage()).startsWith(start);
     }
 }
index d6cdc4923c709166840fb3f24773553034526192..c9c6500e80f8fd019147115341d1abed59baf0af 100644 (file)
@@ -7,10 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.allOf;
-import static org.hamcrest.CoreMatchers.containsString;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 
 import org.junit.jupiter.api.Test;
@@ -19,9 +17,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 class Bug4410Test extends AbstractYangTest {
     @Test
     void test() {
-        final var cause = assertInferenceExceptionDir("/bugs/bug4410",
-            startsWith("Yang model processing phase EFFECTIVE_MODEL failed [at ")).getCause();
-        assertInstanceOf(InferenceException.class, cause);
-        assertThat(cause.getMessage(), allOf(startsWith("Type [(foo)"), containsString("was not found")));
+        final var cause = assertInstanceOf(InferenceException.class, assertInferenceExceptionDir("/bugs/bug4410",
+            startsWith("Yang model processing phase EFFECTIVE_MODEL failed [at ")).getCause());
+        assertThat(cause.getMessage()).startsWith("Type [(foo)").contains("was not found");
     }
 }
index ef88781fa14b5dac1125dfc73d2e6e113501ec77..aa1dba7d6c4b361965b75e79f72f83bf6c46409c 100644 (file)
@@ -7,9 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -17,7 +15,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
 import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 
 class Bug6240Test extends AbstractYangTest {
@@ -41,19 +38,16 @@ class Bug6240Test extends AbstractYangTest {
 
         assertNotNull(bar);
         assertInstanceOf(ContainerSchemaNode.class, bar.getDataChildByName(QName.create(NS, REV, "foo-grp-con")));
-        assertThat(bar.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")),
-            instanceOf(ContainerSchemaNode.class));
+        assertInstanceOf(ContainerSchemaNode.class, bar.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")));
 
         assertEquals(1, bar.getSubmodules().size());
 
-        final DataSchemaNode dataChildByName = bar.getDataChildByName(QName.create(NS, REV, "sub-bar-con"));
-        assertInstanceOf(ContainerSchemaNode.class, dataChildByName);
-        final ContainerSchemaNode subBarCon = (ContainerSchemaNode) dataChildByName;
+        final var subBarCon = assertInstanceOf(ContainerSchemaNode.class,
+            bar.getDataChildByName(QName.create(NS, REV, "sub-bar-con")));
 
-        assertThat(subBarCon.getDataChildByName(QName.create(NS, REV, "foo-grp-con")),
-            instanceOf(ContainerSchemaNode.class));
-        assertThat(subBarCon.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")),
-            instanceOf(ContainerSchemaNode.class));
+        assertInstanceOf(ContainerSchemaNode.class, subBarCon.getDataChildByName(QName.create(NS, REV, "foo-grp-con")));
+        assertInstanceOf(ContainerSchemaNode.class,
+            subBarCon.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")));
     }
 
     @Test
index 0b91655a83f8823bc177fa5b95ba35ec4e053e05..44649975367347a2d749e6afc8fda088748c69e1 100644 (file)
@@ -7,8 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
@@ -22,6 +21,6 @@ class Bug7146Test {
         final var cause = assertThrows(IllegalArgumentException.class,
             () -> StmtTestUtils.parseYangSources(sourceForResource("/bugs/bug7146/foo.yang"))).getCause();
         assertInstanceOf(YangSyntaxErrorException.class, cause);
-        assertThat(cause.getMessage(), containsString("extraneous input '#'"));
+        assertThat(cause.getMessage()).contains("extraneous input '#'");
     }
 }
index 1742fc33e66e22ac3489de9f35a5fc6bdcf73a60..01049476753a0cb50434380f6144af09dea2b7c1 100644 (file)
@@ -7,8 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -52,7 +51,7 @@ class Bug7480Test {
             () -> parseYangSources("/bugs/bug7480/files-2", "/bugs/bug7480/lib-2"));
         final var message = ex.getSuppressed().length > 0 ? ex.getSuppressed()[0].getMessage()
             : ex.getCause().getMessage();
-        assertThat(message, startsWith("Imported module [missing-lib] was not found."));
+        assertThat(message).startsWith("Imported module [missing-lib] was not found.");
     }
 
     @Test
index 1ae35ec1b2724601f0e2d7fa9aba1f32f840976e..1e12c3f56da5e8e0863f15552cd0a6ce7dd06d44 100644 (file)
@@ -7,8 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -98,8 +97,8 @@ class Bug8307Test {
 
         final var cause = assertInstanceOf(InferenceException.class,
             assertThrows(ReactorException.class, reactor::buildEffective).getCause());
-        assertThat(cause.getMessage(),
-            startsWith("Deviation must not target the same module as the one it is defined in"));
+        assertThat(cause.getMessage())
+            .startsWith("Deviation must not target the same module as the one it is defined in");
     }
 
     @Test
@@ -109,7 +108,7 @@ class Bug8307Test {
 
         final var cause = assertInstanceOf(InferenceException.class,
             assertThrows(ReactorException.class, reactor::buildEffective).getCause());
-        assertThat(cause.getMessage(),
-            startsWith("Deviation must not target the same module as the one it is defined in"));
+        assertThat(cause.getMessage())
+            .startsWith("Deviation must not target the same module as the one it is defined in");
     }
 }
index 0cfd3b592b4f15f93b5fc6d72307e5bb49562598..36dbd7a2c518bbc4d07902ce4b0ba40b07218fca 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.containsString;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -269,9 +268,9 @@ class DeviationResolutionTest extends AbstractYangTest {
 
         final var testLog = output.toString();
         System.setOut(stdout);
-        assertThat(testLog, containsString("""
+        assertThat(testLog).contains("""
             Deviation cannot replace substatement (urn:ietf:params:xml:ns:yang:yin:1)default in target leaf-list \
-            (bar?revision=2017-01-20)my-leaf-list because a leaf-list can have multiple default statements."""));
+            (bar?revision=2017-01-20)my-leaf-list because a leaf-list can have multiple default statements.""");
     }
 
     @Test
@@ -289,9 +288,9 @@ class DeviationResolutionTest extends AbstractYangTest {
 
         testLog = output.toString();
         System.setOut(stdout);
-        assertThat(testLog, containsString(
+        assertThat(testLog).contains(
             "Deviation cannot delete substatement (urn:ietf:params:xml:ns:yang:yin:1)units with argument 'seconds' in "
-                + "target node (bar?revision=2017-01-20)my-leaf because it does not exist in the target node."));
+                + "target node (bar?revision=2017-01-20)my-leaf because it does not exist in the target node.");
     }
 
     @Test
index 5c69aab4666793786a452b849dd7900c7df551b1..2217444e934483c008b60d59165b331cc8d942b5 100644 (file)
@@ -7,8 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -44,7 +43,7 @@ class EffectiveIdentityTest {
         final var reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(CYCLIC_IDENTITY_TEST);
         final var cause = assertThrows(SomeModifiersUnresolvedException.class, reactor::buildEffective).getCause();
         assertInstanceOf(InferenceException.class, cause);
-        assertThat(cause.getMessage(), startsWith("Yang model processing phase STATEMENT_DEFINITION failed [at "));
+        assertThat(cause.getMessage()).startsWith("Yang model processing phase STATEMENT_DEFINITION failed [at ");
 
         // This is a bit complicated, as the order of exceptions may differ
         final var causes = new ArrayList<Throwable>();
@@ -57,18 +56,18 @@ class EffectiveIdentityTest {
         assertEquals(4, causes.size());
         causes.forEach(throwable -> assertInstanceOf(InferenceException.class, throwable));
 
-        assertThat(causes.get(0).getMessage(),
-            startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-1 and base identity "
-                + "(cyclic.identity.test)child-identity-2 [at "));
-        assertThat(causes.get(1).getMessage(),
-            startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-2 and base identity "
-                + "(cyclic.identity.test)child-identity-3 [at "));
-        assertThat(causes.get(2).getMessage(),
-            startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-3 and base identity "
-                + "(cyclic.identity.test)child-identity-4 [at "));
-        assertThat(causes.get(3).getMessage(),
-            startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-4 and base identity "
-                + "(cyclic.identity.test)child-identity-1 [at "));
+        assertThat(causes.get(0).getMessage())
+            .startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-1 and base identity "
+                + "(cyclic.identity.test)child-identity-2 [at ");
+        assertThat(causes.get(1).getMessage())
+            .startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-2 and base identity "
+                + "(cyclic.identity.test)child-identity-3 [at ");
+        assertThat(causes.get(2).getMessage())
+            .startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-3 and base identity "
+                + "(cyclic.identity.test)child-identity-4 [at ");
+        assertThat(causes.get(3).getMessage())
+            .startsWith("Unable to resolve identity (cyclic.identity.test)child-identity-4 and base identity "
+                + "(cyclic.identity.test)child-identity-1 [at ");
     }
 
     @Test
index a7b059ffdaf473850712c3965a0667fbdb2fc20a..693c0c5d09bd54ec44b995196cf3551101fef10a 100644 (file)
@@ -7,8 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -72,7 +71,7 @@ class IncludeResolutionTest {
         final var ex = assertThrows(SomeModifiersUnresolvedException.class, callable::call);
         assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, ex.getPhase());
         var cause = assertInstanceOf(InferenceException.class, ex.getCause());
-        assertThat(cause.getMessage(), startsWith(startStr));
+        assertThat(cause.getMessage()).startsWith(startStr);
         return cause;
     }
 }
index a4f6f805637f338c33a9bc577d59e68a18ba9be6..c547b660ee241f3bce1558e4bd45f3828919af82 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.containsString;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -57,10 +56,10 @@ class TypesResolutionTest extends AbstractYangTest {
         assertEquals(14, typedefs.size());
 
         var type = TestUtils.findTypedef(typedefs, "ip-version");
-        assertThat(type.getDescription().orElseThrow(),
-            containsString("This value represents the version of the IP protocol."));
-        assertThat(type.getReference().orElseThrow(),
-            containsString("RFC 2460: Internet Protocol, Version 6 (IPv6) Specification"));
+        assertThat(type.getDescription().orElseThrow())
+            .contains("This value represents the version of the IP protocol.");
+        assertThat(type.getReference().orElseThrow())
+            .contains("RFC 2460: Internet Protocol, Version 6 (IPv6) Specification");
 
         var enumType = assertInstanceOf(EnumTypeDefinition.class, type.getBaseType());
         var values = enumType.getValues();
@@ -278,8 +277,8 @@ class TypesResolutionTest extends AbstractYangTest {
         var typedefs = tested.getTypeDefinitions();
         var testedType = TestUtils.findTypedef(typedefs, "iana-timezone");
 
-        assertThat(testedType.getDescription().orElseThrow(),
-            containsString("A timezone location as defined by the IANA timezone"));
+        assertThat(testedType.getDescription().orElseThrow())
+            .contains("A timezone location as defined by the IANA timezone");
         assertFalse(testedType.getReference().isPresent());
         assertEquals(Status.CURRENT, testedType.getStatus());
 
index f3f80d8cf73d40b5ff5df108906f44d5bca7e9ef..1ef7fe452cdd2fb97585ed6d29c8c58eaf5e0d0f 100644 (file)
@@ -7,9 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.io.ByteArrayOutputStream;
@@ -22,11 +20,11 @@ class YT1133Test extends AbstractYangTest {
     @Test
     @SuppressWarnings("checkstyle:regexpSinglelineJava")
     void testAugmentKeys() {
-        final PrintStream stdout = System.out;
-        final ByteArrayOutputStream output = new ByteArrayOutputStream();
+        final var stdout = System.out;
+        final var output = new ByteArrayOutputStream();
         final EffectiveModelContext ctx;
 
-        try (PrintStream out = new PrintStream(output, true, StandardCharsets.UTF_8)) {
+        try (var out = new PrintStream(output, true, StandardCharsets.UTF_8)) {
             System.setOut(out);
             ctx = assertEffectiveModelDir("/bugs/YT1133");
         } finally {
@@ -34,7 +32,6 @@ class YT1133Test extends AbstractYangTest {
         }
 
         assertEquals(2, ctx.getModules().size());
-        final String log = output.toString();
-        assertThat(log, not(containsString("Configuration list (bar)values")));
+        assertThat(output.toString()).doesNotContain("Configuration list (bar)values");
     }
 }
index e5bd86694992a2d042254e78fa6bd4e139e5e1fa..b9360ea8a97ca562466469d2b6348efae3dcdd6c 100644 (file)
@@ -7,8 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.yang.common.YangVersion;
@@ -47,13 +46,13 @@ class YT1339Test extends AbstractYangTest {
     }
 
     private static void assertFailedImport(final String subdir) {
-        assertThat(assertYangVersionLinkageException(subdir),
-            startsWith("Cannot import by revision version 1.1 module new [at "));
+        assertThat(assertYangVersionLinkageException(subdir))
+            .startsWith("Cannot import by revision version 1.1 module new [at ");
     }
 
     private static void assertFailedInclude(final String subdir, final YangVersion subVer, final YangVersion modVer) {
-        assertThat(assertYangVersionLinkageException(subdir),
-            startsWith("Cannot include a version " + subVer + " submodule in a version " + modVer + " module [at "));
+        assertThat(assertYangVersionLinkageException(subdir))
+            .startsWith("Cannot include a version " + subVer + " submodule in a version " + modVer + " module [at ");
     }
 
     private static String assertYangVersionLinkageException(final String subdir) {
index 5eb556ca501746bd39933893d09fb1c053184a18..4a55997f329cb3cc92cad25d0d66ffe6bd57b67c 100644 (file)
@@ -7,9 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 
 import org.junit.jupiter.api.Test;
@@ -28,11 +26,11 @@ class YT1410Test extends AbstractYangTest {
     @Test
     void testRFC7950() {
         final var module = assertEffectiveModel("/bugs/YT1410/bar.yang").getModuleStatement(QName.create("bar", "bar"));
-        final var one = module.findSchemaTreeNode(QName.create("bar", "one")).orElseThrow();
-        assertInstanceOf(ChoiceEffectiveStatement.class, one);
-        final var two = ((ChoiceEffectiveStatement) one).findSchemaTreeNode(QName.create("bar", "two")).orElseThrow();
-        assertInstanceOf(CaseEffectiveStatement.class, two);
-        assertThat(((CaseEffectiveStatement) two).findSchemaTreeNode(QName.create("bar", "two")).orElseThrow(),
-            instanceOf(ChoiceEffectiveStatement.class));
+        final var one = assertInstanceOf(ChoiceEffectiveStatement.class,
+            module.findSchemaTreeNode(QName.create("bar", "one")).orElseThrow());
+        final var two = assertInstanceOf(CaseEffectiveStatement.class,
+            one.findSchemaTreeNode(QName.create("bar", "two")).orElseThrow());
+        assertInstanceOf(ChoiceEffectiveStatement.class,
+            two.findSchemaTreeNode(QName.create("bar", "two")).orElseThrow());
     }
 }
index 9b47e0a16e028c8d037ca07bbd39360160204034..b0ad9ea041faa6dd9f76093f7de8e148ad79c29f 100644 (file)
@@ -7,9 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.contains;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.List;
@@ -43,8 +41,8 @@ class YT1471Test extends AbstractYangTest {
 
     @Test
     void testAugmentNestedGroupingWithFeatureNotSupported() {
-        assertThat(assertFoo("nested", Set.of()).effectiveSubstatements(),
-            contains(instanceOf(UsesEffectiveStatement.class)));
+        assertThat(assertFoo("nested", Set.of()).effectiveSubstatements())
+            .anyMatch(UsesEffectiveStatement.class::isInstance);
     }
 
     private static ContainerEffectiveStatement assertFoo(final String dirName, final Set<QName> supportedFeatures) {