Remove unnecessary String() constructor invocations
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / 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;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.fail;
13
14 import java.net.URI;
15 import java.net.URISyntaxException;
16 import java.util.ArrayList;
17 import java.util.Collections;
18 import java.util.Date;
19 import java.util.List;
20
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24 import org.opendaylight.yangtools.yang.model.api.Status;
25
26 public class BitImplTest {
27
28     @Test
29     // We're testing equals()
30     @SuppressWarnings({"ObjectEqualsNull", "EqualsBetweenInconvertibleTypes"})
31     public void test() {
32
33         // hashCode method test
34         URI uriA = null;
35         URI uriA1 = null;
36         URI uriA2 = null;
37         URI uriB = null;
38         URI uriB1 = null;
39         URI uriB2 = null;
40         try {
41             uriA = new URI("some:uriA");
42             uriA1 = new URI("some:uriA1");
43             uriA2 = new URI("some:uriA2");
44             uriB = new URI("some:uriB");
45             uriB1 = new URI("some:uriB1");
46             uriB2 = new URI("some:uriB2");
47         } catch (URISyntaxException e) {
48             fail("Not all required uri variables were instantiated.");
49         }
50         QName qnameA = QName.create(uriA, new Date(5000000), "some name");
51
52         QName qnameA1 = QName.create(uriA1, new Date(6000000), "some nameA1");
53         QName qnameA2 = QName.create(uriA2, new Date(7000000), "some nameA2");
54         List<QName> qnamesA = new ArrayList<>();
55         qnamesA.add(qnameA1);
56         qnamesA.add(qnameA2);
57         SchemaPath schemaPathA = SchemaPath.create(qnamesA, true);
58
59         QName qnameB = QName.create(uriB, new Date(5000000), "some name");
60
61         QName qnameB1 = QName.create(uriB1, new Date(6000000), "some nameB1");
62         QName qnameB2 = QName.create(uriB2, new Date(7000000), "some nameB2");
63         List<QName> qnamesB = new ArrayList<>();
64         qnamesB.add(qnameB1);
65         qnamesB.add(qnameB2);
66         SchemaPath schemaPathB = SchemaPath.create(qnamesB, true);
67
68         BitImpl biB;
69         BitImpl biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
70
71         assertEquals("biA should equals to itsefl", biA, biA);
72         assertFalse("biA shouldn't equal to null", biA.equals(null));
73         assertFalse("biA shouldn't equal to object of other type", biA.equals("str"));
74
75         biA = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
76         biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
77         assertEquals("biA should equal to biB", biA, biB);
78
79         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
80         biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
81         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
82
83         // // test schemaPath
84         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
85         biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
86         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
87
88         biA = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
89         biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
90         assertEquals("biA should equal to biB", biA, biB);
91
92         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
93         biB = new BitImpl(55L, qnameA, schemaPathB, "description", "reference", Status.CURRENT, null);
94         assertFalse("biA shouldn't equal to biB", biA.equals(biB));
95
96         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
97         biB = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
98         assertEquals("biA should equal to biB", biA, biB);
99
100         biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT,null);
101
102         // test of getter methods
103         assertEquals("Incorrect value for qname.", qnameA, biA.getQName());
104         assertEquals("Incorrect value for schema path.", schemaPathA, biA.getPath());
105         assertEquals("Incorrect value for description.", "description", biA.getDescription());
106         assertEquals("Incorrect value for reference.", "reference", biA.getReference());
107         assertEquals("Incorrect value for status.", Status.CURRENT, biA.getStatus());
108         assertEquals("Incorrect value for unknown nodes.", Collections.emptyList(), biA.getUnknownSchemaNodes());
109
110         // test of toString method
111         assertEquals("toString method doesn't return correct value", "Bit[name=some name, position=55]", biA.toString());
112
113     }
114 }