示例#1
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());
 }
示例#2
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());
 }