Binding2 runtime - Codecs impl - tests
[mdsal.git] / binding2 / mdsal-binding2-dom-codec / src / main / test / org / opendaylight / mdsal / binding / javav2 / dom / codec / impl / context / UnionValueOptionContextTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.javav2.dom.codec.impl.context;
9
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.assertTrue;
14
15 import java.lang.reflect.Method;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.value.ValueTypeCodec;
19
20 public class UnionValueOptionContextTest {
21
22     private static UnionValueOptionContext TEST_UVOC_1;
23     private static UnionValueOptionContext TEST_UVOC_2;
24
25     @Before
26     public void setUp() throws Exception {
27         final Method methodFoo1 = TestDataObject1.class.getMethod("foo");
28         final Method methodFoo2 = TestDataObject2.class.getMethod("foo");
29         TEST_UVOC_1 = new UnionValueOptionContext(TestUnion.class, TestDataObject1.class, methodFoo1,
30                 ValueTypeCodec.EMPTY_CODEC);
31         TEST_UVOC_2 = new UnionValueOptionContext(TestUnion.class, TestDataObject2.class, methodFoo2,
32                 ValueTypeCodec.EMPTY_CODEC);
33     }
34
35     @Test
36     public void hashCodeTest() throws Exception {
37         final Method methodFoo1 = TestDataObject1.class.getMethod("foo");
38         final UnionValueOptionContext test_uvoc = new UnionValueOptionContext(TestUnion.class, TestDataObject1.class,
39                 methodFoo1, ValueTypeCodec.EMPTY_CODEC);
40
41         assertEquals("HashCode", test_uvoc.hashCode(), TEST_UVOC_1.hashCode());
42         assertNotEquals("HashCode", TEST_UVOC_1.hashCode(), TEST_UVOC_2.hashCode());
43     }
44
45     @Test
46     public void equalsTest() throws Exception {
47         final Method methodFoo1 = TestDataObject1.class.getMethod("foo");
48         final UnionValueOptionContext test_uvoc = new UnionValueOptionContext(TestUnion.class, TestDataObject1.class,
49                 methodFoo1, ValueTypeCodec.EMPTY_CODEC);
50
51         assertTrue("Equals", TEST_UVOC_1.equals(test_uvoc));
52         assertFalse("Not equals", TEST_UVOC_1.equals(TEST_UVOC_2));
53     }
54
55     protected static final class TestDataObject1 {
56         public void foo() {
57         }
58     }
59
60     protected static final class TestDataObject2 {
61         public void foo() {
62         }
63     }
64
65     public static final class TestUnion {
66         public TestUnion(final TestDataObject1 arg) {
67         }
68
69         public TestUnion(final TestDataObject2 arg) {
70         }
71     }
72 }