Browse files

Merge branch 'run-leaf' of https://github.com/kcooney/junit into kcoo…

…ney-run-leaf

Conflicts:
	src/main/java/org/junit/rules/TestRule.java
  • Loading branch information...
2 parents 0781e97 + 7f6173a commit 9d8bb069f68e2194db742981972c8930381b62c2 David Saff committed Jan 11, 2011
View
3 src/main/java/org/junit/ClassRule.java
@@ -1,9 +1,7 @@
package org.junit;
-import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
import org.junit.rules.TestRule;
@@ -57,6 +55,5 @@
* For more information and more examples, see {@link TestRule}.
*/
@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD})
public @interface ClassRule {
}
View
3 src/main/java/org/junit/Rule.java
@@ -1,9 +1,7 @@
package org.junit;
-import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
import org.junit.rules.MethodRule;
@@ -44,7 +42,6 @@
*/
@SuppressWarnings("deprecation")
@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.FIELD})
public @interface Rule {
}
View
5 src/main/java/org/junit/rules/ExpectedException.java
@@ -41,7 +41,7 @@
* }
* </pre>
*/
-public class ExpectedException extends TestRule {
+public class ExpectedException implements TestRule {
/**
* @return a Rule that expects no exception to be thrown
* (identical to behavior without this Rule)
@@ -56,8 +56,7 @@ private ExpectedException() {
}
- @Override
- protected Statement apply(Statement base,
+ public Statement apply(Statement base,
org.junit.runner.Description description) {
return new ExpectedExceptionStatement(base);
}
View
5 src/main/java/org/junit/rules/ExternalResource.java
@@ -32,9 +32,8 @@
* }
* </pre>
*/
-public abstract class ExternalResource extends TestRule {
- @Override
- protected Statement apply(Statement base, Description description) {
+public abstract class ExternalResource implements TestRule {
+ public Statement apply(Statement base, Description description) {
return statement(base);
}
View
29 src/main/java/org/junit/rules/TestRule.java
@@ -35,38 +35,23 @@
* <li>{@link ExternalResource}: start and stop a server, for example</li>
* <li>{@link TemporaryFolder}: create fresh files, and delete after test</li>
* <li>{@link TestName}: remember the test name for use during the method</li>
- * <li>{@link TestWatcher}: add logic at events during method execution</li>
+ * <li>{@link TestWatchman}: add logic at events during method execution</li>
* <li>{@link Timeout}: cause test to fail after a set time</li>
* <li>{@link Verifier}: fail test if object state ends up incorrect</li>
* </ul>
+ *
+ * [[MethodRule has been deprecated, and all uses will be changed to TestRule,
+ * so this javadoc will become more truthy with time.]]
*/
-public abstract class TestRule {
+public interface TestRule {
/**
- * Modifies the method-running {@link Statement} to implement this
+ * Modifies the method-running {@link Statement} to implement an additional
* test-running rule.
*
* @param base The {@link Statement} to be modified
* @param description A {@link Description} of the test implemented in {@code base}
* @return a new statement, which may be the same as {@code base},
* a wrapper around {@code base}, or a completely new Statement.
*/
- protected abstract Statement apply(Statement base, Description description);
-
- /**
- * Modifies the method-running {@link Statement} to implement the additional
- * test-running rules.
- *
- * @param rules The {@link TestRule rules} to apply
- * @param base The {@link Statement} to be modified
- * @param description A {@link Description} of the test implemented in {@code base}
- * @return a new statement, which may be the same as {@code base},
- * a wrapper around {@code base}, or a completely new Statement.
- */
- public static Statement applyAll(Iterable<TestRule> rules, Statement base,
- Description description) {
- Statement result = base;
- for (TestRule each : rules)
- result= each.apply(result, description);
- return result;
- }
+ Statement apply(Statement base, Description description);
}
View
5 src/main/java/org/junit/rules/TestWatcher.java
@@ -36,9 +36,8 @@
* }
* </pre>
*/
-public class TestWatcher extends TestRule {
- @Override
- protected Statement apply(final Statement base, final Description description) {
+public class TestWatcher implements TestRule {
+ public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
View
5 src/main/java/org/junit/rules/Timeout.java
@@ -33,7 +33,7 @@
* }
* </pre>
*/
-public class Timeout extends TestRule {
+public class Timeout implements TestRule {
private final int fMillis;
/**
@@ -43,8 +43,7 @@ public Timeout(int millis) {
fMillis= millis;
}
- @Override
- protected Statement apply(Statement base, Description description) {
+ public Statement apply(Statement base, Description description) {
return new FailOnTimeout(base, fMillis);
}
}
View
5 src/main/java/org/junit/rules/Verifier.java
@@ -25,9 +25,8 @@
* }
* </pre>
*/
-public class Verifier extends TestRule {
- @Override
- protected Statement apply(final Statement base, Description description) {
+public class Verifier implements TestRule {
+ public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
View
4 src/main/java/org/junit/runners/BlockJUnit4ClassRunner.java
@@ -363,7 +363,9 @@ private Statement withMethodRules(FrameworkMethod method, Object target,
private Statement withTestRules(FrameworkMethod method, Object target,
Statement result) {
- return TestRule.applyAll(getTestRules(target), result, describeChild(method));
+ for (TestRule each : getTestRules(target))
+ result= each.apply(result, describeChild(method));
+ return result;
}
private List<TestRule> getTestRules(Object target) {
View
6 src/main/java/org/junit/runners/ParentRunner.java
@@ -192,7 +192,11 @@ private Statement withClassRules(Statement statement) {
if (classRules.isEmpty()) {
return statement;
}
- return TestRule.applyAll(classRules, statement, getDescription());
+ Statement next = statement;
+ for (final TestRule classRule : classRules) {
+ next = classRule.apply(next, getDescription());
+ }
+ return next;
}
/**
View
5 src/test/java/org/junit/tests/experimental/rules/ClassRulesTest.java
@@ -61,11 +61,10 @@ public void ruleIsIntroducedAndEvaluatedOnSubclass() {
assertEquals(1, ExampleTestWithClassRule.counter.count);
}
- public static class CustomCounter extends TestRule {
+ public static class CustomCounter implements TestRule {
public int count = 0;
- @Override
- protected Statement apply(final Statement base, Description description) {
+ public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
View
5 src/test/java/org/junit/tests/experimental/rules/MethodRulesTest.java
@@ -248,11 +248,10 @@ public void beforesAndAfters() {
hasSingleFailureContaining("must be public"));
}
- public static class CustomTestName extends TestRule {
+ public static class CustomTestName implements TestRule {
public String name = null;
- @Override
- protected Statement apply(final Statement base, final Description description) {
+ public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
View
18 src/test/java/org/junit/tests/experimental/rules/TestRuleTest.java
@@ -28,8 +28,7 @@
public static class ExampleTest {
@Rule
public TestRule example= new TestRule() {
- @Override
- protected Statement apply(final Statement base, Description description) {
+ public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
@@ -54,7 +53,7 @@ public void ruleIsIntroducedAndEvaluated() {
}
@SuppressWarnings("deprecation")
- public static class BothKindsOfRule extends TestRule implements org.junit.rules.MethodRule {
+ public static class BothKindsOfRule implements TestRule, org.junit.rules.MethodRule {
public int applications = 0;
public Statement apply(Statement base, FrameworkMethod method,
@@ -63,8 +62,7 @@ public Statement apply(Statement base, FrameworkMethod method,
return base;
}
- @Override
- protected Statement apply(Statement base, Description description) {
+ public Statement apply(Statement base, Description description) {
applications++;
return base;
}
@@ -98,9 +96,8 @@ public void ruleIsIntroducedAndEvaluatedOnSubclass() {
private static int runCount;
public static class MultipleRuleTest {
- private static class Increment extends TestRule {
- @Override
- protected Statement apply(final Statement base, Description description) {
+ private static class Increment implements TestRule {
+ public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
@@ -277,11 +274,10 @@ public void beforesAndAfters() {
hasSingleFailureContaining("must be public"));
}
- public static class CustomTestName extends TestRule {
+ public static class CustomTestName implements TestRule {
public String name = null;
- @Override
- protected Statement apply(final Statement base, final Description description) {
+ public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {

0 comments on commit 9d8bb06

Please sign in to comment.