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