JarContentsManager { public boolean containsPath(File jar, String filePath) { requireFileExistence(jar); Objects.requireNonNull(filePath); try (JarFile jarFile = new JarFile(jar, false)) { boolean containsEntry = jarFile.getJarEntry(filePath) != null; if (!containsEntry) { containsEntry = jarFile.stream().anyMatch( entry -> entry.getName().startsWith(filePath)); } return containsEntry; } 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 containsPath_directoryInsteadOfJar() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(String.format( "Expect '%s' to be an existing file", testDirectory.getRoot())); jarContentsManager.containsPath(testDirectory.getRoot(), "test"); }
@Test public void containsPath_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.containsPath(testFile, "test"); }
@Test public void containsPath_nonExistingJarFile() { File test = new File("test"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( String.format("Expect '%s' to be an existing file", test)); jarContentsManager.containsPath(test, "test"); }
@Test public void containsPath_nonExistingPath() { String nonExistingPath = "should not exist"; assertFalse( String.format("Test jar '%s' should not contain path '%s'", testJar, nonExistingPath), jarContentsManager.containsPath(testJar, nonExistingPath)); }
@Test public void containsPath_existingFile() { String existingPath = "META-INF/resources/webjars/"; assertTrue( String.format("Test jar '%s' should contain path '%s'", testJar, existingPath), jarContentsManager.containsPath(testJar, existingPath)); }
@Test public void containsPath_missingDirectoryStructure_scansForMatch() { String existingPathLocal = "META-INF/resources/webjars/"; File testJarLocal = TestUtils.getTestJar("test-jar-issue-6241.jar"); assertTrue( String.format("Test jar '%s' should contain path '%s'", testJar, existingPathLocal), jarContentsManager.containsPath(testJarLocal, existingPathLocal)); }