2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.binding.data.codec.impl;
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 import java.lang.reflect.Method;
15 import org.junit.Before;
16 import org.junit.Test;
18 public class UnionValueOptionContextTest {
19 private static UnionValueOptionContext TEST_UVOC_1;
20 private static UnionValueOptionContext TEST_UVOC_2;
23 public void setUp() throws Exception {
24 final Method methodFoo1 = TestDataObject1.class.getMethod("foo");
25 final Method methodFoo2 = TestDataObject2.class.getMethod("foo");
26 TEST_UVOC_1 = new UnionValueOptionContext(TestUnion.class, TestDataObject1.class, methodFoo1,
27 ValueTypeCodec.EMPTY_CODEC);
28 TEST_UVOC_2 = new UnionValueOptionContext(TestUnion.class, TestDataObject2.class, methodFoo2,
29 ValueTypeCodec.EMPTY_CODEC);
33 public void hashCodeTest() throws Exception {
34 final Method methodFoo1 = TestDataObject1.class.getMethod("foo");
35 final UnionValueOptionContext test_uvoc = new UnionValueOptionContext(TestUnion.class, TestDataObject1.class,
36 methodFoo1, ValueTypeCodec.EMPTY_CODEC);
38 assertEquals("HashCode", test_uvoc.hashCode(), TEST_UVOC_1.hashCode());
39 assertNotEquals("HashCode", TEST_UVOC_1.hashCode(), TEST_UVOC_2.hashCode());
43 public void equalsTest() throws Exception {
44 final Method methodFoo1 = TestDataObject1.class.getMethod("foo");
45 final UnionValueOptionContext test_uvoc = new UnionValueOptionContext(TestUnion.class, TestDataObject1.class,
46 methodFoo1, ValueTypeCodec.EMPTY_CODEC);
48 assertTrue("Equals", TEST_UVOC_1.equals(test_uvoc));
49 assertFalse("Not equals", TEST_UVOC_1.equals(TEST_UVOC_2));
52 protected static final class TestDataObject1 {
56 protected static final class TestDataObject2 {
60 public static final class TestUnion {
61 public TestUnion(final TestDataObject1 arg) { }
62 public TestUnion(final TestDataObject2 arg) { }