BUG-994: improve object cache
[yangtools.git] / common / object-cache-guava / src / test / java / org / opendaylight / yangtools / objcache / guava / GuavaObjectCacheTest.java
diff --git a/common/object-cache-guava/src/test/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCacheTest.java b/common/object-cache-guava/src/test/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCacheTest.java
new file mode 100644 (file)
index 0000000..bc41da9
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.objcache.guava;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.objcache.ObjectCache;
+import org.opendaylight.yangtools.objcache.ObjectCacheFactory;
+
+public class GuavaObjectCacheTest {
+       private ObjectCache cache;
+
+       @Before
+       public void setUp() {
+               cache = ObjectCacheFactory.getObjectCache(String.class);
+       }
+
+       @Test
+       public void testCorrectWiring() {
+               assertEquals(GuavaObjectCache.class, cache.getClass());
+       }
+
+       @Test
+       public void testInitialReference() {
+               final String s1 = "abcd";
+               final String s2 = cache.getReference(s1);
+               assertSame(s1, s2);
+       }
+
+       @Test
+       public void testMultipleReferences() {
+               final String s1 = "abcd";
+               final String s2 = new String(s1);
+
+               // Preliminary check
+               assertEquals(s1, s2);
+               assertNotSame(s1, s2);
+
+               assertSame(s1, cache.getReference(s1));
+               assertSame(s1, cache.getReference(s2));
+               assertNotSame(s2, cache.getReference(s2));
+       }
+
+}