62f127ef5f381e9184ea808c8a64ee623d4c4b4d
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / ModuleImportImplTest.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.*;
11
12 import java.util.Date;
13
14 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
15 import org.junit.Before;
16 import org.junit.Test;
17
18 public class ModuleImportImplTest {
19
20     private ModuleImport module1, module2, module3, module4, module5;
21     private int hash1, hash2;
22     private Date now;
23
24     @Before
25     public void setup() {
26         now = new Date();
27         module1 = new ModuleImportImpl("myModule", now, "myPrefix");
28         module2 = new ModuleImportImpl(null, null, null);
29         module3 = new ModuleImportImpl("myModule", null, "customPrefix");
30         module4 = new ModuleImportImpl("myModule", now, null);
31         module5 = new ModuleImportImpl("myModule", now, "myPrefix");
32         hash1 = module1.hashCode();
33         hash2 = module2.hashCode();
34     }
35
36     @Test
37     public void testModule() {
38         assertNotNull(module1);
39         assertTrue(module1.getModuleName().equals("myModule"));
40         assertTrue(module1.getPrefix().equals("myPrefix"));
41         assertTrue(module1.getRevision().equals(now));
42         assertFalse(module1.equals(module2));
43     }
44
45     @Test
46     public void testToString() {
47         String toString = module1.toString();
48         assertTrue(toString.contains("ModuleImport"));
49     }
50
51     @Test
52     public void testHashCode() {
53         assertTrue(!(hash1 == hash2));
54     }
55
56     @Test
57     public void testEquals() {
58         assertTrue(module1.equals(module1));
59         assertFalse(module1.equals(module2));
60         assertFalse(module1.equals(""));
61         assertFalse(module2.equals(module1));
62         assertFalse(module1.equals(null));
63         assertFalse(module1.equals(module3));
64         assertFalse(module3.equals(module1));
65         assertFalse(module1.equals(module4));
66         assertFalse(module4.equals(module1));
67         assertTrue(module1.equals(module5));
68     }
69
70 }