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.binding.generator.util.generated.type.builder;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
15 import org.junit.Test;
17 public class ConstantImplTest {
20 public void testMethodsOfConstantImpl() {
21 final GeneratedTypeBuilderImpl definingType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test",
23 final GeneratedTypeBuilderImpl type = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test.v1",
25 final ConstantImpl constImpl = new ConstantImpl(definingType, type, "IpAddress", "127.0.0.1");
26 final ConstantImpl constImpl2 = new ConstantImpl(definingType, type, "IpAddress", "127.0.0.1");
27 final ConstantImpl constImpl3 = new ConstantImpl(definingType, type, "IpAddress", "127.0.0.0");
28 final ConstantImpl constImpl4 = constImpl;
29 final ConstantImpl constImpl5 = new ConstantImpl(definingType, type, null, "127.0.0.0");
30 final ConstantImpl constImpl6 = new ConstantImpl(definingType, type, "IpAddress", null);
32 assertEquals("DefiningType", constImpl.getDefiningType().getName());
33 assertEquals("BaseType", constImpl.getType().getName());
34 assertEquals("IpAddress", constImpl.getName());
35 assertEquals("127.0.0.1", constImpl.getValue());
36 assertTrue(constImpl.toFormattedString().contains("GeneratedTransferObject"));
37 assertTrue(constImpl.toString().contains("GeneratedTransferObject"));
38 assertEquals(constImpl.hashCode(), constImpl2.hashCode());
39 assertNotNull(constImpl.getDefiningType());
40 assertNotNull(constImpl.getType());
41 assertNotNull(constImpl.getName());
42 assertNotNull(constImpl.getValue());
43 assertNotNull(constImpl.toFormattedString());
44 assertNotNull(constImpl.toString());
45 assertNotNull(constImpl.hashCode());
46 assertFalse(constImpl.equals(null));
47 assertFalse(constImpl.equals("test"));
49 assertTrue(constImpl.equals(constImpl2));
50 assertFalse(constImpl.equals(constImpl3));
51 assertTrue(constImpl.equals(constImpl4));
52 assertFalse(constImpl5.equals(constImpl));
53 assertFalse(constImpl6.equals(constImpl));