Refactor GeneratedTypeBuilderImpl
[mdsal.git] / binding / mdsal-binding-generator-util / src / test / java / org / opendaylight / mdsal / binding / model / util / generated / type / builder / ConstantImplTest.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.mdsal.binding.model.util.generated.type.builder;
9
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;
14
15 import org.junit.Test;
16
17 public class ConstantImplTest {
18
19     @Test
20     public void testMethodsOfConstantImpl() {
21         final CodegenGeneratedTypeBuilder definingType = new CodegenGeneratedTypeBuilder("org.opendaylight.yangtools.test",
22                 "DefiningType");
23         final CodegenGeneratedTypeBuilder type = new CodegenGeneratedTypeBuilder("org.opendaylight.yangtools.test.v1",
24                 "BaseType");
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);
31
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"));
48
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));
54     }
55 }