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 org.junit.Test;
18 import org.mockito.Mock;
19 import org.mockito.MockitoAnnotations;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22 import org.opendaylight.yangtools.yang.model.api.Status;
23 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
24 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
26 public class BitsTypeTest {
29 private BitsTypeDefinition.Bit bit;
32 public void canCreateBitsType() {
33 MockitoAnnotations.initMocks(this);
34 doReturn("test").when(bit).getName();
36 QName qname = QName.create("namespace", "localname");
37 SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qname), true);
39 BitsTypeDefinition bitsType = BaseTypes.bitsTypeBuilder(schemaPath).addBit(bit).build();
41 assertFalse(bitsType.getDescription().isPresent());
42 assertEquals("QName", qname, bitsType.getQName());
43 assertNull("Should be null", bitsType.getUnits());
44 assertNotEquals("Description should not be null", null, bitsType.toString());
45 assertFalse(bitsType.getReference().isPresent());
46 assertNull("BaseType should be null", bitsType.getBaseType());
47 assertNull("Default value should be null", bitsType.getDefaultValue());
48 assertEquals("getPath should equal schemaPath", schemaPath, bitsType.getPath());
49 assertEquals("Status should be CURRENT", Status.CURRENT, bitsType.getStatus());
50 assertEquals("Should be empty list", Collections.EMPTY_LIST, bitsType.getUnknownSchemaNodes());
51 assertEquals("Values should be [enumPair]", Collections.singletonList(bit), bitsType.getBits());
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);