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