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.mdsal.eos.common.api;
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;
15 import java.io.Serial;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
19 public class GenericEntityTest {
22 public void basicTest() throws Exception {
23 final TestClass testClass = new TestClass();
24 final GenericEntity<?> genericEntity = new GenericEntity<>("testType", testClass);
25 final GenericEntity<?> genericEntityDiff = new GenericEntity<>("differentTestType", new TestClassDiff());
27 assertEquals(TestClass.class, genericEntity.getIdentifier().getClass());
28 assertEquals("testType", genericEntity.getType());
29 assertTrue(genericEntity.toString().contains("testType"));
30 assertNotEquals(genericEntity.hashCode(), genericEntityDiff.hashCode());
31 assertTrue(genericEntity.equals(genericEntity));
32 assertTrue(genericEntity.equals(new GenericEntity<>("testType", testClass)));
33 assertFalse(genericEntity.equals(genericEntityDiff));
34 assertFalse(genericEntity.equals(""));
35 assertFalse(genericEntity.equals(new GenericEntity<>("differentTestType", testClass)));
38 private static final class TestClass implements HierarchicalIdentifier<TestClass> {
40 private static final long serialVersionUID = 1L;
43 public boolean contains(final TestClass other) {
48 private static final class TestClassDiff implements HierarchicalIdentifier<TestClassDiff> {
50 private static final long serialVersionUID = 1L;
53 public boolean contains(final TestClassDiff other) {