-
Notifications
You must be signed in to change notification settings - Fork 8
/
JarInJarTests.java
59 lines (53 loc) · 2.01 KB
/
JarInJarTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package software.coley.lljzip;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import software.coley.lljzip.format.model.ZipArchive;
import software.coley.lljzip.format.transform.CentralAdoptingMapper;
import software.coley.lljzip.format.transform.IdentityZipPartMapper;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.fail;
import static software.coley.lljzip.JarInJarUtils.handleJar;
/**
* Similar to {@link DataDescriptorTests} but just checking for general handling of jar-in-jar embeddings.
*
* @author Matt Coley
*/
@SuppressWarnings("resource")
public class JarInJarTests {
@ParameterizedTest
@ValueSource(strings = {
"hello-copyjar-at-head.jar",
"hello-copyjar-at-tail.jar",
"hello-jar-in-in-jar-in-jar-in-jar-in-jar.jar",
"jar-in-jar-with-data-descriptor.jar",
})
public void test(String name) {
Path path = Paths.get("src/test/resources/" + name);
// The JVM strategy calculates file data ranges by mapping from the start
// of the current expected data offset of a local file header, to the start of
// the next local file header.
assertDoesNotThrow(() -> handleJar(() -> {
try {
return ZipIO.readJvm(path);
} catch (IOException ex) {
fail(ex);
return null;
}
}), "Failed to read with read(jvm)");
// The standard strategy calculates file data ranges by using the compressed size.
// The value is assumed to be correct. We'll want to use the authoritative values from
// the central directory file header though. The local sizes can be bogus.
assertDoesNotThrow(() -> handleJar(() -> {
try {
ZipArchive archive = ZipIO.readStandard(path);
return archive.withMapping(new CentralAdoptingMapper(new IdentityZipPartMapper()));
} catch (IOException ex) {
fail(ex);
return null;
}
}), "Failed to read with read(standard) + mapping(central-adoption)");
}
}