@Test public void shouldAllowRawPutAndGet() { final Cache cache = newCache(); Object obj1 = new SerializableObj(); cache.set("Key", obj1); MatcherAssert.assertThat(cache.get("Key"), Matchers.is(obj1)); }
@Test public void shouldAllowCacheablePutAndGet() { final Cache cache = newCache(); final CacheableObj cacheable = new CacheableObj(); cache.set(cacheable); MatcherAssert.assertThat(cache.get(cacheable.getKey()), Matchers.is(cacheable.getInstance())); }
@Test public void shouldOverwriteValueOnRawPut() { final Cache cache = newCache(); Object obj1 = new SerializableObj(); Object obj2 = new SerializableObj(); cache.set("Key", obj1); cache.set("Key", obj2); MatcherAssert.assertThat(cache.get("Key"), Matchers.is(obj2)); }
@Test(expected = NullPointerException.class) public void shouldNotAllowCacheablePutWithNullCacheableCacheKey() { final Cache cache = newCache(); final Cacheable cacheable = new Cacheable() { public CacheKey getKey() { return null; } public Object getInstance() { return new Object(); } }; cache.set(cacheable); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowCacheablePutWithNonSerializableValue() { final Cache cache = newCache(); final Cacheable<Object> cacheable = new Cacheable() { public CacheKey getKey() { return new CacheKey<Object>(Object.class); } public Object getInstance() { return new Object(); } }; cache.set(cacheable); }
@Test(expected = NullPointerException.class) public void shouldNotAllowCacheablePutWithNullCacheable() { final Cache cache = newCache(); cache.set(null); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowPutWithNonSerializableValue() { final Cache cache = newCache(); Object obj1 = new Object(); cache.set("Key", obj1); }
@Test(expected = NullPointerException.class) public void shouldNotAllowPutWithNullValue() { final Cache cache = newCache(); cache.set("key", null); }
@Test(expected = NullPointerException.class) public void shouldNotAllowPutWithNullKey() { final Cache cache = newCache(); cache.set(null, new SerializableObj()); }