Harden yang-model-util test suite
[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.runners.MockitoJUnitRunner;
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;
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     private BitsTypeDefinition.Bit bit;
32
33     @Test
34     public void canCreateBitsType() {
35         doReturn("test").when(bit).getName();
36         doReturn(0L).when(bit).getPosition();
37         doReturn("toString").when(bit).toString();
38
39         QName qname = QName.create("namespace", "localname");
40         SchemaPath schemaPath = SchemaPath.create(true, qname);
41
42         BitsTypeDefinition bitsType = BaseTypes.bitsTypeBuilder(schemaPath).addBit(bit).build();
43
44         assertFalse(bitsType.getDescription().isPresent());
45         assertEquals("QName", qname, bitsType.getQName());
46         assertEquals(Optional.empty(), bitsType.getUnits());
47         assertNotEquals("Description should not be null", null, bitsType.toString());
48         assertFalse(bitsType.getReference().isPresent());
49         assertNull("BaseType should be null", bitsType.getBaseType());
50         assertEquals(Optional.empty(), bitsType.getDefaultValue());
51         assertEquals("getPath should equal schemaPath", schemaPath, bitsType.getPath());
52         assertEquals("Status should be CURRENT", Status.CURRENT, bitsType.getStatus());
53         assertEquals("Should be empty list", Collections.EMPTY_LIST, bitsType.getUnknownSchemaNodes());
54         assertEquals("Values should be [enumPair]", Collections.singletonList(bit), bitsType.getBits());
55
56         assertEquals("Hash code of bitsType should be equal",
57                 bitsType.hashCode(), bitsType.hashCode());
58         assertNotEquals("bitsType shouldn't equal to null", null, bitsType);
59         assertEquals("bitsType should equals to itself", bitsType, bitsType);
60         assertNotEquals("bitsType shouldn't equal to object of other type", "str", bitsType);
61     }
62 }