Simplify SchemaContextUtil.findParentModule() 29/94929/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 1 Feb 2021 10:41:30 +0000 (11:41 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 1 Feb 2021 11:04:13 +0000 (12:04 +0100)
We are going through SchemaNode.getPath() only to acquire the last
component -- this is equivalent to SchemaNode.getQName(), so use
that.

Change-Id: I206d9cbdf9932f8ef4eb102eb2fa88660460aca3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtilTest.java

index 73bd1765d1d0cc121702ee110b85075647bec6e5..742dab9e2fa753023ce767ecfcc62587328add95 100644 (file)
@@ -288,10 +288,7 @@ public final class SchemaContextUtil {
      * @throws NullPointerException if any of the arguments is null
      */
     public static Module findParentModule(final SchemaContext context, final SchemaNode schemaNode) {
-        final QName qname = schemaNode.getPath().getLastComponent();
-        checkState(qname != null, "Schema Path contains invalid state of path parts. "
-                + "The Schema Path MUST contain at least ONE QName  which defines namespace and Local name of path.");
-        return context.findModule(qname.getModule()).orElse(null);
+        return context.findModule(schemaNode.getQName().getModule()).orElse(null);
     }
 
     public static SchemaNode findNodeInSchemaContext(final SchemaContext context, final Iterable<QName> path) {
index 6c6407d853620504e646825b623133a2ca1feef3..92bfa0f1234288f2fa74a49394bb9c484ba8b129 100644 (file)
@@ -125,7 +125,7 @@ public class SchemaContextUtilTest {
 
     @Test
     public void findParentModuleIllegalArgumentTest2() {
-        doReturn(SchemaPath.create(true, QName.create("foo", "bar"))).when(schemaNode).getPath();
+        doReturn(QName.create("foo", "bar")).when(schemaNode).getQName();
         assertThrows(NullPointerException.class, () -> SchemaContextUtil.findParentModule(null, schemaNode));
     }