GzipCompressionService implements CompressionService { @Override public ByteArrayOutputStream compress(final InputStream inputStream) { InputStream source = inputStream; ByteArrayOutputStream baos = outputStreamFactory.createByteArrayOutputStream(); try { GZIPOutputStream gout = gzipOutputStreamFactory.createOutputStream(baos); IOUtils.copy(source, gout); gout.finish(); gout.close(); } catch (IOException e) { throw new SystemException("Could not gzip message body!", e); } return baos; }  @Override ByteArrayOutputStream compress(final InputStream inputStream); @Override ByteArrayOutputStream decompress(final InputStream inputStream);  }
@Test public void testCompressShouldReturnABtyeArrayOutputStream() throws IOException { given(source.read((byte[]) Mockito.any())).willReturn(-1); ByteArrayOutputStream actual = underTest.compress(source); assertEquals(actual, baos); }
@Test public void testCompressShouldCallFinish() throws IOException { given(source.read((byte[]) Mockito.any())).willReturn(-1); underTest.compress(source); verify(gzipOutputStream).finish(); }
@Test public void testCompressShouldCallClose() throws IOException { given(source.read((byte[]) Mockito.any())).willReturn(-1); underTest.compress(source); verify(gzipOutputStream).close(); }
@Test(expectedExceptions = SystemException.class) public void testCompressShouldThrowSystemExceptionWhenIOExceptionIsCatched() throws IOException { given(source.read((byte[]) Mockito.any())).willThrow(new IOException()); underTest.compress(source); }