Rework NormalizedNode type hierarchy
[yangtools.git] / yang / yang-data-api / src / test / java / org / opendaylight / yangtools / yang / data / api / schema / tree / NormalizedNodeDataTreeCandidateNodeTest.java
index 8741b5311daecd5873faaa8786bf43f8c84b46c3..5c535237d2c77dbf1fe76841b8c32c985f49d2f5 100644 (file)
@@ -5,14 +5,12 @@
  * 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.data.api.schema.tree;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doCallRealMethod;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
@@ -22,14 +20,14 @@ import java.util.List;
 import java.util.Optional;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
 
 public class NormalizedNodeDataTreeCandidateNodeTest {
 
     @Test
     public void testNormalizedNodeDataTreeCandidateNode() {
-        final NormalizedNode<?, ?> mockedNormalizedNode = mock(NormalizedNode.class);
+        final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
         final NormalizedNodeDataTreeCandidateNode normalizedNodeDataTreeCandidateNode = new
                 NormalizedNodeDataTreeCandidateNode(mockedNormalizedNode);
 
@@ -41,28 +39,28 @@ public class NormalizedNodeDataTreeCandidateNodeTest {
         assertTrue(childNodes instanceof List);
         assertTrue(childNodes.isEmpty());
 
-        assertNull(normalizedNodeDataTreeCandidateNode.getModifiedChild(mockedPathArgument));
+        assertEquals(Optional.empty(), normalizedNodeDataTreeCandidateNode.getModifiedChild(mockedPathArgument));
 
         assertEquals(ModificationType.WRITE, normalizedNodeDataTreeCandidateNode.getModificationType());
         assertEquals(Optional.of(mockedNormalizedNode), normalizedNodeDataTreeCandidateNode.getDataAfter());
         assertEquals(Optional.empty(), normalizedNodeDataTreeCandidateNode.getDataBefore());
 
-        final NormalizedNodeContainer mockedNormalizedNodeContainer = mock(NormalizedNodeContainer.class);
+        final DistinctNodeContainer mockedNormalizedNodeContainer = mock(DistinctNodeContainer.class);
         final NormalizedNodeDataTreeCandidateNode normalizedNodeDataTreeCandidateNode2 = new
                 NormalizedNodeDataTreeCandidateNode(mockedNormalizedNodeContainer);
-        final NormalizedNode<?, ?> mockedChildNormNode1 = mock(NormalizedNode.class);
-        final NormalizedNode<?, ?> mockedChildNormNode2 = mock(NormalizedNode.class);
-        final Collection<NormalizedNode<?, ?>> mockedChildNodes = Arrays.asList(mockedChildNormNode1,
+        final NormalizedNode mockedChildNormNode1 = mock(NormalizedNode.class);
+        final NormalizedNode mockedChildNormNode2 = mock(NormalizedNode.class);
+        final Collection<NormalizedNode> mockedChildNodes = Arrays.asList(mockedChildNormNode1,
                 mockedChildNormNode2, null);
-        doReturn(mockedChildNodes).when(mockedNormalizedNodeContainer).getValue();
+        doReturn(mockedChildNodes).when(mockedNormalizedNodeContainer).body();
         final Collection<DataTreeCandidateNode> childNodes2 = normalizedNodeDataTreeCandidateNode2.getChildNodes();
         assertEquals(3, childNodes2.size());
 
-        doReturn(Optional.empty()).when(mockedNormalizedNodeContainer).getChild(any(PathArgument.class));
-        assertNull(normalizedNodeDataTreeCandidateNode2.getModifiedChild(mockedPathArgument));
+        doReturn(null).when(mockedNormalizedNodeContainer).childByArg(any(PathArgument.class));
+        doCallRealMethod().when(mockedNormalizedNodeContainer).findChildByArg(any(PathArgument.class));
+        assertEquals(Optional.empty(), normalizedNodeDataTreeCandidateNode2.getModifiedChild(mockedPathArgument));
 
-        doReturn(Optional.of(mockedChildNormNode1)).when(mockedNormalizedNodeContainer).getChild(
-                any(PathArgument.class));
-        assertNotNull(normalizedNodeDataTreeCandidateNode2.getModifiedChild(mockedPathArgument));
+        doReturn(mockedChildNormNode1).when(mockedNormalizedNodeContainer).childByArg(any(PathArgument.class));
+        assertTrue(normalizedNodeDataTreeCandidateNode2.getModifiedChild(mockedPathArgument).isPresent());
     }
 }