### Question:
ArrayInputStream implements BufferedInputStream { @Override public final int read(ByteBuffer dst) throws IOException { int available = this.buf.remaining(); int size = java.lang.Math.min(dst.remaining(), available); if (size == 0) { return -1; } ByteBuffer slice = this.buf.slice(); slice.limit(size); dst.put(slice); this.buf.position(this.buf.position() + size); return size; } ArrayInputStream(ByteBuffer buf); @Override final int read(ByteBuffer dst); @Override final ByteBuffer getReadBuffer(); @Override final void close(); @Override final boolean isOpen(); final ByteBuffer buf; }### Answer:
@Test public void testEmptyArray() throws java.io.IOException { ArrayInputStream stream = new ArrayInputStream(ByteBuffer.allocate(0)); ByteBuffer dst = ByteBuffer.allocate(10); Assert.assertEquals(stream.read(dst), -1); }
@Test public void testRequestMoreBytesThanArePresent() throws java.io.IOException { byte[] oneByte = new byte[]{42}; ArrayInputStream stream = new ArrayInputStream(ByteBuffer.wrap(oneByte)); ByteBuffer dst = ByteBuffer.allocate(10); Assert.assertEquals(stream.read(dst), 1); Assert.assertEquals(stream.read(dst), -1); }