### Question:
ByteBufferInputStream extends InputStream { @Override public int read() throws IOException { if (bb.remaining() == 0) { return -1; } return bb.get() & 0xff; } ByteBufferInputStream(ByteBuffer bb); @Override int read(); @Override int available(); @Override int read(byte[] b, int off, int len); @Override int read(byte[] b); @Override long skip(long n); static void byteBuffer2Record(ByteBuffer bb, Record record);  }### Answer:
@Test public void testRead() throws Exception { for (int i = 0; i < DATA_BYTES.length; i++) { int b = in.read(); assertEquals(DATA_BYTES[i], (byte) b); } assertEquals(-1, in.read()); }
@Test public void testReadArrayOffsetLength() throws Exception { assertEquals(1, in.read(bs, 2, 1)); byte[] expected = new byte[]{(byte) 1, (byte) 2, DATA_BYTES[0], (byte) 4}; assertArrayEquals(expected, bs); }
@Test public void testReadArrayOffsetLength_LengthTooLarge() throws Exception { assertThrows(IndexOutOfBoundsException.class, () -> { in.read(bs, 2, 3); }); }
@Test public void testReadArrayOffsetLength_HitEndOfStream() throws Exception { for (int i = 0; i < DATA_BYTES.length - 1; i++) { in.read(); } assertEquals(1, in.read(bs, 2, 2)); byte[] expected = new byte[]{(byte) 1, (byte) 2, DATA_BYTES[DATA_BYTES.length - 1], (byte) 4}; assertArrayEquals(expected, bs); }
@Test public void testReadArrayOffsetLength_AtEndOfStream() throws Exception { for (int i = 0; i < DATA_BYTES.length; i++) { in.read(); } byte[] expected = Arrays.copyOf(bs, bs.length); assertEquals(-1, in.read(bs, 2, 2)); assertArrayEquals(expected, bs); }
@Test public void testReadArrayOffsetLength_0Length() throws Exception { byte[] expected = Arrays.copyOf(bs, bs.length); assertEquals(0, in.read(bs, 2, 0)); assertArrayEquals(expected, bs); }
@Test public void testReadArray() throws Exception { byte[] expected = Arrays.copyOf(DATA_BYTES, 4); assertEquals(4, in.read(bs)); assertArrayEquals(expected, bs); }