Cleaned up Java Binding code from YANG Tools
[mdsal.git] / binding / mdsal-binding-generator-util / src / test / java / org / opendaylight / yangtools / binding / generator / util / generated / type / builder / MethodSignatureImplTest.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.binding.generator.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.assertTrue;
13
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.binding.generator.util.Types;
19 import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier;
20 import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
21 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature.Parameter;
22 import org.opendaylight.yangtools.sal.binding.model.api.Type;
23
24 public class MethodSignatureImplTest {
25
26     MethodSignatureImpl signature1, signature2, signature3, signature4;
27     int hash1, hash4;
28
29     @Before
30     public void setup() {
31         Type type = Types.STRING;
32         String name = "customMethod";
33         List<AnnotationType> annotations = new ArrayList<>();
34         String comment = "This is just a comment";
35         AccessModifier accessModifier = AccessModifier.PUBLIC;
36         Type returnType = Types.STRING;
37         List<Parameter> params = new ArrayList<>();
38         boolean isFinal = false;
39         boolean isAbstract = false;
40         boolean isStatic = false;
41
42         signature1 = new MethodSignatureImpl(type, name, annotations, comment,
43                 accessModifier, returnType, params, isFinal, isAbstract,
44                 isStatic);
45         signature2 = new MethodSignatureImpl(type, name, annotations, comment,
46                 accessModifier, returnType, params, isFinal, isAbstract,
47                 isStatic);
48         returnType = null;
49         signature3 = new MethodSignatureImpl(type, name, annotations, comment,
50                 accessModifier, returnType, params, isFinal, isAbstract,
51                 isStatic);
52         name = null;
53         signature4 = new MethodSignatureImpl(type, name, annotations, comment,
54                 accessModifier, returnType, params, isFinal, isAbstract,
55                 isStatic);
56
57         hash1 = signature1.hashCode();
58         hash4 = signature4.hashCode();
59     }
60
61     @Test
62     public void testToString() {
63         String toString = signature1.toString();
64         assertTrue(toString.contains("MethodSignatureImpl"));
65     }
66
67     @Test
68     public void testHashCode() {
69         assertEquals(hash1, hash1);
70         assertTrue(!(hash1 == hash4));
71     }
72
73     @Test
74     public void testEquals() {
75         assertTrue(signature1.equals(signature1));
76         assertTrue(signature1.equals(signature2));
77         assertFalse(signature1.equals(signature3));
78         assertFalse(signature3.equals(signature1));
79         assertFalse(signature1.equals(null));
80         assertFalse(signature1.equals(signature4));
81         assertFalse(signature4.equals(signature1));
82         assertFalse(signature1.equals(Types.STRING));
83     }
84
85 }