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