@@ -27,7 +27,7 @@ public class HierarchicalRunRulesStatementBuilder implements MethodStatementBuil
27
27
public Statement createStatement (final TestClass testClass , final FrameworkMethod method , final Object target ,
28
28
final Statement next , final Description description , final RunNotifier notifier ) {
29
29
try {
30
- final TestRuleDefinitions testRules = new TestRuleDefinitions (hierarchyInstancesInAscendingOrder (target ));
30
+ final TestRuleDefinitions testRules = new TestRuleDefinitions (hierarchyOfTestsFromLowestToHighest (target ));
31
31
final List <MethodRule > methodRules = new LinkedList <MethodRule >();
32
32
33
33
@@ -45,62 +45,70 @@ public Statement createStatement(final TestClass testClass, final FrameworkMetho
45
45
statement = methodRule .apply (statement , method , instance );
46
46
}
47
47
if (testRules .hasSome ())
48
- statement = new RunRules (statement , testRules .getTestRulesDefinedForThisHieraryLevel (instance ), description );
48
+ statement = new RunRules (statement , testRules .getTestRulesDefinedForThisHierarchyLevel (instance ), description );
49
49
}
50
50
return statement ;
51
51
} catch (final IllegalAccessException e ) {
52
52
return new Fail (e );
53
53
}
54
54
}
55
55
56
- private List <Object > hierarchyInstancesInAscendingOrder (Object target ) throws IllegalAccessException {
56
+ private List <Object > hierarchyOfTestsFromLowestToHighest (Object target ) throws IllegalAccessException {
57
57
List <Object > result = new ArrayList <Object >();
58
58
for (Object instance = target ; instance != null ; instance = getEnclosingInstance (instance )) {
59
59
result .add (instance );
60
60
}
61
61
return result ;
62
62
}
63
63
64
- private class TestRuleWithInstance {
64
+ private class TestRuleInTestHierarchy {
65
65
private TestRule testRule ;
66
- private Object instance ;
66
+ private Object objectRepresentingHierarchy ;
67
67
68
- public TestRuleWithInstance (TestRule testRule , Object instance ) {
68
+ public TestRuleInTestHierarchy (TestRule testRule , Object objectRepresentingHierarchy ) {
69
69
this .testRule = testRule ;
70
- this .instance = instance ;
70
+ this .objectRepresentingHierarchy = objectRepresentingHierarchy ;
71
+ }
72
+
73
+ public TestRule getTestRule () {
74
+ return testRule ;
75
+ }
76
+
77
+ public Object getObjectRepresentingHierarchyLevel () {
78
+ return objectRepresentingHierarchy ;
71
79
}
72
80
}
73
81
74
82
private class TestRuleDefinitions {
75
- private List <TestRuleWithInstance > testRulePositionInTestHierarchies = new ArrayList <TestRuleWithInstance >();
83
+ private List <TestRuleInTestHierarchy > testRulePositionInTestHierarchies = new ArrayList <TestRuleInTestHierarchy >();
76
84
private List <Object > hierarchyOfTestsFromLowestToHighest ;
77
85
78
86
public TestRuleDefinitions (List <Object > hierarchyOfTestsFromLowestToHighest ) {
79
87
this .hierarchyOfTestsFromLowestToHighest = hierarchyOfTestsFromLowestToHighest ;
80
88
}
81
89
82
90
public boolean contains (MethodRule methodRule ) {
83
- for (TestRuleWithInstance t : testRulePositionInTestHierarchies ) {
84
- if (t .testRule .equals (methodRule ))
91
+ for (TestRuleInTestHierarchy t : testRulePositionInTestHierarchies ) {
92
+ if (t .getTestRule () .equals (methodRule ))
85
93
return true ;
86
94
}
87
95
return false ;
88
96
}
89
97
90
98
public void addAll (List <TestRule > testRules , Object instance ) {
91
99
for (TestRule testRule : testRules )
92
- testRulePositionInTestHierarchies .add (new TestRuleWithInstance (testRule , instance ));
100
+ testRulePositionInTestHierarchies .add (new TestRuleInTestHierarchy (testRule , instance ));
93
101
}
94
102
95
103
public boolean hasSome () {
96
104
return !testRulePositionInTestHierarchies .isEmpty ();
97
105
}
98
106
99
- public Iterable <TestRule > getTestRulesDefinedForThisHieraryLevel (Object instance ) {
107
+ public Iterable <TestRule > getTestRulesDefinedForThisHierarchyLevel (Object instance ) {
100
108
List <TestRule > result = new ArrayList <TestRule >();
101
- for (TestRuleWithInstance t : testRulePositionInTestHierarchies )
102
- if (hierarchyOfTestsFromLowestToHighest .indexOf (t . instance ) >= hierarchyOfTestsFromLowestToHighest .indexOf (instance ))
103
- result .add (t . testRule );
109
+ for (TestRuleInTestHierarchy testRulePosition : testRulePositionInTestHierarchies )
110
+ if (hierarchyOfTestsFromLowestToHighest .indexOf (testRulePosition . getObjectRepresentingHierarchyLevel () ) >= hierarchyOfTestsFromLowestToHighest .indexOf (instance ))
111
+ result .add (testRulePosition . getTestRule () );
104
112
return result ;
105
113
}
106
114
}
0 commit comments