69218873ca5229967a9f72aca57754732c3426ad
[yangtools.git] / common / object-cache-guava / src / test / java / org / opendaylight / yangtools / objcache / guava / GuavaObjectCacheTest.java
1 /*
2  * Copyright (c) 2014 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.yangtools.objcache.guava;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotSame;
12 import static org.junit.Assert.assertSame;
13
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.objcache.ObjectCache;
17 import org.opendaylight.yangtools.objcache.ObjectCacheFactory;
18
19 public class GuavaObjectCacheTest {
20     private ObjectCache cache;
21
22     @Before
23     public void setUp() {
24         cache = ObjectCacheFactory.getObjectCache(String.class);
25     }
26
27     @Test
28     public void testCorrectWiring() {
29         assertEquals(GuavaObjectCache.class, cache.getClass());
30     }
31
32     @Test
33     public void testInitialReference() {
34         final String s1 = "abcd";
35         final String s2 = cache.getReference(s1);
36         assertSame(s1, s2);
37     }
38
39     @Test
40     // This test is based on using different references
41     @SuppressWarnings("RedundantStringConstructorCall")
42     public void testMultipleReferences() {
43         final String s1 = "abcd";
44         final String s2 = new String(s1);
45
46         // Preliminary check
47         assertEquals(s1, s2);
48         assertNotSame(s1, s2);
49
50         assertSame(s1, cache.getReference(s1));
51         assertSame(s1, cache.getReference(s2));
52         assertNotSame(s2, cache.getReference(s2));
53     }
54
55 }