Skip to content

Commit

Permalink
Us etry with resources to guarantee zip closure
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Dec 19, 2024
1 parent 0bc523b commit e332fc4
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,25 @@ protected String buildFinalTestSourceName(final String projectName) {
}

protected void assertJarContent(final File jarFile, final String[] expectedFiles) throws IOException {
ZipFile jar = new ZipFile(jarFile);
Enumeration<? extends ZipEntry> entries = jar.entries();
try (ZipFile jar = new ZipFile(jarFile)) {
Enumeration<? extends ZipEntry> entries = jar.entries();

if (expectedFiles.length == 0) {
assertFalse(entries.hasMoreElements(), "Jar file should not contain any entry");
} else {
assertTrue(entries.hasMoreElements());
if (expectedFiles.length == 0) {
assertFalse(entries.hasMoreElements(), "Jar file should not contain any entry");
} else {
assertTrue(entries.hasMoreElements());

Set<String> expected = new TreeSet<>(Arrays.asList(expectedFiles));
Set<String> expected = new TreeSet<>(Arrays.asList(expectedFiles));

while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();

assertTrue(expected.remove(entry.getName()), "Not expecting " + entry.getName() + " in " + jarFile);
}
assertTrue(expected.remove(entry.getName()), "Not expecting " + entry.getName() + " in " + jarFile);
}

assertTrue(expected.isEmpty(), "Missing entries " + expected + " in " + jarFile);
assertTrue(expected.isEmpty(), "Missing entries " + expected + " in " + jarFile);
}
}

jar.close();
}

protected File getTestTargetDir(String projectName) {
Expand Down

0 comments on commit e332fc4

Please sign in to comment.