1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.analysis.license;
20
21 import static org.junit.Assert.assertEquals;
22
23 import java.io.BufferedReader;
24 import java.io.File;
25
26 import org.apache.commons.io.IOUtils;
27 import org.apache.rat.analysis.IHeaderMatcher;
28 import org.apache.rat.api.Document;
29 import org.apache.rat.document.MockLocation;
30 import org.apache.rat.test.utils.Resources;
31 import org.junit.Assert;
32
33 class DirectoryScanner {
34
35 @SuppressWarnings("boxing")
36
37
38
39
40
41
42
43 public static void testFilesInDir(String directory, IHeaderMatcher matcher, boolean expected) throws Exception {
44 final File[] resourceFiles = Resources.getResourceFiles(directory);
45 if (resourceFiles.length == 0) {
46 Assert.fail("No files found under "+directory);
47 }
48 for(File f : resourceFiles) {
49 final Document subject = new MockLocation(f.toString());
50 BufferedReader br = null;
51 try {
52 boolean result = false;
53 br = Resources.getBufferedReader(f);
54 String line;
55 while(!result && (line = br.readLine()) != null) {
56 result = matcher.match(subject, line);
57 }
58 assertEquals(f.toString(), expected, result);
59 } finally {
60 matcher.reset();
61 IOUtils.closeQuietly(br);
62 }
63 }
64 }
65
66 }