1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.common.junit48;
20
21 import org.apache.maven.surefire.api.testset.ResolvedTest;
22 import org.junit.runner.Description;
23 import org.junit.runner.manipulation.Filter;
24
25 final class RequestedTest extends Filter {
26 private static final String CLASS_FILE_EXTENSION = ".class";
27
28 private final ResolvedTest test;
29 private final boolean isPositiveFilter;
30
31 RequestedTest(ResolvedTest test, boolean isPositiveFilter) {
32 this.test = test;
33 this.isPositiveFilter = isPositiveFilter;
34 }
35
36 @Override
37 public boolean shouldRun(Description description) {
38 Class<?> realTestClass = description.getTestClass();
39 String methodName = description.getMethodName();
40 if (realTestClass == null && methodName == null) {
41 return true;
42 } else {
43 String testClass = classFile(realTestClass);
44 return isPositiveFilter
45 ? test.matchAsInclusive(testClass, methodName)
46 : !test.matchAsExclusive(testClass, methodName);
47 }
48 }
49
50 @Override
51 public String describe() {
52 String description = test.toString();
53 return description.isEmpty() ? "*" : description;
54 }
55
56 @Override
57 public boolean equals(Object o) {
58 return this == o || o != null && getClass() == o.getClass() && equals((RequestedTest) o);
59 }
60
61 private boolean equals(RequestedTest o) {
62 return isPositiveFilter == o.isPositiveFilter && test.equals(o.test);
63 }
64
65 @Override
66 public int hashCode() {
67 return test.hashCode();
68 }
69
70 private String classFile(Class<?> realTestClass) {
71 return realTestClass == null ? null : realTestClass.getName().replace('.', '/') + CLASS_FILE_EXTENSION;
72 }
73 }