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