Bug 3899: Milestone Increase test coverage for YangTools - Types
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / StringTypeTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertTrue;
15
16 import java.sql.Types;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 import org.opendaylight.yangtools.yang.model.api.Status;
21
22 public class StringTypeTest {
23
24     private StringType string;
25     private int hash;
26
27     @Before
28     public void setup() {
29         string = StringType.getInstance();
30         hash = string.hashCode();
31     }
32
33     @Test
34     public void testGetBaseTypeShouldReturnNull() {
35         assertTrue(string.getBaseType() == null);
36     }
37
38     @Test
39     public void testGetters() {
40         assertEquals(string.getUnits(), "");
41         assertNull(string.getDefaultValue());
42         assertEquals(string.getDescription(), "");
43         assertEquals(string.getReference(), "");
44         assertEquals(string.getQName(), BaseTypes.STRING_QNAME);
45         assertEquals(string.getStatus(), Status.CURRENT);
46
47         SchemaPath path = SchemaPath.create(true, string.getQName());
48         assertEquals(string.getPath(), path);
49
50         assertNotNull(string.getLengthConstraints());
51         assertNotNull(string.getPatternConstraints());
52         assertNotNull(string.getUnknownSchemaNodes());
53     }
54
55     @Test
56     public void testToString() {
57         String toString = string.toString();
58         assertTrue(toString.contains("StringType"));
59     }
60
61     @Test
62     public void testEquals() {
63         assertTrue(string.equals(string));
64         assertFalse(string.equals(null));
65         assertFalse(string.equals(Types.DOUBLE));
66     }
67 }