1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.api.filter;
20
21 import java.util.Collections;
22 import java.util.HashSet;
23 import java.util.Set;
24
25 import org.apache.maven.surefire.api.util.ScannerFilter;
26 import org.apache.maven.surefire.shared.utils.io.SelectorUtils;
27
28
29
30
31
32 public class SpecificTestClassFilter implements ScannerFilter {
33
34 private static final char FS = System.getProperty("file.separator").charAt(0);
35
36 private static final String JAVA_CLASS_FILE_EXTENSION = ".class";
37
38 private Set<String> names;
39
40 public SpecificTestClassFilter(String[] classNames) {
41 if (classNames != null && classNames.length > 0) {
42 names = new HashSet<>();
43 Collections.addAll(names, classNames);
44 }
45 }
46
47 @Override
48 public boolean accept(Class testClass) {
49
50 boolean result = true;
51
52 if (names != null && !names.isEmpty()) {
53 String className = testClass.getName().replace('.', FS) + JAVA_CLASS_FILE_EXTENSION;
54
55 boolean found = false;
56 for (String pattern : names) {
57 if ('\\' == FS) {
58 pattern = pattern.replace('/', FS);
59 }
60
61
62
63 if (SelectorUtils.matchPath(pattern, className, true)) {
64 found = true;
65 break;
66 }
67 }
68
69 if (!found) {
70 result = false;
71 }
72 }
73
74 return result;
75 }
76 }