Cleaned up Java Binding code from YANG Tools
[mdsal.git] / binding / mdsal-binding-generator-util / src / test / java / org / opendaylight / yangtools / binding / generator / util / AbstractBaseTypeTest.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.binding.generator.util;
9
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.junit.rules.ExpectedException;
17
18 public class AbstractBaseTypeTest {
19
20     @Rule
21     public ExpectedException expException = ExpectedException.none();
22
23     @Test
24     public void testgetFullyQualifiedName() {
25         AbstractBaseType baseType = new AbstractBaseType("", "");
26         assertTrue(baseType.getFullyQualifiedName().isEmpty());
27     }
28
29     @Test
30     public void testCreateAbstractBaseTypeWithNullPackagename() {
31         expException.expect(IllegalArgumentException.class);
32         expException.expectMessage("Package Name for Generated Type cannot be null!");
33         new AbstractBaseType(null, "Test");
34     }
35
36     @Test
37     public void testCreateAbstractBaseTypeWithNullTypeName() {
38         expException.expect(IllegalArgumentException.class);
39         expException.expectMessage("Name of Generated Type cannot be null!");
40         new AbstractBaseType("org.opendaylight.yangtools.test", null);
41     }
42
43     @Test
44     public void testHashCode() {
45         AbstractBaseType baseType1 = new AbstractBaseType("org.opendaylight.yangtools.test", "Test");
46         AbstractBaseType baseType2 = new AbstractBaseType("org.opendaylight.yangtools.test", "Test2");
47         assertNotEquals(baseType1.hashCode(), baseType2.hashCode());
48     }
49
50     @Test
51     public void testToString() {
52         AbstractBaseType baseType = new AbstractBaseType("org.opendaylight.yangtools.test", "Test");
53         assertTrue(baseType.toString().contains("org.opendaylight.yangtools.test.Test"));
54         baseType = new AbstractBaseType("", "Test");
55         assertTrue(baseType.toString().contains("Test"));
56     }
57
58     @Test
59     public void testEquals() {
60         AbstractBaseType baseType1 = new AbstractBaseType("org.opendaylight.yangtools.test", "Test");
61         AbstractBaseType baseType2 = new AbstractBaseType("org.opendaylight.yangtools.test", "Test2");
62         AbstractBaseType baseType3 = null;
63         AbstractBaseType baseType4 = new AbstractBaseType("org.opendaylight.yangtools.test", "Test");
64         AbstractBaseType baseType5 = new AbstractBaseType("org.opendaylight.yangtools.test1", "Test");
65
66         assertFalse(baseType1.equals(baseType2));
67         assertFalse(baseType1.equals(baseType3));
68         assertTrue(baseType1.equals(baseType4));
69         assertFalse(baseType1.equals(baseType5));
70         assertFalse(baseType1.equals(null));
71     }
72 }