public void testSetDuringDependencyNodeOperations() { CharacterObjectStorage storage = mock(CharacterObjectStorage.class); when(storage.load('*')).thenReturn(Storage.UNDEFINED, 42); CharacterIntCalculatable calculatable = mock(CharacterIntCalculatable.class); MxResource r = mock(MxResource.class); when(calculatable.calculate("123", '*')).thenThrow(new ResourceOccupied(r)); CharacterIntCache cache = (CharacterIntCache) Wrapping.getFactory( new Signature(char.class, Object.class), new Signature(char.class, int.class), false) .wrap("123", calculatable, storage, new MutableStatisticsImpl()); cache.setDependencyNode(DependencyTracker.DUMMY_NODE); assert cache.getStatistics().getHits() == 0; assert cache.getStatistics().getMisses() == 0; assert cache.getOrCreate('*') == 42; assert cache.getStatistics().getHits() == 1; assert cache.getStatistics().getMisses() == 0; verify(storage, atLeast(2)).load('*'); verifyNoMoreInteractions(storage); verify(calculatable).calculate("123", '*'); verifyNoMoreInteractions(calculatable); }
public void testClear() { CharacterObjectStorage storage = mock(CharacterObjectStorage.class); CharacterIntCache cache = (CharacterIntCache) Wrapping.getFactory( new Signature(char.class, Object.class), new Signature(char.class, int.class), false) .wrap("123", CALCULATABLE, storage, new MutableStatisticsImpl()); cache.setDependencyNode(DependencyTracker.DUMMY_NODE); cache.clear(); verify(storage).clear(); verifyNoMoreInteractions(storage); }
public void testResetStat() { CharacterObjectStorage storage = mock(CharacterObjectStorage.class); when(storage.load('*')).thenReturn(Storage.UNDEFINED); CharacterIntCache cache = (CharacterIntCache) Wrapping.getFactory( new Signature(char.class, Object.class), new Signature(char.class, int.class), false) .wrap("123", CALCULATABLE, storage, new MutableStatisticsImpl()); cache.setDependencyNode(DependencyTracker.DUMMY_NODE); assert cache.getStatistics().getHits() == 0; assert cache.getStatistics().getMisses() == 0; assert cache.getOrCreate('*') == 42; assert cache.getStatistics().getHits() == 0; assert cache.getStatistics().getMisses() == 1; cache.getStatistics().reset(); assert cache.getStatistics().getHits() == 0; assert cache.getStatistics().getMisses() == 0; verify(storage, atLeast(1)).load('*'); verify(storage).save('*', 42); verifyNoMoreInteractions(storage); }