ContentCacheImpl implements ContentCache { @Override public boolean put(String contentUrl, ContentReader source) { File cacheFile = createCacheFile(); if (source.getSize() > 0L) { source.getContent(cacheFile); recordCacheEntries(contentUrl, cacheFile); return true; } return false; }  @Override boolean contains(String contentUrl); boolean contains(Key key); void putIntoLookup(Key key, String value); String getCacheFilePath(String contentUrl); String getContentUrl(File file); @Override ContentReader getReader(String contentUrl); @Override boolean put(String contentUrl, ContentReader source); @Override void remove(String contentUrl); void removeAll(); @Override void deleteFile(String url); @Override ContentWriter getWriter(final String url); static String createNewCacheFilePath(); void setMemoryStore(SimpleCache<Key, String> memoryStore); void setCacheRoot(File cacheRoot); @Override File getCacheRoot(); void processFiles(FileHandler handler);  }
@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: 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()); Mockito.verify(lookupTable).put(Key.forUrl(url), cacheFileArg.getValue().getAbsolutePath()); Mockito.verify(lookupTable).put(Key.forCacheFile(cacheFileArg.getValue().getAbsolutePath()), url); }