### Question:
DiskBasedCache implements Cache { static byte[] streamToBytes(CountingInputStream cis, long length) throws IOException { long maxLength = cis.bytesRemaining(); if (length < 0 || length > maxLength || (int) length != length) { throw new IOException("streamToBytes length=" + length + ", maxLength=" + maxLength); } byte[] bytes = new byte[(int) length]; new DataInputStream(cis).readFully(bytes); return bytes; } DiskBasedCache(File rootDirectory, int maxCacheSizeInBytes);  DiskBasedCache(File rootDirectory); @Override synchronized void clear(); @Override synchronized Entry get(String key); @Override synchronized void initialize(); @Override synchronized void invalidate(String key, boolean fullExpire); @Override synchronized void put(String key, Entry entry); @Override synchronized void remove(String key); File getFileForKey(String key);  }### Answer:
@Test public void testStreamToBytesNegativeLength() throws IOException { byte[] data = new byte[1]; CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(data), data.length); exception.expect(IOException.class); DiskBasedCache.streamToBytes(cis, -1); }
@Test public void testStreamToBytesExcessiveLength() throws IOException { byte[] data = new byte[1]; CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(data), data.length); exception.expect(IOException.class); DiskBasedCache.streamToBytes(cis, 2); }
@Test public void testStreamToBytesOverflow() throws IOException { byte[] data = new byte[0]; CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(data), 0x100000000L); exception.expect(IOException.class); DiskBasedCache.streamToBytes(cis, 0x100000000L); }