Skip to content

Commit 832d8e3

Browse files
committed
Add test for JvmClassDirectoryMapper
1 parent 990ad92 commit 832d8e3

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/test/java/software/coley/lljzip/PatchingTests.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package software.coley.lljzip;
22

3+
import org.junit.jupiter.api.Test;
34
import org.junit.jupiter.params.ParameterizedTest;
45
import org.junit.jupiter.params.provider.ValueSource;
6+
import software.coley.lljzip.format.model.LocalFileHeader;
57
import software.coley.lljzip.format.model.ZipArchive;
8+
import software.coley.lljzip.format.transform.IdentityZipPartMapper;
9+
import software.coley.lljzip.format.transform.JvmClassDirectoryMapper;
610
import software.coley.lljzip.format.write.ZipOutputStreamZipWriter;
711

812
import java.io.ByteArrayInputStream;
@@ -14,7 +18,7 @@
1418
import java.util.zip.ZipEntry;
1519
import java.util.zip.ZipInputStream;
1620

17-
import static org.junit.jupiter.api.Assertions.fail;
21+
import static org.junit.jupiter.api.Assertions.*;
1822

1923
/**
2024
* Tests for patching the <i>"trick"</i> jars, and making them compatible with standard Java ZIP apis.
@@ -43,7 +47,7 @@ public void testTrickJarPatched(String name) {
4347
if (entry.getName().contains("Hello.class")) {
4448
byte[] buffer = new byte[1024];
4549
baos = new ByteArrayOutputStream();
46-
int len = 0;
50+
int len;
4751
while ((len = zis.read(buffer)) > 0)
4852
baos.write(buffer, 0, len);
4953

@@ -67,7 +71,7 @@ public void testTrickJarPatched(String name) {
6771
if (entry.getName().contains("Hello.class")) {
6872
byte[] buffer = new byte[1024];
6973
baos = new ByteArrayOutputStream();
70-
int len = 0;
74+
int len;
7175
while ((len = zis.read(buffer)) > 0)
7276
baos.write(buffer, 0, len);
7377

@@ -81,4 +85,14 @@ public void testTrickJarPatched(String name) {
8185
fail(ex);
8286
}
8387
}
88+
89+
@Test
90+
@SuppressWarnings("resource")
91+
public void testTrailingSlashTransform() {
92+
// The 'JvmClassDirectoryMapper' maps 'Name.class/' paths to 'Name.class'
93+
Path path = Paths.get("src/test/resources/hello-secret-trailing-slash.jar");
94+
ZipArchive zip = assertDoesNotThrow(() -> ZipIO.readStandard(path)
95+
.withMapping(new JvmClassDirectoryMapper(new IdentityZipPartMapper())));
96+
assertNotNull(zip.getLocalFileByName("Hello.class"), "Trailing slash was not patched");
97+
}
8498
}

0 commit comments

Comments
 (0)