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