1 package org.opendaylight.yangtools.yang.parser.util;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertTrue;
8 import java.net.URISyntaxException;
11 import org.junit.Test;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.*;
14 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
15 import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
17 public class BitImplTest {
22 // hashCode method test
29 boolean urisInitiallized = false;
31 uriA = new URI("some:uriA");
32 uriA1 = new URI("some:uriA1");
33 uriA2 = new URI("some:uriA2");
34 uriB = new URI("some:uriB");
35 uriB1 = new URI("some:uriB1");
36 uriB2 = new URI("some:uriB2");
37 urisInitiallized = true;
39 } catch (URISyntaxException e) {
41 assertTrue("Not all required uri variables were instantiated.", urisInitiallized);
44 QName qnameA = new QName(uriA, new Date(5000000), "some name");
46 QName qnameA1 = new QName(uriA1, new Date(6000000), "some nameA1");
47 QName qnameA2 = new QName(uriA2, new Date(7000000), "some nameA2");
48 List<QName> qnamesA = new ArrayList<>();
51 SchemaPath schemaPathA = new SchemaPath(qnamesA, true);
53 QName qnameB = new QName(uriB, new Date(5000000), "some name");
55 QName qnameB1 = new QName(uriB1, new Date(6000000), "some nameB1");
56 QName qnameB2 = new QName(uriB2, new Date(7000000), "some nameB2");
57 List<QName> qnamesB = new ArrayList<>();
60 SchemaPath schemaPathB = new SchemaPath(qnamesB, true);
63 BitImpl biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
65 assertEquals("biA should equals to itsefl", biA, biA);
66 assertFalse("biA shouldn't equal to null", biA.equals(null));
67 assertFalse("biA shouldn't equal to object of other type", biA.equals(new String("str")));
69 // test of equals method
71 biA = new BitImpl(55L, null, schemaPathA, "description", "reference", Status.CURRENT, null);
72 biB = new BitImpl(55L, qnameB, schemaPathA, "description", "reference", Status.CURRENT, null);
73 assertFalse("biA shouldn't equal to biB", biA.equals(biB));
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);
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));
84 biA = new BitImpl(55L, qnameA, null, "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));
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);
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));
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);
100 // test of hashCode method
101 biA = new BitImpl(null, null, null, "description", "reference", Status.CURRENT, null);
102 assertEquals("Incorrect hash code for biA.", 923522, biA.hashCode());
104 List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
105 SchemaPath path = org.mockito.Mockito.mock(SchemaPath.class);
106 UnknownSchemaNodeBuilder usnb = new UnknownSchemaNodeBuilder("module", 3, qnameB, path);
107 ModuleBuilder parent = org.mockito.Mockito.mock(ModuleBuilder.class);
108 usnb.setParent(parent);
110 unknownNodes.add(usnb.build());
112 biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, unknownNodes);
114 // test of getter methods
115 assertEquals("Incorrect value for qname.", qnameA, biA.getQName());
116 assertEquals("Incorrect value for schema path.", schemaPathA, biA.getPath());
117 assertEquals("Incorrect value for description.", "description", biA.getDescription());
118 assertEquals("Incorrect value for reference.", "reference", biA.getReference());
119 assertEquals("Incorrect value for status.", Status.CURRENT, biA.getStatus());
120 assertEquals("Incorrect value for unknown nodes.", unknownNodes, biA.getUnknownSchemaNodes());
122 // test of toString method
123 assertEquals("toString method doesn't return correct value", "Bit[name=some name, position=55]", biA.toString());