Cleanup: remove redundant type parameters
[yangtools.git] / common / object-cache-api / src / test / java / org / opendaylight / yangtools / objcache / spi / CacheTest.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.spi;
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.After;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.objcache.ObjectCache;
18
19 import com.google.common.base.FinalizableReferenceQueue;
20 import com.google.common.cache.CacheBuilder;
21
22 public class CacheTest {
23     private FinalizableReferenceQueue queue;
24     private ObjectCache oc;
25
26     @Before
27     public void setUp() {
28         queue = new FinalizableReferenceQueue();
29         oc = new AbstractObjectCache(CacheBuilder.newBuilder().softValues().build(), queue) {
30         };
31     }
32
33     @After
34     public void tearDown() {
35         queue.close();
36     }
37
38     @Test
39     public void testMissingKey() {
40         final String key1 = "abcd";
41         final String key2 = "efgh";
42
43         assertSame(key1, oc.getReference(key1));
44         assertSame(key2, oc.getReference(key2));
45     }
46
47     @Test
48     // This test is based on using different references
49     @SuppressWarnings("RedundantStringConstructorCall")
50     public void testPresentKey() {
51         final String key1 = new String("abcd");
52         final String key2 = new String("abcd");
53
54         assertSame(key1, oc.getReference(key1));
55
56         final String key3 = oc.getReference(key2);
57         assertEquals(key2, key3);
58         assertNotSame(key2, key3);
59         assertSame(key1, key3);
60     }
61 }