Cleanup Bug6870Test 27/97727/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 4 Oct 2021 09:05:59 +0000 (11:05 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 5 Oct 2021 08:36:41 +0000 (10:36 +0200)
Use AbstractYangTest to reduce verbosity and duplication.

JIRA: YANGTOOLS-1345
Change-Id: I973b7c91f3fb33bc315fd6022eea1209e7bde22b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6870Test.java

index ecdfc881f0d1b101b50046dc6a2e6c36e513395c..4365ad36302d9d32da7cde75261ae6e07511cb72 100644 (file)
@@ -12,7 +12,6 @@ import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.startsWith;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
 
 import java.util.List;
 import java.util.Optional;
@@ -25,18 +24,14 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.ModifierKind;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
+import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
 
-public class Bug6870Test {
+public class Bug6870Test extends AbstractYangTest {
     @Test
     public void valid11Test() throws Exception {
-        final EffectiveModelContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6870/foo.yang");
-
-        assertModifier(schemaContext, ModifierKind.INVERT_MATCH, QName.create("foo", "root"),
-            QName.create("foo", "my-leaf"));
-        assertModifier(schemaContext, null, QName.create("foo", "root"), QName.create("foo", "my-leaf-2"));
+        final var context = assertEffectiveModel("/rfc7950/bug6870/foo.yang");
+        assertModifier(context, ModifierKind.INVERT_MATCH, QName.create("foo", "root"), QName.create("foo", "my-leaf"));
+        assertModifier(context, null, QName.create("foo", "root"), QName.create("foo", "my-leaf-2"));
     }
 
     private static void assertModifier(final EffectiveModelContext schemaContext,
@@ -54,19 +49,13 @@ public class Bug6870Test {
 
     @Test
     public void invalid11Test() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6870/invalid11.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("'Invert-match' is not valid argument of modifier statement"));
+        assertSourceException(startsWith("'Invert-match' is not valid argument of modifier statement"),
+            "/rfc7950/bug6870/invalid11.yang");
     }
 
     @Test
     public void invalid10Test() {
-        final ReactorException ex = assertThrows(ReactorException.class,
-            () -> StmtTestUtils.parseYangSource("/rfc7950/bug6870/invalid10.yang"));
-        final Throwable cause = ex.getCause();
-        assertThat(cause, instanceOf(SourceException.class));
-        assertThat(cause.getMessage(), startsWith("modifier is not a YANG statement or use of extension"));
+        assertSourceException(startsWith("modifier is not a YANG statement or use of extension"),
+            "/rfc7950/bug6870/invalid10.yang");
     }
 }
\ No newline at end of file