You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2012/05/28 17:39:02 UTC

svn commit: r1343291 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java

Author: jacopoc
Date: Mon May 28 15:39:02 2012
New Revision: 1343291

URL: http://svn.apache.org/viewvc?rev=1343291&view=rev
Log:
Enhanced unit test for UtilCache.putIfAbsentAndGet method to better explain its behaviour: it returns the reference to the same object passed as argument only if the key was not already found in cache.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java?rev=1343291&r1=1343290&r2=1343291&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/test/UtilCacheTests.java Mon May 28 15:39:02 2012
@@ -344,11 +344,21 @@ public class UtilCacheTests extends Gene
         Listener<String, String> gotListener = createListener(cache);
         Listener<String, String> wantedListener = new Listener<String, String>();
         wantedListener.noteKeyAddition(cache, "key", "value");
+        wantedListener.noteKeyAddition(cache, "anotherKey", "anotherValue");
         assertNull("no-get", cache.get("key"));
         assertEquals("putIfAbsentAndGet", "value", cache.putIfAbsentAndGet("key", "value"));
         assertHasSingleKey(cache, "key", "value");
         assertEquals("putIfAbsentAndGet", "value", cache.putIfAbsentAndGet("key", "newValue"));
         assertHasSingleKey(cache, "key", "value");
+        String anotherValueAddedToCache = new String("anotherValue");
+        String anotherValueNotAddedToCache = new String("anotherValue");
+        assertEquals(anotherValueAddedToCache, anotherValueNotAddedToCache);
+        assertNotSame(anotherValueAddedToCache, anotherValueNotAddedToCache);
+        String cachedValue = cache.putIfAbsentAndGet("anotherKey", anotherValueAddedToCache);
+        assertSame(cachedValue, anotherValueAddedToCache);
+        cachedValue = cache.putIfAbsentAndGet("anotherKey", anotherValueNotAddedToCache);
+        assertNotSame(cachedValue, anotherValueNotAddedToCache);
+        assertSame(cachedValue, anotherValueAddedToCache);
         cache.removeListener(gotListener);
         assertEquals("listener", wantedListener, gotListener);
     }