IgDiskCache { public OptionalStream<EditorOutputStream> edit(String key) { validateKey(key); if (mMaxSizeInBytes == 0 || mMaxCount == 0 || FAKE_CACHE_DIRECTORY.equals(mDirectory)) { return OptionalStream.absent(); } else { Entry entry; synchronized (mDiskCacheLock) { entry = mLruEntries.get(key); } if (entry == null) { entry = new Entry(mDirectory, key); synchronized (mDiskCacheLock) { mLruEntries.put(key, entry); } } else if (entry.getCurrentEditorStream() != null) { throw new IllegalStateException( "Trying to edit a disk cache entry while another edit is in progress."); } mJournal.logDirtyFileUpdate(key); return getOutputStream(entry); } } IgDiskCache(File directory);  IgDiskCache(File directory, Executor serialExecutor);  IgDiskCache(File directory, long maxSizeInBytes);  IgDiskCache(File directory, long maxSizeInBytes, Executor serialExecutor);  IgDiskCache(File directory, long maxSizeInBytes, int maxCount);  IgDiskCache(File directory, long maxSizeInBytes, int maxCount, Executor serialExecutor); boolean has(String key); OptionalStream<SnapshotInputStream> get(String key); OptionalStream<EditorOutputStream> edit(String key); void remove(String key); void flush(); void close(); File getDirectory(); long getMaxSizeInBytes(); int getMaxCount(); void setMaxSizeInBytes(long maxSizeInBytes); long size(); int count(); final String getHitRateString();  }
@Test public void editSameEntry() throws Exception { try { mCache.edit("k1"); mCache.edit("k1"); fail(); } catch (IllegalStateException expected) { assertThat(expected.getMessage() .equals("Trying to edit a disk cache entry while another edit is in progress.")); } }
@SuppressLint("EmptyCatchBlock") @Test public void keyWithSpaceNotPermitted() throws Exception { try { mCache.edit("my key"); fail(); } catch (IllegalArgumentException expected) { } }
@SuppressLint("EmptyCatchBlock") @Test public void keyWithNewlineNotPermitted() throws Exception { try { mCache.edit("my\nkey"); fail(); } catch (IllegalArgumentException expected) { } }
@SuppressLint("EmptyCatchBlock") @Test public void keyWithCarriageReturnNotPermitted() throws Exception { try { mCache.edit("my\rkey"); fail(); } catch (IllegalArgumentException expected) { } }
@SuppressLint("EmptyCatchBlock") @Test public void nullKeyThrows() throws Exception { try { mCache.edit(null); fail(); } catch (NullPointerException expected) { } }