--- /dev/null
+/*
+ * 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));
+ }
+
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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));
+ }
+}