Fix ModifiedNode.toString() 67/79967/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 28 Jan 2019 18:39:27 +0000 (19:39 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 28 Jan 2019 19:01:25 +0000 (20:01 +0100)
This method's return is extremely confusing, as it is reporting
logical operation instead of modification type and it hides behind
NodeModification, rendering identification hard.

Fix this by using ToStringHelper to make sure this works correctly.

Change-Id: I39907db8d260043809f68fc76c57a3bd5b922b0d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ModifiedNode.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedListTest.java

index 2e5cdbfa282c3590f52c44a6e09199c0c20d1f13..1b02ea7fc3328c0262d91dba44150eb5d354b151 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import static java.util.Objects.requireNonNull;
 
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
 import java.util.Collection;
 import java.util.Map;
 import java.util.Optional;
@@ -316,8 +318,12 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
 
     @Override
     public String toString() {
-        return "NodeModification [identifier=" + identifier + ", modificationType="
-                + operation + ", childModification=" + children + "]";
+        final ToStringHelper helper = MoreObjects.toStringHelper(this).omitNullValues()
+                .add("identifier", identifier).add("operation", operation).add("modificationType", modType);
+        if (!children.isEmpty()) {
+            helper.add("childModification", children);
+        }
+        return helper.toString();
     }
 
     void resolveModificationType(@Nonnull final ModificationType type) {
index fa7d1dc15a2e6ff617c8f3334ca880660c49ab45..3e69e5c4f286729da4a22e961642dd594e19b2fd 100644 (file)
@@ -185,7 +185,7 @@ public class OrderedListTest {
             inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification));
         } catch (final IllegalArgumentException ex) {
             LOG.debug("IllegalArgumentException was thrown as expected", ex);
-            assertTrue(ex.getMessage().contains("Metadata not available for modification NodeModification"));
+            assertTrue(ex.getMessage().contains("Metadata not available for modification ModifiedNode"));
         }
 
         DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();