*/
package org.opendaylight.mdsal.binding.yang.types;
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
import java.net.URI;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.opendaylight.mdsal.binding.generator.spi.TypeProvider;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Bug4621 {
-
- @Rule
- public ExpectedException expectedEx = ExpectedException.none();
-
@Test
public void bug4621test() {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug-4621/foo.yang");
final Module moduleValid = schemaContext.findModules(URI.create("foo")).iterator().next();
final TypeProvider typeProvider = new RuntimeTypeProvider(schemaContext);
- expectedEx.expect(IllegalArgumentException.class);
-
final QName listNode = QName.create(moduleValid.getQNameModule(), "neighbor");
final QName leafrefNode = QName.create(moduleValid.getQNameModule(), "neighbor2-id");
- DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName(listNode))
+ final DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName(listNode))
.getDataChildByName(leafrefNode);
- LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
- TypeDefinition<?> leafTypeRel = leafRel.getType();
- assertNotNull(typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel));
+ final LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
+ final TypeDefinition<?> leafTypeRel = leafRel.getType();
+
+ final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
+ () -> typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel));
+ assertThat(ex.getMessage(),
+ startsWith("Failed to find leafref target: /foo:neighbor/foo:mystring1 in module foo"));
}
}
\ No newline at end of file