Do not tolerate duplicate identities
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / IdentityStmtTest.java
index a58ece2738cd0294aded3f9298ff4d43399669f5..6f04c422c130bcbc01aaad1e8ee04f0418a06648 100644 (file)
@@ -5,16 +5,18 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.yangtools.yang.stmt;
 
 import static org.hamcrest.CoreMatchers.anyOf;
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.startsWith;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
+import com.google.common.base.Throwables;
 import java.util.Iterator;
 import java.util.Set;
 import org.junit.Test;
@@ -24,6 +26,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 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.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 
 public class IdentityStmtTest {
@@ -102,13 +105,12 @@ public class IdentityStmtTest {
 
     @Test
     public void duplicateIdentityTest() throws ReactorException {
-        SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
-                .addSource(DUPLICATE_IDENTITY_MODULE)
-                .buildEffective();
-        assertNotNull(result);
-
-        Module testModule = result.findModules("duplicate-identity-test").iterator().next();
-        Set<IdentitySchemaNode> identities = testModule.getIdentities();
-        assertEquals(1, identities.size());
+        try {
+            RFC7950Reactors.defaultReactor().newBuild().addSource(DUPLICATE_IDENTITY_MODULE).buildEffective();
+            fail("Duplicate identities should have been detected");
+        } catch (SomeModifiersUnresolvedException e) {
+            final SourceException cause = Throwables.getCauseAs(e, SourceException.class);
+            assertThat(cause.getMessage(), startsWith("Duplicate identity definition "));
+        }
     }
 }