Example #1
0
 @Test
 public void assertThatPutPutsSomething() {
   long key = 5;
   Entity entity = new Entity(key, 10);
   cache.put(entity);
   assertEquals(entity, cache.get(key));
 }
Example #2
0
 @Test
 public void assertThatRemoveRemovesSomething() {
   long key = 5;
   Entity entity = new Entity(key, 10);
   cache.put(entity);
   assertEquals(entity, cache.get(key));
   cache.remove(key);
   assertEquals(null, cache.get(key));
 }
Example #3
0
 @Test
 public void assertThatRemoveKeepsCorrectSize() {
   final int size = 10;
   SneakyEntity entity =
       new SneakyEntity(0l, size) {
         @Override
         void doThisBadStuffInSizeCall() {
           // when AAC.remove asks the object for size this will emulate a cache.updateSize(
           // oldObj, size, size + 1 )
           updateSize(size + 1);
           cache.updateSize(this, size + 1);
         }
       };
   cache.put(entity); // will increase internal size to 11 and update cache
   entity.updateSize(size); // will reset entity size to 10
   cache.remove(entity.getId());
   assertEquals(0, cache.size());
 }
Example #4
0
 @Test
 public void assertThatPutKeepsCorrectSize() {
   final int size = 10;
   SneakyEntity oldEntity =
       new SneakyEntity(0l, size) {
         @Override
         void doThisBadStuffInSizeCall() {
           // when AAC.put asks the old object for size this will emulate a cache.updateSize(
           // oldObj, size, size + 1 )
           updateSize(size + 1);
           cache.updateSize(this, size + 1);
         }
       };
   cache.put(oldEntity); // will increase internal size to 11 and update cache
   oldEntity.updateSize(size); // will reset entity size to 10
   Entity newEntity = new Entity(0l, 11);
   cache.put(newEntity); // will increase oldEntity size + 1 when cache.put asks for it
   assertEquals(11, cache.size());
 }
Example #5
0
 @Test(expected = IndexOutOfBoundsException.class)
 public void assertPutCanHandleWrongId() {
   Entity entity = new Entity(-1l, 1);
   cache.put(entity);
 }
Example #6
0
 @Test(expected = NullPointerException.class)
 public void assertNullPutTriggersNPE() {
   cache.put(null);
 }
Example #7
0
 @Test(expected = IndexOutOfBoundsException.class)
 public void assertRemoveCanHandleWrongId() {
   cache.remove(-1l);
 }
Example #8
0
 @Test(expected = IndexOutOfBoundsException.class)
 public void assertGetCanHandleWrongId() {
   cache.get(-1l);
 }