mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +01:00
modify cache api to match the one from shiro
This commit is contained in:
@@ -30,17 +30,21 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.cache;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
@@ -107,6 +111,21 @@ public abstract class CacheTestBase
|
||||
assertFalse(cache.contains("test-2"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testOverride()
|
||||
{
|
||||
cache.put("test", "test123");
|
||||
|
||||
String previous = cache.put("test", "test456");
|
||||
|
||||
assertEquals("test123", previous);
|
||||
assertEquals("test456", cache.get("test"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -127,7 +146,10 @@ public abstract class CacheTestBase
|
||||
{
|
||||
cache.put("test", "test123");
|
||||
assertEquals("test123", cache.get("test"));
|
||||
cache.remove("test");
|
||||
|
||||
String previous = cache.remove("test");
|
||||
|
||||
assertEquals("test123", previous);
|
||||
assertNull(cache.get("test"));
|
||||
}
|
||||
|
||||
@@ -139,10 +161,11 @@ public abstract class CacheTestBase
|
||||
public void testRemoveAll()
|
||||
{
|
||||
cache.put("test-1", "test123");
|
||||
cache.put("test-2", "test123");
|
||||
cache.put("test-2", "test456");
|
||||
cache.put("a-1", "test123");
|
||||
cache.put("a-2", "test123");
|
||||
cache.removeAll(new Predicate<String>()
|
||||
|
||||
Iterable<String> previous = cache.removeAll(new Predicate<String>()
|
||||
{
|
||||
@Override
|
||||
public boolean apply(String item)
|
||||
@@ -150,12 +173,32 @@ public abstract class CacheTestBase
|
||||
return item.startsWith("test");
|
||||
}
|
||||
});
|
||||
|
||||
assertThat(previous, containsInAnyOrder("test123", "test456"));
|
||||
assertNull(cache.get("test-1"));
|
||||
assertNull(cache.get("test-2"));
|
||||
assertNotNull(cache.get("a-1"));
|
||||
assertNotNull(cache.get("a-2"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testSize()
|
||||
{
|
||||
assertEquals(0, cache.size());
|
||||
cache.put("test", "test123");
|
||||
assertEquals(1, cache.size());
|
||||
cache.put("test-1", "test123");
|
||||
assertEquals(2, cache.size());
|
||||
cache.remove("test");
|
||||
assertEquals(1, cache.size());
|
||||
cache.clear();
|
||||
assertEquals(0, cache.size());
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
Reference in New Issue
Block a user