forked from Pragmatists/JUnitParams
-
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.
Fixes Pragmatists#122: Apply filters consistently
- Loading branch information
1 parent
a5c330d
commit a909e39
Showing
20 changed files
with
567 additions
and
432 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
45 changes: 45 additions & 0 deletions
45
src/main/java/junitparams/internal/DeferredErrorFrameworkMethod.java
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,45 @@ | ||
package junitparams.internal; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runner.notification.RunNotifier; | ||
import org.junit.runners.model.Statement; | ||
|
||
/** | ||
* Encapsulates a {@link Throwable} that was caught during initialization so that it can be | ||
* thrown during execution in order to preserve previous behavior. | ||
*/ | ||
public class DeferredErrorFrameworkMethod extends InvokableFrameworkMethod { | ||
|
||
private final Description description; | ||
private final Throwable throwable; | ||
|
||
DeferredErrorFrameworkMethod(Method method, Description description, Throwable throwable) { | ||
super(method); | ||
this.description = description; | ||
this.throwable = throwable; | ||
} | ||
|
||
@Override | ||
public Description getDescription() { | ||
return description; | ||
} | ||
|
||
@Override | ||
public Statement getInvokeStatement(Object test) { | ||
return new Statement() { | ||
@Override | ||
public void evaluate() throws Throwable { | ||
throw throwable; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public void run(MethodBlockSupplier supplier, RunNotifier notifier) { | ||
// Do not call the MethodBlockSupplier as that could introduce additional errors, simply | ||
// throw the encapsulated Throwable immediately. | ||
runMethodInvoker(notifier, getInvokeStatement(notifier), getDescription()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/junitparams/internal/DescribableFrameworkMethod.java
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,17 @@ | ||
package junitparams.internal; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.junit.runner.Describable; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.FrameworkMethod; | ||
|
||
/** | ||
* A {@link FrameworkMethod} that also provides a {@link Description}. | ||
*/ | ||
public abstract class DescribableFrameworkMethod extends FrameworkMethod implements Describable { | ||
|
||
DescribableFrameworkMethod(Method method) { | ||
super(method); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/junitparams/internal/InstanceFrameworkMethod.java
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,65 @@ | ||
package junitparams.internal; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runner.Runner; | ||
import org.junit.runner.notification.RunListener; | ||
import org.junit.runner.notification.RunNotifier; | ||
import org.junit.runners.model.FrameworkMethod; | ||
import org.junit.runners.model.Statement; | ||
|
||
/** | ||
* A {@link FrameworkMethod} that represents an instance of an | ||
* {@link ParameterisedFrameworkMethod}, that is the combination of the test method with the | ||
* parameter set that it will be passed. | ||
*/ | ||
public class InstanceFrameworkMethod extends InvokableFrameworkMethod { | ||
|
||
private final Description description; | ||
|
||
private final Description instanceDescription; | ||
|
||
private final Object parametersSet; | ||
|
||
/** | ||
* Create an {@link InstanceFrameworkMethod}. | ||
* | ||
* <p>It has two {@link Description} instances because it has to provide different | ||
* {@link Description} to {@link TestRule} instances than other usages in order to maintain | ||
* backwards compatibility. | ||
* | ||
* @param method the test method | ||
* @param description the description that is supplied to {@link TestRule} instances. | ||
* @param instanceDescription the description used for all other purposes, e.g. filtering, | ||
* {@link Runner#getDescription()} and {@link RunListener}. | ||
* @param parametersSet the set of parameters to pass to the method. | ||
*/ | ||
InstanceFrameworkMethod(Method method, Description description, | ||
Description instanceDescription, Object parametersSet) { | ||
super(method); | ||
this.description = description; | ||
this.instanceDescription = instanceDescription; | ||
this.parametersSet = parametersSet; | ||
} | ||
|
||
@Override | ||
public Description getDescription() { | ||
return description; | ||
} | ||
|
||
Description getInstanceDescription() { | ||
return instanceDescription; | ||
} | ||
|
||
@Override | ||
public Statement getInvokeStatement(Object test) { | ||
return new InvokeParameterisedMethod(this, test, parametersSet); | ||
} | ||
|
||
@Override | ||
public void run(MethodBlockSupplier supplier, RunNotifier notifier) { | ||
runMethodInvoker(notifier, supplier.getMethodBlock(this), getInstanceDescription()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/junitparams/internal/InvokableFrameworkMethod.java
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,51 @@ | ||
package junitparams.internal; | ||
|
||
import java.lang.reflect.Method; | ||
import junitparams.JUnitParamsRunner; | ||
import org.junit.internal.AssumptionViolatedException; | ||
import org.junit.internal.runners.model.EachTestNotifier; | ||
import org.junit.runner.Description; | ||
import org.junit.runner.notification.RunNotifier; | ||
import org.junit.runners.model.FrameworkMethod; | ||
import org.junit.runners.model.Statement; | ||
|
||
/** | ||
* Base for {@link FrameworkMethod} classes that provide a {@link Statement} for invoking. | ||
*/ | ||
public abstract class InvokableFrameworkMethod extends DescribableFrameworkMethod { | ||
|
||
InvokableFrameworkMethod(Method method) { | ||
super(method); | ||
} | ||
|
||
/** | ||
* Create a {@link Statement} that when called will invoke the method. | ||
* | ||
* <p>This is usually called from the | ||
* {@link JUnitParamsRunner#methodInvoker(FrameworkMethod, Object)} method via the | ||
* {@link MethodBlockSupplier} which is usually called from within the | ||
* {@link #run(MethodBlockSupplier, RunNotifier)} method. | ||
* | ||
* @param test | ||
* the object on which the method will be invoked. | ||
* @return the {@link Statement}. | ||
*/ | ||
public abstract Statement getInvokeStatement(Object test); | ||
|
||
void runMethodInvoker(RunNotifier notifier, Statement methodInvoker, | ||
Description methodWithParams) { | ||
EachTestNotifier eachNotifier = new EachTestNotifier(notifier, methodWithParams); | ||
eachNotifier.fireTestStarted(); | ||
try { | ||
methodInvoker.evaluate(); | ||
} catch (AssumptionViolatedException e) { | ||
eachNotifier.addFailedAssumption(e); | ||
} catch (Throwable e) { | ||
eachNotifier.addFailure(e); | ||
} finally { | ||
eachNotifier.fireTestFinished(); | ||
} | ||
} | ||
|
||
public abstract void run(MethodBlockSupplier supplier, RunNotifier notifier); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/junitparams/internal/InvokeNonParameterisedMethod.java
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,24 @@ | ||
package junitparams.internal; | ||
|
||
import org.junit.runners.model.FrameworkMethod; | ||
import org.junit.runners.model.Statement; | ||
|
||
/** | ||
* JUnit invoker for non-parameterised test methods | ||
*/ | ||
public class InvokeNonParameterisedMethod extends Statement { | ||
|
||
private final FrameworkMethod testMethod; | ||
private final Object testClass; | ||
|
||
InvokeNonParameterisedMethod(FrameworkMethod testMethod, Object testClass) { | ||
this.testMethod = testMethod; | ||
this.testClass = testClass; | ||
} | ||
|
||
@Override | ||
public void evaluate() throws Throwable { | ||
testMethod.invokeExplosively(testClass); | ||
} | ||
|
||
} |
Oops, something went wrong.