JarContentsManager { public byte[] getFileContents(File jar, String filePath) { requireFileExistence(jar); Objects.requireNonNull(filePath); try (JarFile jarFile = new JarFile(jar, false)) { return getJarEntryContents(jarFile, jarFile.getJarEntry(filePath)); } catch (IOException e) { throw new UncheckedIOException( String.format("Failed to retrieve file '%s' from jar '%s'", filePath, jar), e); } }  boolean containsPath(File jar, String filePath); byte[] getFileContents(File jar, String filePath); List<String> findFiles(File jar, String baseDirectoryName,
            String fileName); void copyFilesFromJarTrimmingBasePath(File jar,
            String jarDirectoryToCopyFrom, File outputDirectory,
            String... wildcardPathExclusions); void copyIncludedFilesFromJarTrimmingBasePath(File jar,
            String jarDirectoryToCopyFrom, File outputDirectory,
            String... wildcardPathInclusions);  }
@Test public void getFileContents_directoryInsteadOfJar() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(String.format( "Expect '%s' to be an existing file", testDirectory.getRoot())); jarContentsManager.getFileContents(testDirectory.getRoot(), "test"); }
@Test public void getFileContents_notAJarFile() throws IOException { File testFile = testDirectory.newFile("test"); expectedException.expect(UncheckedIOException.class); expectedException.expectMessage( String.format("Failed to retrieve file '%s' from jar '%s'", "test", testFile)); jarContentsManager.getFileContents(testFile, "test"); }
@Test public void getFileContents_nonExistingJarFile() { File test = new File("test"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( String.format("Expect '%s' to be an existing file", test)); jarContentsManager.getFileContents(test, "test"); }
@Test public void getFileContents_nonExistingFile() { byte[] fileContents = jarContentsManager.getFileContents(testJar, "blah"); assertNull("Expect to have non-empty file from jar", fileContents); }
@Test public void getFileContents_existingFile() { byte[] fileContents = jarContentsManager.getFileContents(testJar, "META-INF/resources/webjars/paper-button/2.0.0/bower.json"); assertNotNull("Expect to have non-empty file from jar", fileContents); assertTrue("Expect to have non-empty file from jar", fileContents.length > 0); }