AbstractFilePublishHelper implements IPublishHelper<Event> { static OutputStream createCompressedStreamAsNecessary( OutputStream outputStream, boolean compressEnabled, boolean verbose) throws IOException { Objects.requireNonNull(outputStream); if (compressEnabled) { if (verbose) { System.out.println("Content will be compressed."); } return new GZIPOutputStream(outputStream); } else { return outputStream; } } AbstractFilePublishHelper(boolean compressEnabled, boolean verbose); @Override void start(PublishContext context); @Override void publish(PublishContext context, int sequence, Event event); @Override void end(PublishContext context);  }
@Test public void testCreateCompressedStreamAsNecessary() { try (OutputStream os = new ByteArrayOutputStream()) { try (OutputStream testStream = AbstractFilePublishHelper.createCompressedStreamAsNecessary(os, false, false)) { Assert.assertEquals(ByteArrayOutputStream.class, testStream.getClass()); } try (OutputStream testStream = AbstractFilePublishHelper.createCompressedStreamAsNecessary(os, true, false)) { Assert.assertEquals(GZIPOutputStream.class, testStream.getClass()); } } catch (IOException e) { Assert.fail( String.format("Fail due to exception: %s", e.getMessage())); } }