forked from junit-team/junit4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ComplexRule as a superclass to TestRule.
Allows a single rule implementation to support @ClassRule and/or @rule, thus allowing features of complex runners to be migrated to something like: @rule @ClassRule public static SpringContextManagementRule rule = new MySpringContextManagementRule();
- Loading branch information
neale.upstone
committed
Feb 22, 2011
1 parent
b4180bf
commit da6c5e5
Showing
9 changed files
with
364 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.junit.rules; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
/** | ||
* A rule that can apply behaviour to at both class and method level. | ||
* | ||
* @author Neale Upstone | ||
*/ | ||
public abstract class ComplexRule { | ||
protected abstract Statement applyClassRule(Statement base, | ||
Description description, Class<?> clazz); | ||
|
||
protected abstract Statement applyMethodRule(Statement base, | ||
Description description, Object target); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.junit.rules; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
import org.junit.runners.model.TestClass; | ||
|
||
/** | ||
* Run the class-specific part of each Rule on a {@link Statement} | ||
* | ||
* @author Neale Upstone | ||
*/ | ||
public class RunClassRules extends Statement { | ||
|
||
private final Statement statement; | ||
|
||
public RunClassRules(Statement base, List<ComplexRule> rules, Description description, TestClass testClass) { | ||
statement = applyAll(base, rules, description, testClass); | ||
} | ||
|
||
@Override | ||
public void evaluate() throws Throwable { | ||
statement.evaluate(); | ||
} | ||
|
||
private static Statement applyAll(Statement result, Iterable<ComplexRule> rules, Description description, TestClass testClass) { | ||
for (ComplexRule each : rules) { | ||
result = each.applyClassRule(result, description, testClass.getJavaClass()); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.junit.rules; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
/** | ||
* Run the method-specific part of each Rule on a {@link Statement} | ||
* | ||
* @author Neale Upstone | ||
*/ | ||
public class RunMethodRules extends Statement { | ||
|
||
private final Statement statement; | ||
|
||
public RunMethodRules(Statement base, List<ComplexRule> rules, Description description, Object target) { | ||
statement = applyAll(base, rules, description, target); | ||
} | ||
|
||
@Override | ||
public void evaluate() throws Throwable { | ||
statement.evaluate(); | ||
} | ||
|
||
private static Statement applyAll(Statement result, Iterable<ComplexRule> rules, Description description, Object target) { | ||
for (ComplexRule each : rules) { | ||
result = each.applyMethodRule(result, description, target); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.