2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.util;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.fail;
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;
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;
26 public class BitImplTest {
29 // We're testing equals()
30 @SuppressWarnings({"ObjectEqualsNull", "EqualsBetweenInconvertibleTypes"})
33 // hashCode method test
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.");
50 QName qnameA = QName.create(uriA, new Date(5000000), "some name");
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<>();
57 SchemaPath schemaPathA = SchemaPath.create(qnamesA, true);
59 QName qnameB = QName.create(uriB, new Date(5000000), "some name");
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<>();
66 SchemaPath schemaPathB = SchemaPath.create(qnamesB, true);
69 BitImpl biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT, null);
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"));
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, 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));
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 biA = new BitImpl(55L, qnameA, schemaPathA, "description", "reference", Status.CURRENT,null);
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());
110 // test of toString method
111 assertEquals("toString method doesn't return correct value", "Bit[name=some name, position=55]", biA.toString());