BUG-865: remove BitImpl
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / type / BitImplTest.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.type;
9
10 import static java.util.Collections.emptyList;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import java.net.URI;
14 import java.net.URISyntaxException;
15 import java.util.Date;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.Status;
20
21 public class BitImplTest {
22
23     @Test
24     // We're testing equals()
25     @SuppressWarnings({"ObjectEqualsNull", "EqualsBetweenInconvertibleTypes"})
26     public void test() throws URISyntaxException {
27
28         // hashCode method test
29         final URI uriA1 = new URI("some:uriA1");
30         final URI uriA2 = new URI("some:uriA2");
31         final URI uriB1 = new URI("some:uriB1");
32         final URI uriB2 = new URI("some:uriB2");
33
34         QName qnameA1 = QName.create(uriA1, new Date(6000000), "some nameA1");
35         QName qnameA2 = QName.create(uriA2, new Date(7000000), "some nameA2");
36         SchemaPath schemaPathA = SchemaPath.create(true, qnameA1, qnameA2);
37
38         QName qnameB1 = QName.create(uriB1, new Date(6000000), "some nameB1");
39         QName qnameB2 = QName.create(uriB2, new Date(7000000), "some nameB2");
40         SchemaPath schemaPathB = SchemaPath.create(true, qnameB1, qnameB2);
41
42         BitImpl biB;
43         BitImpl biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
44
45         assertEquals("biA should equals to itsefl", biA, biA);
46         assertFalse("biA shouldn't equal to null", biA.equals(null));
47         assertFalse("biA shouldn't equal to object of other type", biA.equals("str"));
48
49          // // test schemaPath
50         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
51         biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
52         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
53
54         biA = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
55         biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
56         assertEquals("biA should equal to biB", biA, biB);
57
58         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
59         biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
60         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
61
62         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
63         biB = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
64         assertEquals("biA should equal to biB", biA, biB);
65
66         biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
67
68         // test of getter methods
69         assertEquals("Incorrect value for qname.", qnameA2, biA.getQName());
70         assertEquals("Incorrect value for schema path.", schemaPathA, biA.getPath());
71         assertEquals("Incorrect value for description.", "description", biA.getDescription());
72         assertEquals("Incorrect value for reference.", "reference", biA.getReference());
73         assertEquals("Incorrect value for status.", Status.CURRENT, biA.getStatus());
74         assertEquals("Incorrect value for unknown nodes.", emptyList(), biA.getUnknownSchemaNodes());
75
76         // test of toString method
77         assertEquals("toString method doesn't return correct value", "Bit[name=some nameA2, position=55]", biA.toString());
78     }
79 }