2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.util;
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;
16 import java.util.Collections;
17 import java.util.Optional;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.api.Status;
24 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
25 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
27 public class BitsTypeTest {
30 private BitsTypeDefinition.Bit bit;
33 public void canCreateBitsType() {
34 MockitoAnnotations.initMocks(this);
35 doReturn("test").when(bit).getName();
37 QName qname = QName.create("namespace", "localname");
38 SchemaPath schemaPath = SchemaPath.create(true, qname);
40 BitsTypeDefinition bitsType = BaseTypes.bitsTypeBuilder(schemaPath).addBit(bit).build();
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("getPath should equal schemaPath", schemaPath, bitsType.getPath());
50 assertEquals("Status should be CURRENT", Status.CURRENT, bitsType.getStatus());
51 assertEquals("Should be empty list", Collections.EMPTY_LIST, bitsType.getUnknownSchemaNodes());
52 assertEquals("Values should be [enumPair]", Collections.singletonList(bit), bitsType.getBits());
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);