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.type;
10 import static java.util.Collections.emptyList;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
15 import java.net.URISyntaxException;
16 import java.util.Date;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 import org.opendaylight.yangtools.yang.model.api.Status;
22 public class BitImplTest {
25 // We're testing equals()
26 @SuppressWarnings({"ObjectEqualsNull", "EqualsBetweenInconvertibleTypes"})
27 public void test() throws URISyntaxException {
29 // hashCode method test
30 final URI uriA1 = new URI("some:uriA1");
31 final URI uriA2 = new URI("some:uriA2");
32 final URI uriB1 = new URI("some:uriB1");
33 final URI uriB2 = new URI("some:uriB2");
35 QName qnameA1 = QName.create(uriA1, new Date(6000000), "some nameA1");
36 QName qnameA2 = QName.create(uriA2, new Date(7000000), "some nameA2");
37 SchemaPath schemaPathA = SchemaPath.create(true, qnameA1, qnameA2);
39 final QName qnameB1 = QName.create(uriB1, new Date(6000000), "some nameB1");
40 final QName qnameB2 = QName.create(uriB2, new Date(7000000), "some nameB2");
41 final SchemaPath schemaPathB = SchemaPath.create(true, qnameB1, qnameB2);
43 BitImpl biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
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"));
50 biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
51 BitImpl biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList());
52 assertFalse("biA shouldn't equal to biB", biA.equals(biB));
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);
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));
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);
66 biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList());
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());
76 // test of toString method
77 assertEquals("toString method doesn't return correct value", "Bit[name=some nameA2, position=55]",