### Question:
ReadableStreamChannelInputStream extends InputStream { @Override public int read() throws IOException { int data = -1; if (loadData()) { data = currentChunk.get() & 0xFF; reportBytesRead(1); } return data; } ReadableStreamChannelInputStream(ReadableStreamChannel readableStreamChannel); @Override int available(); @Override int read(); @Override int read(byte b[], int off, int len); @Override void close();  }### Answer:
@Test public void readErrorCasesTest() throws IOException { byte[] in = new byte[1024]; new Random().nextBytes(in); ReadableStreamChannel channel = new ByteBufferReadableStreamChannel(ByteBuffer.wrap(in)); InputStream dstInputStream = new ReadableStreamChannelInputStream(channel); try { dstInputStream.read(null, 0, in.length); fail("The read should have failed"); } catch (NullPointerException e) { } byte[] out = new byte[in.length]; try { dstInputStream.read(out, -1, out.length); fail("The read should have failed"); } catch (IndexOutOfBoundsException e) { } try { dstInputStream.read(out, 0, -1); fail("The read should have failed"); } catch (IndexOutOfBoundsException e) { } try { dstInputStream.read(out, 0, out.length + 1); fail("The read should have failed"); } catch (IndexOutOfBoundsException e) { } assertEquals("Bytes read should have been 0 because passed len was 0", 0, dstInputStream.read(out, 0, 0)); }
@Test public void incompleteReadsTest() throws IOException { String exceptionMsg = "@@randomMsg@@"; Exception exceptionToThrow = new Exception(exceptionMsg); ReadableStreamChannel channel = new IncompleteReadReadableStreamChannel(exceptionToThrow); InputStream inputStream = new ReadableStreamChannelInputStream(channel); try { inputStream.read(); fail("The read should have failed"); } catch (Exception e) { while (e.getCause() != null) { e = (Exception) e.getCause(); } assertEquals("Exception messages do not match", exceptionMsg, e.getMessage()); } channel = new IncompleteReadReadableStreamChannel(null); inputStream = new ReadableStreamChannelInputStream(channel); try { inputStream.read(); fail("The read should have failed"); } catch (IllegalStateException e) { } }