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