-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJvmVsZipFileEqualityEdgeCaseTests.java
51 lines (45 loc) · 1.93 KB
/
JvmVsZipFileEqualityEdgeCaseTests.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
package software.coley.lljzip;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import software.coley.lljzip.format.model.AbstractZipFileHeader;
import software.coley.lljzip.format.model.ZipArchive;
import software.coley.lljzip.format.read.JvmZipReader;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.zip.ZipFile;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Some edge case tests where {@link JvmZipReader} needs to match a few quirky cases from {@link ZipFile}.
*
* @author Matt Coley
*/
public class JvmVsZipFileEqualityEdgeCaseTests {
@Disabled("Updating to JDK changes how ZipFile works, which no longer reads the test sample")
@ParameterizedTest
@ValueSource(strings = {
"resource-pack-trick-header-N-to-1-cen-to-loc-mapping.zip",
})
public void test(String name) {
Path path = Paths.get("src/test/resources/" + name);
try {
ZipArchive zipJvm = ZipIO.read(path, new JvmZipReader(false, false));
ZipArchive zipAdapting = ZipIO.readAdaptingIO(path);
int sizeDel = zipAdapting.getLocalFiles().size();
int sizeJvm = zipJvm.getLocalFiles().size();
Set<String> namesAdapting = zipAdapting.getLocalFiles().stream().map(AbstractZipFileHeader::getFileNameAsString).collect(Collectors.toCollection(TreeSet::new));
Set<String> namesJvm = zipJvm.getLocalFiles().stream().map(AbstractZipFileHeader::getFileNameAsString).collect(Collectors.toCollection(TreeSet::new));
Set<String> namesDifference = new TreeSet<>(namesAdapting);
namesDifference.removeAll(namesJvm);
// Both files should have the same number of local file headers
assertEquals(0, namesDifference.size());
assertEquals(sizeDel, sizeJvm);
} catch (Exception ex) {
fail(ex);
}
}
}