Remove SchemaPath from TypeDefinition implementations
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / BitsTypeTest.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.assertNotEquals;
13 import static org.junit.Assert.assertNull;
14 import static org.mockito.Mockito.doReturn;
15
16 import java.util.Collections;
17 import java.util.Optional;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.junit.MockitoJUnitRunner;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.common.Uint32;
24 import org.opendaylight.yangtools.yang.model.api.Status;
25 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
26 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
27
28 @RunWith(MockitoJUnitRunner.class)
29 public class BitsTypeTest {
30     @Mock
31     public BitsTypeDefinition.Bit bit;
32
33     @Test
34     public void canCreateBitsType() {
35         doReturn("test").when(bit).getName();
36         doReturn(Uint32.ZERO).when(bit).getPosition();
37         doReturn("toString").when(bit).toString();
38
39         QName qname = QName.create("namespace", "localname");
40
41         BitsTypeDefinition bitsType = BaseTypes.bitsTypeBuilder(qname).addBit(bit).build();
42
43         assertFalse(bitsType.getDescription().isPresent());
44         assertEquals("QName", qname, bitsType.getQName());
45         assertEquals(Optional.empty(), bitsType.getUnits());
46         assertNotEquals("Description should not be null", null, bitsType.toString());
47         assertFalse(bitsType.getReference().isPresent());
48         assertNull("BaseType should be null", bitsType.getBaseType());
49         assertEquals(Optional.empty(), bitsType.getDefaultValue());
50         assertEquals("Status should be CURRENT", Status.CURRENT, bitsType.getStatus());
51         assertEquals("Should be empty list", Collections.emptyList(), bitsType.getUnknownSchemaNodes());
52         assertEquals("Values should be [enumPair]", Collections.singletonList(bit), bitsType.getBits());
53
54         assertEquals("Hash code of bitsType should be equal",
55                 bitsType.hashCode(), bitsType.hashCode());
56         assertNotEquals("bitsType shouldn't equal to null", null, bitsType);
57         assertEquals("bitsType should equals to itself", bitsType, bitsType);
58         assertNotEquals("bitsType shouldn't equal to object of other type", "str", bitsType);
59     }
60 }