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