Add NormalizedNodeContainer.size()
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / Bug4454Test.java
index 5057117815e6e684ec4c00b0fd40779f93ecf746..9d05210203107461574c4360acc855f2161d729c 100644 (file)
@@ -8,16 +8,17 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import static junit.framework.TestCase.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableMap;
-import java.io.IOException;
-import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.util.UnmodifiableCollection;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -25,6 +26,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
@@ -32,17 +34,17 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class Bug4454Test {
@@ -56,12 +58,15 @@ public class Bug4454Test {
             .create(MASTER_CONTAINER_QNAME, "min-max-list-no-minmax");
     private static final QName MIN_MAX_KEY_LEAF_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-key-leaf");
     private static final QName MIN_MAX_VALUE_LEAF_QNAME = QName.create(MASTER_CONTAINER_QNAME, "min-max-value-leaf");
+    private static final QName PRESENCE_QNAME = QName.create(MASTER_CONTAINER_QNAME, "presence");
 
     private static final YangInstanceIdentifier MASTER_CONTAINER_PATH = YangInstanceIdentifier
             .of(MASTER_CONTAINER_QNAME);
     private static final YangInstanceIdentifier MIN_MAX_LIST_PATH = YangInstanceIdentifier
             .builder(MASTER_CONTAINER_PATH)
             .node(MIN_MAX_LIST_QNAME).build();
+    private static final YangInstanceIdentifier PRESENCE_PATH = YangInstanceIdentifier.of(PRESENCE_QNAME);
+    private static final YangInstanceIdentifier PRESENCE_MIN_MAX_LIST_PATH = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME);
     private static final YangInstanceIdentifier MIN_MAX_LIST_NO_MINMAX_PATH = YangInstanceIdentifier
             .builder(MASTER_CONTAINER_PATH)
             .node(MIN_MAX_LIST_QNAME_NO_MINMAX).build();
@@ -72,10 +77,10 @@ public class Bug4454Test {
     private static final Map<QName, Object> BAZ_PREDICATES = ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "baz");
 
     private final MapEntryNode fooEntryNodeWithValue = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(
-        new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, FOO_PREDICATES))
+        NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, FOO_PREDICATES))
             .withChild(ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "footest")).build();
     private final MapEntryNode bazEntryNodeWithValue = ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(
-        new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, BAZ_PREDICATES))
+        NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, BAZ_PREDICATES))
             .withChild(ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "baztest")).build();
     private final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME,
             "foo");
@@ -98,15 +103,25 @@ public class Bug4454Test {
             .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
             .withChild(bazEntryNode).build();
 
-    private InMemoryDataTree inMemoryDataTree;
+    private static SchemaContext schemaContext;
+
+    private DataTree inMemoryDataTree;
+
+    @BeforeClass
+    public static void beforeClass() {
+        schemaContext = YangParserTestUtils.parseYangResource("/bug-4454-test.yang");
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        schemaContext = null;
+    }
 
     @Before
-    public void prepare() throws IOException, YangSyntaxErrorException, ReactorException, URISyntaxException {
-        SchemaContext schemaContext = createTestContext();
-        assertNotNull("Schema context must not be null.", schemaContext);
-        inMemoryDataTree =  (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
-        inMemoryDataTree.setSchemaContext(schemaContext);
-        final InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
+    public void prepare() {
+        inMemoryDataTree =  new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
+            schemaContext);
+        final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
         final DataTreeModification modificationTree = initialDataTreeSnapshot.newModification();
 
         modificationTree.write(MASTER_CONTAINER_PATH, ImmutableNodes.containerNode(MASTER_CONTAINER_QNAME));
@@ -114,19 +129,14 @@ public class Bug4454Test {
         inMemoryDataTree.commit(inMemoryDataTree.prepare(modificationTree));
     }
 
-    public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException, ReactorException,
-            URISyntaxException {
-        return YangParserTestUtils.parseYangResource("/bug-4454-test.yang");
-    }
-
     @Test
     public void minMaxListDeleteWriteTest() throws DataValidationFailedException {
-        final InMemoryDataTreeModification modificationTree1 = inMemoryDataTree.takeSnapshot().newModification();
+        final DataTreeModification modificationTree1 = inMemoryDataTree.takeSnapshot().newModification();
 
         Map<QName, Object> key = new HashMap<>();
         key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
 
-        NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME , key);
+        NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME , key);
 
         final YangInstanceIdentifier minMaxLeafFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
                 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
@@ -134,7 +144,7 @@ public class Bug4454Test {
         key.clear();
         key.put(MIN_MAX_KEY_LEAF_QNAME, "NON-EXISTING-LEAF");
 
-        mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, key);
+        mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, key);
 
         final YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
                 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
@@ -142,7 +152,7 @@ public class Bug4454Test {
         final Map<QName, Object> keyTemp = new HashMap<>();
         keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "baz");
 
-        NodeIdentifierWithPredicates mapEntryPathTest = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME , keyTemp);
+        NodeIdentifierWithPredicates mapEntryPathTest = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME , keyTemp);
 
         final YangInstanceIdentifier pathToBaz = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
                 .node(MIN_MAX_LIST_QNAME).node(mapEntryPathTest).node(MIN_MAX_VALUE_LEAF_QNAME).build();
