bc41da9ab31f8d2b1f1368d280bf03a17e1fdb72
[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         public void testMultipleReferences() {
41                 final String s1 = "abcd";
42                 final String s2 = new String(s1);
43
44                 // Preliminary check
45                 assertEquals(s1, s2);
46                 assertNotSame(s1, s2);
47
48                 assertSame(s1, cache.getReference(s1));
49                 assertSame(s1, cache.getReference(s2));
50                 assertNotSame(s2, cache.getReference(s2));
51         }
52
53 }