Bug 584: test coverage increase 67/12067/2
authorMartin Ciglan <mciglan@cisco.com>
Mon, 20 Oct 2014 08:16:45 +0000 (10:16 +0200)
committerMartin Ciglan <mciglan@cisco.com>
Tue, 21 Oct 2014 08:59:25 +0000 (10:59 +0200)
ModuleImportImpl.java
SchemaNodeUtils.java
StringType.java

Change-Id: I6df004289189bf80557c650dae27d63f895898d0
Signed-off-by: Martin Ciglan <mciglan@cisco.com>
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImplTest.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaNodeUtilsTest.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/StringTypeTest.java [new file with mode: 0644]

diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImplTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImplTest.java
new file mode 100644 (file)
index 0000000..62f127e
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014 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.model.util;
+
+import static org.junit.Assert.*;
+
+import java.util.Date;
+
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ModuleImportImplTest {
+
+    private ModuleImport module1, module2, module3, module4, module5;
+    private int hash1, hash2;
+    private Date now;
+
+    @Before
+    public void setup() {
+        now = new Date();
+        module1 = new ModuleImportImpl("myModule", now, "myPrefix");
+        module2 = new ModuleImportImpl(null, null, null);
+        module3 = new ModuleImportImpl("myModule", null, "customPrefix");
+        module4 = new ModuleImportImpl("myModule", now, null);
+        module5 = new ModuleImportImpl("myModule", now, "myPrefix");
+        hash1 = module1.hashCode();
+        hash2 = module2.hashCode();
+    }
+
+    @Test
+    public void testModule() {
+        assertNotNull(module1);
+        assertTrue(module1.getModuleName().equals("myModule"));
+        assertTrue(module1.getPrefix().equals("myPrefix"));
+        assertTrue(module1.getRevision().equals(now));
+        assertFalse(module1.equals(module2));
+    }
+
+    @Test
+    public void testToString() {
+        String toString = module1.toString();
+        assertTrue(toString.contains("ModuleImport"));
+    }
+
+    @Test
+    public void testHashCode() {
+        assertTrue(!(hash1 == hash2));
+    }
+
+    @Test
+    public void testEquals() {
+        assertTrue(module1.equals(module1));
+        assertFalse(module1.equals(module2));
+        assertFalse(module1.equals(""));
+        assertFalse(module2.equals(module1));
+        assertFalse(module1.equals(null));
+        assertFalse(module1.equals(module3));
+        assertFalse(module3.equals(module1));
+        assertFalse(module1.equals(module4));
+        assertFalse(module4.equals(module1));
+        assertTrue(module1.equals(module5));
+    }
+
+}
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaNodeUtilsTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaNodeUtilsTest.java
new file mode 100644 (file)
index 0000000..cdae541
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2014 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.model.util;
+
+import com.google.common.base.Optional;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Mock;
+import org.junit.Before;
+import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
+import org.junit.Test;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.hamcrest.CoreMatchers.instanceOf;
+
+public class SchemaNodeUtilsTest {
+
+    @Mock
+    private DerivableSchemaNode derivableNode;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    @Test
+    public void testHandleNullGetOriginalIfPossible() {
+        Optional<SchemaNode> originalIfPossible = SchemaNodeUtils
+                .getOriginalIfPossible(null);
+        assertNotNull(originalIfPossible);
+        assertThat(originalIfPossible, instanceOf(Optional.class));
+    }
+
+    @Test
+    public void testHandleNodeGetOriginalIfPossible() {
+        Optional<DerivableSchemaNode> of = Optional.of(derivableNode);
+        doReturn(of).when(derivableNode).getOriginal();
+        Optional<SchemaNode> originalIfPossible = SchemaNodeUtils
+                .getOriginalIfPossible(derivableNode);
+        assertNotNull(originalIfPossible);
+        assertThat(originalIfPossible, instanceOf(Optional.class));
+    }
+
+    @Test
+    public void testHandleNullGetRootOriginalIfPossible() {
+        SchemaNode rootOriginalIfPossible = SchemaNodeUtils
+                .getRootOriginalIfPossible(null);
+        assertNull(rootOriginalIfPossible);
+    }
+}
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/StringTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/StringTypeTest.java
new file mode 100644 (file)
index 0000000..095fb58
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2014 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.model.util;
+
+import static org.junit.Assert.*;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import java.sql.Types;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.junit.Before;
+import org.junit.Test;
+
+public class StringTypeTest {
+
+    private StringType string;
+    private int hash;
+
+    @Before
+    public void setup() {
+        string = StringType.getInstance();
+        hash = string.hashCode();
+    }
+
+    @Test
+    public void testGetBaseTypeShouldReturnNull() {
+        assertTrue(string.getBaseType() == null);
+    }
+
+    @Test
+    public void testGetters() {
+        assertEquals(string.getUnits(), "");
+        assertEquals(string.getDefaultValue(), "");
+        assertEquals(string.getDescription(), "");
+        assertEquals(string.getReference(), "");
+        assertEquals(string.getQName(), BaseTypes.STRING_QNAME);
+        assertEquals(string.getStatus(), Status.CURRENT);
+
+        SchemaPath path = SchemaPath.create(true, string.getQName());
+        assertEquals(string.getPath(), path);
+
+        assertNotNull(string.getLengthConstraints());
+        assertNotNull(string.getPatternConstraints());
+        assertNotNull(string.getUnknownSchemaNodes());
+    }
+
+    @Test
+    public void testToString() {
+        String toString = string.toString();
+        assertTrue(toString.contains("StringType"));
+    }
+
+    @Test
+    public void testEquals() {
+        assertTrue(string.equals(string));
+        assertFalse(string.equals(null));
+        assertFalse(string.equals(Types.DOUBLE));
+    }
+}