### Question:
StrictInputStream extends InputStream { public byte[] readBytes(int len) throws IOException { byte[] bytes = new byte[len]; int totalRead = 0; while (totalRead < len) { int r = inputStream.read(bytes, totalRead, len - totalRead); if (r == -1) { throw new EOFException(); } totalRead += r; } return bytes; } StrictInputStream(InputStream inputStream); byte[] readBytes(int len); @Override int read(); @Override int available();  }### Answer:
@Test public void should_read_into_byte_array() throws IOException { StrictInputStream in = new StrictInputStream(new ByteArrayInputStream(new byte[]{1, 2, 3, 4})); assertArrayEquals(new byte[]{1, 2, 3}, in.readBytes(3)); assertThatThrownBy(() -> in.readBytes(2)).isExactlyInstanceOf(EOFException.class); }
@Test public void should_thrown_eof_when_readBytes() throws IOException { InputStream eofIn = new InputStream() { @Override public int read() throws IOException { return -1; } }; StrictInputStream in = new StrictInputStream(eofIn); assertThatThrownBy(() -> in.readBytes(2)).isExactlyInstanceOf(EOFException.class); }