2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.objcache.spi;
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;
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;
22 public class SoftKeyTest {
23 private FinalizableReferenceQueue queue;
28 queue = new FinalizableReferenceQueue();
32 public void tearDown() {
37 public void testEquals() {
38 final String str = "foo";
40 final SoftKey<?> key = new SoftKey<String>(str, queue) {
42 public void finalizeReferent() {
47 assertSame(str, key.get());
48 assertEquals(str.hashCode(), key.hashCode());
49 assertTrue(key.equals(str));
51 assertNull(key.get());
52 assertEquals(str.hashCode(), key.hashCode());
53 assertFalse(key.equals(str));