Move Adapter for Binding EntityOwnershipService
[mdsal.git] / entityownership / mdsal-eos-common-api / src / test / java / org / opendaylight / mdsal / common / api / clustering / GenericEntityTest.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.common.api.clustering;
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 javax.annotation.Nonnull;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.concepts.Path;
18
19 public class GenericEntityTest {
20
21     @Test
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());
26
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(new String()));
35         assertFalse(genericEntity.equals(new GenericEntity<>("differentTestType", testClass)));
36     }
37
38     private final class TestClass implements Path {
39         @Override
40         public boolean contains(@Nonnull Path other) {
41             return false;
42         }
43     }
44
45     private final class TestClassDiff implements Path {
46         @Override
47         public boolean contains(@Nonnull Path other) {
48             return false;
49         }
50     }
51 }