### Question:
ZipEntryInputStream extends InputStream { @Override public int read() throws IOException { return zipInputStream.read(); } ZipEntryInputStream(ZipInputStream zipInputStream); @Override int available(); @Override void close(); @Override void mark(int readlimit); @Override boolean markSupported(); @Override int read(); @Override int read(byte[] b); @Override int read(byte[] b, int off, int len); @Override void reset(); @Override long skip(long n);  }### Answer:
@Test public void readShouldDelegateToZipInputStreamRead() throws IOException { Mockito.doReturn(7).when(zipInputStream).read(); int result = zipEntryInputStream.read(); Assert.assertEquals(7, result); Mockito.verify(zipInputStream, Mockito.times(1)).read(); Mockito.verifyNoMoreInteractions(zipInputStream); }
@Test public void readShouldPassOnExceptionThrownByZipInputStreamRead() throws IOException { IOException ioException = new IOException("Some ZipInputStream exception"); Mockito.doThrow(ioException).when(zipInputStream).read(); try { zipEntryInputStream.read(); Assert.fail("Should not reach here"); } catch (IOException exception) { Assert.assertEquals(ioException.getMessage(), exception.getMessage()); } Mockito.verify(zipInputStream, Mockito.times(1)).read(); Mockito.verifyNoMoreInteractions(zipInputStream); }
@Test public void readWithArrayShouldDelegateToZipInputStreamReadWithArray() throws IOException { Mockito.doReturn(7).when(zipInputStream).read(Mockito.any(byte[].class)); byte[] arrayOfBytes = new byte[32]; int result = zipEntryInputStream.read(arrayOfBytes); Assert.assertEquals(7, result); Mockito.verify(zipInputStream, Mockito.times(1)).read(arrayOfBytes); Mockito.verifyNoMoreInteractions(zipInputStream); }
@Test public void readWithArrayShouldPassOnExceptionThrownByZipInputStreamReadWithArray() throws IOException { IOException ioException = new IOException("Some ZipInputStream exception"); Mockito.doThrow(ioException).when(zipInputStream).read(Mockito.any(byte[].class)); byte[] arrayOfBytes = new byte[32]; try { zipEntryInputStream.read(arrayOfBytes); Assert.fail("Should not reach here"); } catch (IOException exception) { Assert.assertEquals(ioException.getMessage(), exception.getMessage()); } Mockito.verify(zipInputStream, Mockito.times(1)).read(arrayOfBytes); Mockito.verifyNoMoreInteractions(zipInputStream); }
@Test public void readWithArrayAndBoundsShouldDelegateToZipInputStreamReadWithArrayAndBounds() throws IOException { Mockito.doReturn(7).when(zipInputStream).read(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt()); byte[] arrayOfBytes = new byte[32]; int result = zipEntryInputStream.read(arrayOfBytes, 3, 9); Assert.assertEquals(7, result); Mockito.verify(zipInputStream, Mockito.times(1)).read(arrayOfBytes, 3, 9); Mockito.verifyNoMoreInteractions(zipInputStream); }
@Test public void readWithArrayAndBoundsShouldPassOnExceptionThrownByZipInputStreamReadWithArrayAndBounds() throws IOException { IOException ioException = new IOException("Some ZipInputStream exception"); Mockito.doThrow(ioException).when(zipInputStream).read(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt()); byte[] arrayOfBytes = new byte[32]; try { zipEntryInputStream.read(arrayOfBytes, 3, 9); Assert.fail("Should not reach here"); } catch (IOException exception) { Assert.assertEquals(ioException.getMessage(), exception.getMessage()); } Mockito.verify(zipInputStream, Mockito.times(1)).read(arrayOfBytes, 3, 9); Mockito.verifyNoMoreInteractions(zipInputStream); }