Enable checkstyle on objectcache and mockito-config
[yangtools.git] / common / object-cache-api / src / test / java / org / opendaylight / yangtools / objcache / spi / SoftKeyTest.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.assertFalse;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertSame;
14 import static org.junit.Assert.assertTrue;
15
16 import com.google.common.base.FinalizableReferenceQueue;
17 import org.junit.After;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.objcache.spi.AbstractObjectCache.SoftKey;
21
22 public class SoftKeyTest {
23     private FinalizableReferenceQueue queue;
24
25
26     @Before
27     public void setUp() {
28         queue = new FinalizableReferenceQueue();
29     }
30
31     @After
32     public void tearDown() {
33         queue.close();
34     }
35
36     @Test
37     public void testEquals() {
38         final String str = "foo";
39
40         final SoftKey<?> key = new SoftKey<String>(str, queue) {
41             @Override
42             public void finalizeReferent() {
43
44             }
45         };
46
47         assertSame(str, key.get());
48         assertEquals(str.hashCode(), key.hashCode());
49         assertTrue(key.equals(str));
50         key.clear();
51         assertNull(key.get());
52         assertEquals(str.hashCode(), key.hashCode());
53         assertFalse(key.equals(str));
54     }
55 }