Promote SchemaUnawareCodec to a top-level construct
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / mdsal / binding / dom / codec / impl / UnionValueOptionContextTest.java
1 /*
2  * Copyright (c) 2016 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.dom.codec.impl;
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
19 public class UnionValueOptionContextTest {
20     private static UnionValueOptionContext TEST_UVOC_1;
21     private static UnionValueOptionContext TEST_UVOC_2;
22
23     @Before
24     public void setUp() throws Exception {
25         final Method methodFoo1 = TestDataObject1.class.getMethod("foo");
26         final Method methodFoo2 = TestDataObject2.class.getMethod("foo");
27         TEST_UVOC_1 = new UnionValueOptionContext(TestUnion.class, TestDataObject1.class, methodFoo1,
28             SchemaUnawareCodec.NOOP_CODEC);
29         TEST_UVOC_2 = new UnionValueOptionContext(TestUnion.class, TestDataObject2.class, methodFoo2,
30             SchemaUnawareCodec.NOOP_CODEC);
31     }
32
33     @Test
34     public void hashCodeTest() throws Exception {
35         final Method methodFoo1 = TestDataObject1.class.getMethod("foo");
36         final UnionValueOptionContext test_uvoc = new UnionValueOptionContext(TestUnion.class, TestDataObject1.class,
37             methodFoo1, SchemaUnawareCodec.NOOP_CODEC);
38
39         assertEquals("HashCode", test_uvoc.hashCode(), TEST_UVOC_1.hashCode());
40         assertNotEquals("HashCode", TEST_UVOC_1.hashCode(), TEST_UVOC_2.hashCode());
41     }
42
43     @Test
44     public void equalsTest() throws Exception {
45         final Method methodFoo1 = TestDataObject1.class.getMethod("foo");
46         final UnionValueOptionContext test_uvoc = new UnionValueOptionContext(TestUnion.class, TestDataObject1.class,
47             methodFoo1, SchemaUnawareCodec.NOOP_CODEC);
48
49         assertTrue("Equals", TEST_UVOC_1.equals(test_uvoc));
50         assertFalse("Not equals", TEST_UVOC_1.equals(TEST_UVOC_2));
51     }
52
53     protected static final class TestDataObject1 {
54         public void foo() {
55
56         }
57     }
58
59     protected static final class TestDataObject2 {
60         public void foo() {
61
62         }
63     }
64
65     public static final class TestUnion {
66         public TestUnion(final TestDataObject1 arg) {
67
68         }
69
70         public TestUnion(final TestDataObject2 arg) {
71
72         }
73     }
74 }