CompressedContentExtractor extends ComponentSupport { @Nullable public InputStream extractFile(final InputStream projectAsStream, final String fileName) { return extract(projectAsStream, fileName, this::fetchFileAsStream); }  @Nullable InputStream extractFile(final InputStream projectAsStream, final String fileName); boolean fileExists(final Payload payload, final String path, final String fileName);  }
@Test public void canExtractFile() throws Exception { InputStream project = getClass().getResourceAsStream(SONATYPE_ZIP); InputStream goMod = getClass().getResourceAsStream(GO_MOD); InputStream result = underTest.extractFile(project, GO_MOD); String goModFromProject = new ByteSource() { @Override public InputStream openStream() { return result; } }.asCharSource(Charsets.UTF_8).read(); String goModAsString = new ByteSource() { @Override public InputStream openStream() { return goMod; } }.asCharSource(Charsets.UTF_8).read(); assertThat(goModFromProject, is(equalTo(goModAsString))); }
@Test public void entryNotFound() { InputStream project = getClass().getResourceAsStream(SONATYPE_ZIP); InputStream response = underTest.extractFile(project, "does_not_exist.txt"); assertThat(response, is(nullValue())); }