### Question:
ByteArrayInputStream extends InputStream { @Override public void close() { } ByteArrayInputStream(byte[] buf);  ByteArrayInputStream(ByteArrayRange byteArrayRange);  ByteArrayInputStream(byte[] buf, int offset, int length); @Override void close(); @Override int read(); @Override int read(byte[] b, int offset, int length);  }### Answer:
@Test public void testReadFully() { byte[] data = new byte[3]; data[0] = 1; data[1] = 2; data[2] = 3; ByteArrayInputStream bais = new ByteArrayInputStream(data); byte[] readData = new byte[3]; bais.readFully(readData); bais.close(); assertArrayEquals(data, readData); }
@Test public void testCoppy() { byte[] data = new byte[3]; data[0] = 1; data[1] = 2; data[2] = 3; ByteArrayInputStream sut = new ByteArrayInputStream(data); ByteArrayOutputStream coppy = new ByteArrayOutputStream(); sut.copyTo(coppy); byte[] coppiedData = coppy.getByteArray().toByteArray(); sut.close(); assertEquals(data.length, coppiedData.length); assertArrayEquals(data, coppiedData); }
@Test public void testOffsetRead() { byte[] data = new byte[3]; data[0] = 1; data[1] = 2; data[2] = 3; ByteArrayInputStream bais = new ByteArrayInputStream(data); byte[] readData = new byte[4]; bais.readFully(readData, 1, 4); bais.close(); assertEquals(0, readData[0]); assertEquals(data[0], readData[1]); }
@Test public void testCoppyToByteArray(){ byte[] data = new byte[3]; data[0] = 1; data[1] = 2; data[2] = 3; ByteArrayInputStream bais = new ByteArrayInputStream(data); byte[] readData = bais.copyToByteArray().toByteArray(); bais.close(); assertEquals(data[0], readData[0]); assertEquals(data[1], readData[1]); }