1 package org.apache.maven.surefire.common.junit4;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.junit.runner.Description;
23 import org.junit.runner.manipulation.Filter;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28
29
30
31
32
33 public final class MatchDescriptions
34 extends Filter
35 {
36 private final List<Filter> filters = new ArrayList<Filter>();
37
38 public MatchDescriptions( Iterable<Description> descriptions )
39 {
40 for ( Description description : descriptions )
41 {
42 filters.add( matchDescription( description ) );
43 }
44 }
45
46 @Override
47 public boolean shouldRun( Description description )
48 {
49 for ( Filter filter : filters )
50 {
51 if ( filter.shouldRun( description ) )
52 {
53 return true;
54 }
55 }
56 return false;
57 }
58
59 @Override
60 public String describe()
61 {
62 StringBuilder description = new StringBuilder( "Matching description " );
63 for ( int i = 0; i < filters.size(); i++ )
64 {
65 description.append( filters.get( i ).describe() );
66 if ( i != filters.size() - 1 )
67 {
68 description.append( " OR " );
69 }
70 }
71 return description.toString();
72 }
73
74 private static Filter matchDescription( final Description desiredDescription )
75 {
76 return new Filter()
77 {
78 @Override
79 public boolean shouldRun( Description description )
80 {
81 if ( description.isTest() )
82 {
83 return desiredDescription.equals( description );
84 }
85
86 for ( Description each : description.getChildren() )
87 {
88 if ( shouldRun( each ) )
89 {
90 return true;
91 }
92 }
93
94 return false;
95 }
96
97 @Override
98 public String describe()
99 {
100 return String.format( "Method %s", desiredDescription.getDisplayName() );
101 }
102 };
103 }
104 }