From faf2feebb38a9348c03ba2c15c8a908affb7c1e6 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 4 Oct 2021 11:05:59 +0200 Subject: [PATCH] Cleanup Bug6870Test Use AbstractYangTest to reduce verbosity and duplication. JIRA: YANGTOOLS-1345 Change-Id: I973b7c91f3fb33bc315fd6022eea1209e7bde22b Signed-off-by: Robert Varga --- .../yang/parser/stmt/rfc7950/Bug6870Test.java | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6870Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6870Test.java index ecdfc881f0..4365ad3630 100644 --- a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6870Test.java +++ b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6870Test.java @@ -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 -- 2.36.6