1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.compress;
19
20 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
21 import static org.junit.jupiter.api.Assertions.assertTrue;
22
23 import java.io.BufferedReader;
24 import java.io.File;
25 import java.net.URISyntaxException;
26 import java.nio.file.Files;
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.stream.Stream;
30
31 import org.apache.commons.compress.archivers.ArchiveEntry;
32 import org.junit.jupiter.api.BeforeAll;
33 import org.junit.jupiter.params.ParameterizedTest;
34 import org.junit.jupiter.params.provider.Arguments;
35 import org.junit.jupiter.params.provider.MethodSource;
36
37
38
39
40
41
42
43
44 public class ArchiveReadTest extends AbstractTest {
45
46 private static final ClassLoader CLASSLOADER = ArchiveReadTest.class.getClassLoader();
47 private static final File ARCDIR;
48 private static final ArrayList<String> FILELIST = new ArrayList<>();
49
50 static {
51 try {
52 ARCDIR = new File(CLASSLOADER.getResource("archives").toURI());
53 } catch (final URISyntaxException e) {
54 throw new AssertionError(e);
55 }
56 }
57
58 public static Stream<Arguments> data() {
59 assertTrue(ARCDIR.exists());
60 final Collection<Arguments> params = new ArrayList<>();
61 for (final String fileName : ARCDIR.list((dir, name) -> !name.endsWith(".txt"))) {
62 params.add(Arguments.of(new File(ARCDIR, fileName)));
63 }
64 return params.stream();
65 }
66
67 @BeforeAll
68 public static void setUpFileList() throws Exception {
69 assertTrue(ARCDIR.exists());
70 final File listing = new File(ARCDIR, "files.txt");
71 assertTrue(listing.canRead(), "files.txt is readable");
72 try (BufferedReader br = new BufferedReader(Files.newBufferedReader(listing.toPath()))) {
73 String line;
74 while ((line = br.readLine()) != null) {
75 if (!line.startsWith("#")) {
76 FILELIST.add(line);
77 }
78 }
79 }
80 }
81
82
83 @Override
84 protected String getExpectedString(final ArchiveEntry entry) {
85 return entry.getSize() + " " + entry.getName();
86 }
87
88 @ParameterizedTest
89 @MethodSource("data")
90 public void testArchive(final File file) throws Exception {
91 @SuppressWarnings("unchecked")
92 final ArrayList<String> expected = (ArrayList<String>) FILELIST.clone();
93 assertDoesNotThrow(() -> checkArchiveContent(file, expected), "Problem checking " + file);
94 }
95 }