Merge branch '2.1.x'

Closes gh-18168
This commit is contained in:
Andy Wilkinson
2019-09-06 14:38:45 +01:00
4 changed files with 23 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ public abstract class TestJarCreator {
public static void createTestJar(File file, boolean unpackNested) throws Exception {
FileOutputStream fileOutputStream = new FileOutputStream(file);
try (JarOutputStream jarOutputStream = new JarOutputStream(fileOutputStream)) {
jarOutputStream.setComment("outer");
writeManifest(jarOutputStream, "j1");
writeEntry(jarOutputStream, "1.dat", 1);
writeEntry(jarOutputStream, "2.dat", 2);
@@ -88,6 +89,7 @@ public abstract class TestJarCreator {
private static byte[] getNestedJarData(boolean multiRelease) throws Exception {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JarOutputStream jarOutputStream = new JarOutputStream(byteArrayOutputStream);
jarOutputStream.setComment("nested");
writeManifest(jarOutputStream, "j2", multiRelease);
if (multiRelease) {
writeEntry(jarOutputStream, "multi-release.dat", 8);

View File

@@ -86,6 +86,7 @@ class JarFileTests {
void jdkJarFile() throws Exception {
// Sanity checks to see how the default jar file operates
java.util.jar.JarFile jarFile = new java.util.jar.JarFile(this.rootJarFile);
assertThat(jarFile.getComment()).isEqualTo("outer");
Enumeration<java.util.jar.JarEntry> entries = jarFile.entries();
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/");
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/MANIFEST.MF");
@@ -168,6 +169,11 @@ class JarFileTests {
assertThat(inputStream.read()).isEqualTo(-1);
}
@Test
void getComment() {
assertThat(this.jarFile.getComment()).isEqualTo("outer");
}
@Test
void getName() {
assertThat(this.jarFile.getName()).isEqualTo(this.rootJarFile.getPath());
@@ -252,6 +258,7 @@ class JarFileTests {
@Test
void getNestedJarFile() throws Exception {
try (JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))) {
assertThat(nestedJarFile.getComment()).isEqualTo("nested");
Enumeration<java.util.jar.JarEntry> entries = nestedJarFile.entries();
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/");
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/MANIFEST.MF");