@Test public void testNullValue() throws Exception { // mocks have their methods returning null by default PersistentCacheLoader<byte[]> c = mock(PersistentCacheLoader.class); assertThat(cache.get(URI, c)).isNull(); verify(c).get(); assertCacheHit(false); }
@Test public void errorSave() throws IOException { when(cache.getDirectory()).thenReturn(tmp.getRoot().toPath().resolve("unexistent_folder")); cacheStatus = new DefaultProjectCacheStatus(cache); exception.expect(IllegalStateException.class); exception.expectMessage("Failed to write cache sync status"); cacheStatus.save(); }
public WSLoader provide( AnalysisProperties props, AnalysisMode mode, PersistentCache cache, ServerClient client) { if (wsLoader == null) { // recreate cache directory if needed for this analysis cache.reconfigure(); wsLoader = new WSLoader(isCacheEnabled(props.properties(), mode.isPreview()), cache, client); wsLoader.setStrategy(getStrategy(mode)); } return wsLoader; }
@Test public void testReconfigure() throws Exception { cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, mock(Logger.class)); assertCacheHit(false); assertCacheHit(true); File root = tmp.getRoot(); FileUtils.deleteQuietly(root); // should re-create cache directory and start using the cache cache.reconfigure(); assertThat(root).exists(); assertCacheHit(false); assertCacheHit(true); }
@Before public void setUp() { when(cache.getDirectory()).thenReturn(tmp.getRoot().toPath()); cacheStatus = new DefaultProjectCacheStatus(cache); }
@Test public void testClean() throws Exception { assertCacheHit(false); cache.clear(); assertCacheHit(false); }
@Test public void testNullLoader() throws Exception { assertThat(cache.get(URI, null)).isNull(); assertCacheHit(false); }
/** * WSCache should be transparent regarding exceptions: if an exception is thrown by the value * loader, it should pass through the cache to the original caller using the cache. * * @throws Exception */ @Test(expected = ArithmeticException.class) public void testExceptions() throws Exception { PersistentCacheLoader<byte[]> c = mock(PersistentCacheLoader.class); when(c.get()).thenThrow(ArithmeticException.class); cache.get(URI, c); }
private void assertCacheHit(boolean hit) throws Exception { CacheFillerString c = new CacheFillerString(); assertThat(cache.getString(URI, c)).isEqualTo(VALUE); assertThat(c.wasCalled).isEqualTo(!hit); }