### Question:
CombinedInputStream extends InputStream { @Override public int read() throws IOException { while (currentStream != null) { int byteRead = currentStream.read(); if (byteRead != -1) { return lastByteRead = byteRead; } advanceStream(); } return lastByteRead = -1; } CombinedInputStream(@NonNull List<InputStream> inputStreams, boolean newLinePadding); @Override int read(); @Override int read(@NonNull byte buffer[], int offset, int length); @Override int available(); @Override void close();  }### Answer:
@Test public void testRead() throws IOException { assertThat(combinedInputStream.read()).isEqualTo(1); assertThat(combinedInputStream.read()).isEqualTo(2); assertThat(combinedInputStream.read()).isEqualTo(3); assertThat(combinedInputStream.read()).isEqualTo(4); assertThat(combinedInputStream.read()).isEqualTo('\n'); assertThat(combinedInputStream.read()).isEqualTo(5); assertThat(combinedInputStream.read()).isEqualTo(6); assertThat(combinedInputStream.read()).isEqualTo(-1); }
@Test public void testReadByteArray() throws IOException { byte[] buffer = new byte[10]; int byteCount = combinedInputStream.read(buffer); int bytesRead = byteCount; assertThat(Arrays.copyOfRange(buffer, 0, bytesRead)).isEqualTo(new byte[] {1, 2}); byteCount = combinedInputStream.read(buffer, bytesRead, buffer.length - bytesRead); bytesRead += byteCount; assertThat(Arrays.copyOfRange(buffer, 0, bytesRead)) .isEqualTo(new byte[] {1, 2, 3, 4, '\n'}); byteCount = combinedInputStream.read(buffer, bytesRead, buffer.length - bytesRead); bytesRead += byteCount; assertThat(Arrays.copyOfRange(buffer, 0, bytesRead)) .isEqualTo(new byte[] {1, 2, 3, 4, '\n', 5, 6}); byteCount = combinedInputStream.read(buffer, bytesRead, buffer.length - bytesRead); assertThat(byteCount).isEqualTo(-1); }
@Test public void testReadWithNewLinePadding() throws IOException { assertThat(paddedCombinedInputStream.read()).isEqualTo(1); assertThat(paddedCombinedInputStream.read()).isEqualTo(2); assertThat(paddedCombinedInputStream.read()).isEqualTo('\n'); assertThat(paddedCombinedInputStream.read()).isEqualTo(3); assertThat(paddedCombinedInputStream.read()).isEqualTo(4); assertThat(paddedCombinedInputStream.read()).isEqualTo('\n'); assertThat(paddedCombinedInputStream.read()).isEqualTo(5); assertThat(paddedCombinedInputStream.read()).isEqualTo(6); assertThat(paddedCombinedInputStream.read()).isEqualTo(-1); }
@Test public void testReadByteArrayWithNewLinePadding() throws IOException { byte[] buffer = new byte[10]; int byteCount = paddedCombinedInputStream.read(buffer); int bytesRead = byteCount; assertThat(Arrays.copyOfRange(buffer, 0, bytesRead)).isEqualTo(new byte[] {1, 2}); byteCount = paddedCombinedInputStream.read(buffer, bytesRead, buffer.length - bytesRead); bytesRead += byteCount; assertThat(Arrays.copyOfRange(buffer, 0, bytesRead)).isEqualTo(new byte[] {1, 2, '\n'}); byteCount = paddedCombinedInputStream.read(buffer, bytesRead, buffer.length - bytesRead); bytesRead += byteCount; assertThat(Arrays.copyOfRange(buffer, 0, bytesRead)) .isEqualTo(new byte[] {1, 2, '\n', 3, 4, '\n'}); byteCount = paddedCombinedInputStream.read(buffer, bytesRead, buffer.length - bytesRead); bytesRead += byteCount; assertThat(Arrays.copyOfRange(buffer, 0, bytesRead)) .isEqualTo(new byte[] {1, 2, '\n', 3, 4, '\n', 5, 6}); byteCount = paddedCombinedInputStream.read(buffer, bytesRead, buffer.length - bytesRead); assertThat(byteCount).isEqualTo(-1); }