*/
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.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import org.junit.Test;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
public class YT838Test {
@Test
- public void testGroupingShadowing() throws Exception {
+ public void testGroupingShadowing() {
testGrouping("grouping.yang");
}
@Test
- public void testGroupingPostShadowing() throws Exception {
+ public void testGroupingPostShadowing() {
testGrouping("grouping-post.yang");
}
@Test
- public void testTypedefShadowing() throws Exception {
+ public void testTypedefShadowing() {
testTypedef("typedef.yang");
}
@Test
- public void testTypedefPostShadowing() throws Exception {
+ public void testTypedefPostShadowing() {
testTypedef("typedef-post.yang");
}
- private static void testGrouping(final String model) throws Exception {
- try {
- StmtTestUtils.parseYangSource("/bugs/YT838/" + model);
- fail("Expected failure due to grouping identifier shadowing");
- } catch (ReactorException e) {
- final Throwable cause = e.getCause();
- assertTrue(cause instanceof SourceException);
- assertTrue(cause.getMessage().startsWith(
- "Duplicate name for grouping (grouping?revision=2017-12-20)foo [at "));
- }
+ private static void testGrouping(final String model) {
+ final ReactorException ex = assertThrows(ReactorException.class,
+ () -> StmtTestUtils.parseYangSource("/bugs/YT838/" + model));
+
+ final Throwable cause = ex.getCause();
+ assertThat(cause, instanceOf(SourceException.class));
+ assertThat(cause.getMessage(),
+ startsWith("Duplicate name for grouping (grouping?revision=2017-12-20)foo [at "));
}
- private static void testTypedef(final String model) throws Exception {
- try {
- StmtTestUtils.parseYangSource("/bugs/YT838/" + model);
- fail("Expected failure due to type identifier shadowing");
- } catch (ReactorException e) {
- final Throwable cause = e.getCause();
- assertTrue(cause instanceof SourceException);
- assertTrue(cause.getMessage().startsWith(
- "Duplicate name for typedef (typedef?revision=2017-12-20)foo [at "));
- }
+ private static void testTypedef(final String model) {
+ final ReactorException ex = assertThrows(ReactorException.class,
+ () -> StmtTestUtils.parseYangSource("/bugs/YT838/" + model));
+ final Throwable cause = ex.getCause();
+ assertTrue(cause instanceof SourceException);
+ assertThat(cause, instanceOf(SourceException.class));
+ assertThat(cause.getMessage(), startsWith("Duplicate name for typedef (typedef?revision=2017-12-20)foo [at "));
}
}