This adds some trivial tests.
Change-Id: I76b2ed6d76657f9687d7ab1b449857f44ea22d67
Signed-off-by: Robert Varga <rovarga@cisco.com>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
</dependencies>
</project>
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+import com.google.common.collect.UnmodifiableIterator;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+
+public class PathArgumentListTest {
+ private static final class TestClass extends PathArgumentList {
+ @Override
+ public UnmodifiableIterator<PathArgument> iterator() {
+ return null;
+ }
+
+ @Override
+ public PathArgument get(final int index) {
+ return null;
+ }
+
+ @Override
+ public int size() {
+ return 0;
+ }
+ }
+
+ @Test
+ public void testIsEmpty() {
+ assertFalse(new TestClass().isEmpty());
+ }
+
+ @Test
+ public void testProtections() {
+ final PathArgumentList l = new TestClass();
+
+ try {
+ l.remove(null);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ }
+
+ try {
+ l.addAll(null);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ }
+
+ try {
+ l.removeAll(null);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ }
+
+ try {
+ l.retainAll(null);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ }
+
+ try {
+ l.clear();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ }
+
+ try {
+ l.addAll(0, null);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ }
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.spi;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.mockito.Mockito;
+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.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+
+public class TreeNodeFactoryTest {
+
+ private static void checkTreeNode(final TreeNode node, final NormalizedNode<?, ?> data, final Version version) {
+ assertSame(data, node.getData());
+ assertSame(version, node.getSubtreeVersion());
+ assertSame(version, node.getVersion());
+ }
+
+ @Test
+ public void testNormalizedNodeContainer() {
+ final ContainerNode data = Mockito.mock(ContainerNode.class);
+ final Version version = Version.initial();
+ final TreeNode node = TreeNodeFactory.createTreeNode(data, version);
+
+ assertTrue(node instanceof LazyContainerNode);
+ checkTreeNode(node, data, version);
+ }
+
+ @Test
+ public void testOrderedNodeContainer() {
+ final OrderedMapNode data = Mockito.mock(OrderedMapNode.class);
+ final Version version = Version.initial();
+ final TreeNode node = TreeNodeFactory.createTreeNode(data, version);
+
+ assertTrue(node instanceof LazyContainerNode);
+ checkTreeNode(node, data, version);
+ }
+
+ @Test
+ public void testLeaf() {
+ final LeafNode<?> data = Mockito.mock(LeafNode.class);
+ final Version version = Version.initial();
+ final TreeNode node = TreeNodeFactory.createTreeNode(data, version);
+
+ assertTrue(node instanceof ValueNode);
+ checkTreeNode(node, data, version);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.spi;
+
+import static org.junit.Assert.assertFalse;
+import org.junit.Test;
+
+public class VersionTest {
+
+ @Test
+ public void testInitial() {
+ final Version v1 = Version.initial();
+ final Version v2 = Version.initial();
+
+ assertFalse(v1.equals(v2));
+ assertFalse(v2.equals(v1));
+ }
+
+ @Test
+ public void testNext() {
+ final Version v1 = Version.initial();
+ final Version v2 = v1.next();
+ final Version v3 = v2.next();
+ final Version v4 = v1.next();
+
+ assertFalse(v3.equals(v4));
+ assertFalse(v4.equals(v3));
+ }
+}