Close FileInputStreams in RepackagerTests

This commit is contained in:
Andy Wilkinson 2020-01-17 20:04:31 +00:00
parent 04d6b21dfb
commit 408f17f821
1 changed files with 17 additions and 13 deletions

View File

@ -330,12 +330,14 @@ class RepackagerTests {
});
assertThat(hasEntry(file, "BOOT-INF/classpath.idx")).isTrue();
ZipUtil.unpack(file, new File(file.getParent()));
FileInputStream inputStream = new FileInputStream(new File(file.getParent() + "/BOOT-INF/classpath.idx"));
try (FileInputStream inputStream = new FileInputStream(
new File(file.getParent() + "/BOOT-INF/classpath.idx"))) {
String index = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);
String[] libraries = index.split("\\r?\\n");
assertThat(Arrays.asList(libraries)).contains("BOOT-INF/lib/" + libJarFile1.getName(),
"BOOT-INF/lib/" + libJarFile2.getName(), "BOOT-INF/lib/" + libJarFile3.getName());
}
}
@Test
void layeredLayout() throws Exception {
@ -364,7 +366,8 @@ class RepackagerTests {
});
assertThat(hasEntry(file, "BOOT-INF/classpath.idx")).isTrue();
ZipUtil.unpack(file, new File(file.getParent()));
FileInputStream inputStream = new FileInputStream(new File(file.getParent() + "/BOOT-INF/classpath.idx"));
try (FileInputStream inputStream = new FileInputStream(
new File(file.getParent() + "/BOOT-INF/classpath.idx"))) {
String index = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);
String[] libraries = index.split("\\r?\\n");
List<String> expected = new ArrayList<>();
@ -373,6 +376,7 @@ class RepackagerTests {
expected.add("BOOT-INF/layers/0003/lib/" + libJarFile3.getName());
assertThat(Arrays.asList(libraries)).containsExactly(expected.toArray(new String[0]));
}
}
@Test
void duplicateLibraries() throws Exception {