@Test public void putForZeroLengthFile() { ContentReader contentReader = Mockito.mock(ContentReader.class); Mockito.when(contentReader.getSize()).thenReturn(0L); boolean putResult = contentCache.put("", contentReader); assertFalse("Zero length files should not be cached", putResult); }
@Test public void putForNonEmptyFile() { ContentReader contentReader = Mockito.mock(ContentReader.class); Mockito.when(contentReader.getSize()).thenReturn(999000L); final String url = "store://some/url.bin"; boolean putResult = contentCache.put(url, contentReader); assertTrue("Non-empty files should be cached", putResult); ArgumentCaptor<File> cacheFileArg = ArgumentCaptor.forClass(File.class); Mockito.verify(contentReader).getContent(cacheFileArg.capture()); // Check cached item is recorded properly in ehcache Mockito.verify(lookupTable).put(Key.forUrl(url), cacheFileArg.getValue().getAbsolutePath()); Mockito.verify(lookupTable) .put(Key.forCacheFile(cacheFileArg.getValue().getAbsolutePath()), url); }