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
33 RequestedTest( ResolvedTest test )
34 {
35 this.test = test;
36 }
37
38 @Override
39 public boolean shouldRun( Description description )
40 {
41 Class<?> realTestClass = description.getTestClass();
42 String methodName = description.getMethodName();
43 return realTestClass == null && methodName == null || test.shouldRun( classFile( realTestClass ), methodName );
44 }
45
46 @Override
47 public String describe()
48 {
49 final String classPattern = test.getTestClassPattern();
50 final String methodPattern = test.getTestMethodPattern();
51 String description = classPattern == null ? "" : classPattern;
52 if ( methodPattern != null )
53 {
54 description += "#" + methodPattern;
55 }
56 return description.length() == 0 ? "*" : description;
57 }
58
59 @Override
60 public boolean equals( Object o )
61 {
62 return this == o || o != null && getClass() == o.getClass() && test.equals( ( (RequestedTest) o ).test );
63 }
64
65 @Override
66 public int hashCode()
67 {
68 return test.hashCode();
69 }
70
71 private String classFile( Class<?> realTestClass )
72 {
73 return realTestClass.getName().replace( '.', '/' ) + CLASS_FILE_EXTENSION;
74 }
75 }