@@ -150,7 +160,7 @@ public class Bug4454Test {
         keyTemp.clear();
         keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "bar");
 
-        mapEntryPathTest = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME , keyTemp);
+        mapEntryPathTest = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME , keyTemp);
 
         final YangInstanceIdentifier pathToBar = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
                 .node(MIN_MAX_LIST_QNAME).node(mapEntryPathTest).node(MIN_MAX_VALUE_LEAF_QNAME).build();
@@ -158,7 +168,7 @@ public class Bug4454Test {
         keyTemp.clear();
         keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
 
-        final NodeIdentifierWithPredicates mapEntryPathTestKey = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME,
+        final NodeIdentifierWithPredicates mapEntryPathTestKey = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
             keyTemp);
 
         final YangInstanceIdentifier pathToKeyFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
@@ -171,7 +181,7 @@ public class Bug4454Test {
 
         assertFalse(inMemoryDataTree.toString().contains("list"));
 
-        InMemoryDataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
+        DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
         Optional<NormalizedNode<?, ?>> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
         assertTrue(!minMaxListRead.isPresent());
 
@@ -192,10 +202,10 @@ public class Bug4454Test {
         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree1);
         inMemoryDataTree.commit(prepare);
 
-        InMemoryDataTreeSnapshot test = inMemoryDataTree.takeSnapshot();
+        DataTreeSnapshot test = inMemoryDataTree.takeSnapshot();
         testLoop(test, "bar", "test");
 
-        InMemoryDataTreeModification tempMod = test.newModification();
+        DataTreeModification tempMod = test.newModification();
         tempMod.write(pathToBaz, newNode2);
         tempMod.write(pathToBaz, newNode1);
         tempMod.merge(pathToBaz, newNode2);
@@ -206,10 +216,10 @@ public class Bug4454Test {
         final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(tempMod);
         inMemoryDataTree.commit(prepare1);
 
-        InMemoryDataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
+        DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
         testLoop(test1, "bar", "test1");
 
-        InMemoryDataTreeModification tempMod1 = test1.newModification();
+        DataTreeModification tempMod1 = test1.newModification();
         tempMod1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
 
         tempMod1.ready();
@@ -217,12 +227,12 @@ public class Bug4454Test {
         final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
         inMemoryDataTree.commit(prepare2);
 
-        InMemoryDataTreeSnapshot test2 = inMemoryDataTree.takeSnapshot();
+        DataTreeSnapshot test2 = inMemoryDataTree.takeSnapshot();
         minMaxListRead = test2.readNode(MIN_MAX_LIST_PATH);
         assertTrue(minMaxListRead.isPresent());
-        assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 3);
+        assertEquals(3, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
 
-        InMemoryDataTreeModification tempMod2 = test2.newModification();
+        DataTreeModification tempMod2 = test2.newModification();
         tempMod2.write(MIN_MAX_LIST_PATH, mapNodeBaz);
         tempMod2.write(pathToBaz, newNode2);
 
@@ -231,13 +241,13 @@ public class Bug4454Test {
         final DataTreeCandidate prepare3 = inMemoryDataTree.prepare(tempMod2);
         inMemoryDataTree.commit(prepare3);
 
-        InMemoryDataTreeSnapshot test3 = inMemoryDataTree.takeSnapshot();
+        DataTreeSnapshot test3 = inMemoryDataTree.takeSnapshot();
         minMaxListRead = test3.readNode(MIN_MAX_LIST_PATH);
         assertTrue(minMaxListRead.isPresent());
-        assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 1);
+        assertEquals(1, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
         assertTrue(minMaxListRead.get().getValue().toString().contains("test2"));
 
-        InMemoryDataTreeModification tempMod3 = test3.newModification();
+        DataTreeModification tempMod3 = test3.newModification();
         tempMod3.merge(MIN_MAX_LIST_PATH, mapNodeBar);
         tempMod3.merge(pathToBar, newNode1);
 
@@ -246,7 +256,7 @@ public class Bug4454Test {
         final DataTreeCandidate prepare4 = inMemoryDataTree.prepare(tempMod3);
         inMemoryDataTree.commit(prepare4);
 
-        InMemoryDataTreeSnapshot test4 = inMemoryDataTree.takeSnapshot();
+        DataTreeSnapshot test4 = inMemoryDataTree.takeSnapshot();
         testLoop(test4, "test1", "test2");
     }
 
@@ -276,9 +286,9 @@ public class Bug4454Test {
         final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
         inMemoryDataTree.commit(prepare1);
 
-        InMemoryDataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
+        DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
 
-        InMemoryDataTreeModification tempMod1 = test1.newModification();
+        DataTreeModification tempMod1 = test1.newModification();
         tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry);
         tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
         tempMod1.ready();
@@ -287,40 +297,34 @@ public class Bug4454Test {
         final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
         inMemoryDataTree.commit(prepare2);
 
-        final InMemoryDataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
+        final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
         final Optional<NormalizedNode<?, ?>> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
         assertTrue(masterContainer.isPresent());
         final Optional<NormalizedNodeContainer<?, ?, ?>> leafList = ((NormalizedNodeContainer) masterContainer.get())
                 .getChild(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
         assertTrue(leafList.isPresent());
-        assertTrue(leafList.get().getValue().size() == 3);
+        assertEquals(3, leafList.get().size());
     }
 
+    @Test
+    public void minMaxListDeleteTest() throws DataValidationFailedException {
+        final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
-    @Test(expected = DataValidationFailedException.class)
-    public void minMaxListDeleteExceptionTest() throws DataValidationFailedException {
-        final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
-
-        Map<QName, Object> key = new HashMap<>();
-        key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
 
-        NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, key);
+        NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
+            ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "foo"));
 
         final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH
                 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
 
-        key.clear();
-        key.put(MIN_MAX_KEY_LEAF_QNAME, "bar");
-
-        mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, key);
+        mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
+            ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "bar"));
 
         final YangInstanceIdentifier minMaxLeafBar = MASTER_CONTAINER_PATH
                 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
 
-        key.clear();
-        key.put(MIN_MAX_KEY_LEAF_QNAME, "baz");
-
-        mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME, key);
+        mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
+            ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "baz"));
 
         final YangInstanceIdentifier minMaxLeafBaz = MASTER_CONTAINER_PATH
                 .node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
