Skip to content

Commit

Permalink
Add test for plain jars
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jul 16, 2020
1 parent cfa9f52 commit ef2cda2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions io/src/test/java/io/smallrye/common/io/jar/JarEntriesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class JarEntriesIT {
@Test
@DisabledOnJre(JRE.JAVA_8)
public void shouldUseMultiReleaseName() throws IOException {
File tmpFile = MultiReleaseJarGenerator.generateMultiReleaseJar();
File tmpFile = JarGenerator.generateMultiReleaseJar();
JarFile jarFile = JarFiles.create(tmpFile);
JarEntry jarEntry = jarFile.getJarEntry("foo.txt");
assertEquals("META-INF/versions/9/foo.txt", JarEntries.getRealName(jarEntry));
Expand All @@ -27,7 +27,7 @@ public void shouldUseMultiReleaseName() throws IOException {
@Test
@EnabledOnJre(JRE.JAVA_8)
public void shouldUseName() throws IOException {
File tmpFile = MultiReleaseJarGenerator.generateMultiReleaseJar();
File tmpFile = JarGenerator.generateMultiReleaseJar();
JarFile jarFile = JarFiles.create(tmpFile);
JarEntry jarEntry = jarFile.getJarEntry("foo.txt");
assertEquals("foo.txt", JarEntries.getRealName(jarEntry));
Expand Down
11 changes: 10 additions & 1 deletion io/src/test/java/io/smallrye/common/io/jar/JarFilesTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.smallrye.common.io.jar;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
Expand All @@ -10,10 +11,18 @@

public class JarFilesTest {

@Test
public void shouldReadPlainJars() throws IOException {
File tmpFile = JarGenerator.generatePlainJar();
JarFile jarFile = JarFiles.create(tmpFile);
assertFalse(JarFiles.isMultiRelease(jarFile));
}

@Test
public void shouldReadMultiReleaseJars() throws IOException {
File tmpFile = MultiReleaseJarGenerator.generateMultiReleaseJar();
File tmpFile = JarGenerator.generateMultiReleaseJar();
JarFile jarFile = JarFiles.create(tmpFile);
assertTrue(JarFiles.isMultiRelease(jarFile));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;

public class MultiReleaseJarGenerator {
public class JarGenerator {
public static File generatePlainJar() throws IOException {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
.addAsResource(new StringAsset("Original"), "foo.txt");
File tmpFile = File.createTempFile("tmp", ".tmp");
jar.as(ZipExporter.class).exportTo(tmpFile, true);
return tmpFile;
}

public static File generateMultiReleaseJar() throws IOException {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
.addAsManifestResource(new StringAsset("Multi-Release: true\n"), "MANIFEST.MF")
Expand Down

0 comments on commit ef2cda2

Please sign in to comment.