Remove redundant string operations
[mdsal.git] / entityownership / mdsal-eos-common-api / src / test / java / org / opendaylight / mdsal / eos / common / api / 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.eos.common.api;
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 org.junit.Test;
16 import org.opendaylight.yangtools.concepts.Path;
17
18 public class GenericEntityTest {
19
20     @Test
21     public void basicTest() throws Exception {
22         final TestClass testClass = new TestClass();
23         final GenericEntity genericEntity = new GenericEntity<>("testType", testClass);
24         final GenericEntity genericEntityDiff = new GenericEntity<>("differentTestType", new TestClassDiff());
25
26         assertEquals(TestClass.class, genericEntity.getIdentifier().getClass());
27         assertEquals("testType", genericEntity.getType());
28         assertTrue(genericEntity.toString().contains("testType"));
29         assertNotEquals(genericEntity.hashCode(), genericEntityDiff.hashCode());
30         assertTrue(genericEntity.equals(genericEntity));
31         assertTrue(genericEntity.equals(new GenericEntity<>("testType", testClass)));
32         assertFalse(genericEntity.equals(genericEntityDiff));
33         assertFalse(genericEntity.equals(""));
34         assertFalse(genericEntity.equals(new GenericEntity<>("differentTestType", testClass)));
35     }
36
37     private final class TestClass implements Path {
38         @Override
39         public boolean contains(final Path other) {
40             return false;
41         }
42     }
43
44     private final class TestClassDiff implements Path {
45         @Override
46         public boolean contains(final Path other) {
47             return false;
48         }
49     }
50 }