@@ -337,23 +341,67 @@ public class Bug4454Test {
         inMemoryDataTree.validate(modificationTree);
         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
         inMemoryDataTree.commit(prepare);
+
+        // Empty list should have disappeared, along with the container, as we are not enforcing root
+        final NormalizedNode<?, ?> data = inMemoryDataTree.takeSnapshot()
+                .readNode(YangInstanceIdentifier.empty()).get();
+        assertTrue(data instanceof ContainerNode);
+        assertEquals(0, ((ContainerNode) data).size());
+    }
+
+    @Test
+    public void minMaxListDeleteExceptionTest() throws DataValidationFailedException {
+        final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
+
+        NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
+            ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "foo"));
+
+        final YangInstanceIdentifier minMaxLeafFoo = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
+
+        mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
+            ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "bar"));
+
+        final YangInstanceIdentifier minMaxLeafBar = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
+
+        mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME,
+            ImmutableMap.of(MIN_MAX_KEY_LEAF_QNAME, "baz"));
+
+        final YangInstanceIdentifier minMaxLeafBaz = PRESENCE_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
+
+        modificationTree.write(PRESENCE_PATH, ImmutableNodes.containerNode(PRESENCE_QNAME));
+        modificationTree.write(PRESENCE_MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
+        modificationTree.merge(PRESENCE_MIN_MAX_LIST_PATH, mapNodeBar);
+        modificationTree.merge(PRESENCE_MIN_MAX_LIST_PATH, mapNodeBaz);
+        modificationTree.delete(minMaxLeafFoo);
+        modificationTree.delete(minMaxLeafBar);
+        modificationTree.delete(minMaxLeafBaz);
+
+        try {
+            // Unlike minMaxListDeleteTest(), presence container enforces the list to be present
+            modificationTree.ready();
+            fail("Should have failed with IAE");
+        } catch (IllegalArgumentException e) {
+            assertEquals("Node (urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model?"
+                    + "revision=2015-02-02)presence is missing mandatory descendant "
+                    + "/(urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model?"
+                    + "revision=2015-02-02)min-max-list", e.getMessage());
+        }
     }
 
     @Test
     public void minMaxListNoMinMaxDeleteTest() throws DataValidationFailedException {
-        final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME_NO_MINMAX, MIN_MAX_KEY_LEAF_QNAME,
-            "foo");
+        final MapEntryNode fooEntryNoMinMaxNode =
+                ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME_NO_MINMAX, MIN_MAX_KEY_LEAF_QNAME, "foo");
         final MapNode mapNode1 = ImmutableNodes.mapNodeBuilder()
                 .withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME_NO_MINMAX))
