1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.jar;
20
21 import java.io.File;
22 import java.io.UnsupportedEncodingException;
23 import java.net.URLDecoder;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.regex.Matcher;
28 import java.util.regex.Pattern;
29
30 import org.opentest4j.AssertionFailedError;
31
32 import static java.nio.charset.StandardCharsets.UTF_8;
33
34
35
36
37 public abstract class AbstractJarAnalyzerTestCase {
38
39 protected File getSampleJar(String filename) throws UnsupportedEncodingException {
40 String path = getClass().getResource("/jars/" + filename).getPath();
41
42 return new File(URLDecoder.decode(path, UTF_8.name()));
43 }
44
45 protected void assertNotContainsRegex(String msg, String regex, Collection<String> coll) {
46 List<String> failures = new ArrayList<>();
47 Pattern pat = Pattern.compile(regex);
48 for (String value : coll) {
49 Matcher mat = pat.matcher(value);
50 if (mat.find()) {
51 failures.add(value);
52 }
53 }
54
55 if (!failures.isEmpty()) {
56 StringBuilder sb = new StringBuilder();
57 sb.append(msg)
58 .append(" collection has illegal regex \"")
59 .append(regex)
60 .append("\"");
61 for (String failure : failures) {
62 sb.append("\n - \"").append(failure).append("\"");
63 }
64 throw new AssertionFailedError(sb.toString());
65 }
66 }
67 }