-                .withChild(fooEntryNode).build();
+                .withChild(fooEntryNoMinMaxNode).build();
 
-        final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
+        final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
         Map<QName, Object> key = new HashMap<>();
         key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
 
-        NodeIdentifierWithPredicates mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME_NO_MINMAX,
-            key);
+        NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
 
         final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH
                 .node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2);
@@ -361,7 +409,7 @@ public class Bug4454Test {
         key.clear();
         key.put(MIN_MAX_KEY_LEAF_QNAME, "non-existing-leaf");
 
-        mapEntryPath2 = new NodeIdentifierWithPredicates(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
+        mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
 
         YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH)
                 .node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2).build();
@@ -376,16 +424,17 @@ public class Bug4454Test {
         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
         inMemoryDataTree.commit(prepare);
 
-        final InMemoryDataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
+        final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
         final Optional<NormalizedNode<?, ?>> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_NO_MINMAX_PATH);
-        assertTrue(minMaxListRead.isPresent());
-        assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 0);
+
+        // Empty list should have disappeared
+        assertFalse(minMaxListRead.isPresent());
     }
 
-    private static void testLoop(final InMemoryDataTreeSnapshot snapshot, final String first, final String second) {
+    private static void testLoop(final DataTreeSnapshot snapshot, final String first, final String second) {
         Optional<NormalizedNode<?, ?>> minMaxListRead = snapshot.readNode(MIN_MAX_LIST_PATH);
         assertTrue(minMaxListRead.isPresent());
-        assertTrue(((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).getValue().size() == 2);
+        assertEquals(2, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
         UnmodifiableCollection<?> collectionChildren = (UnmodifiableCollection<?>) minMaxListRead.get().getValue();
 
         for (Object collectionChild : collectionChildren) {