use of org.junit.internal.runners.statements.Fail in project intellij-community by JetBrains.
the class GuiTestRunner method methodBlock.
@Override
protected Statement methodBlock(FrameworkMethod method) {
FrameworkMethod newMethod;
try {
if (Arrays.stream(getTestClass().getAnnotations()).anyMatch(annotation -> annotation instanceof ParentPlugin)) {
loadClassesWithNewPluginClassLoader();
} else {
loadClassesWithIdeClassLoader();
}
Method methodFromClassLoader = myTestClass.getJavaClass().getMethod(method.getName());
newMethod = new FrameworkMethod(methodFromClassLoader);
} catch (Exception e) {
return new Fail(e);
}
Object test;
try {
test = new ReflectiveCallable() {
@Override
protected Object runReflectiveCall() throws Throwable {
return createTest();
}
}.run();
} catch (Throwable e) {
return new Fail(e);
}
Statement statement = methodInvoker(newMethod, test);
List<FrameworkMethod> beforeMethods = myTestClass.getAnnotatedMethods(Before.class);
if (!beforeMethods.isEmpty()) {
statement = new RunBefores(statement, beforeMethods, test);
}
List<FrameworkMethod> afterMethods = myTestClass.getAnnotatedMethods(After.class);
if (!afterMethods.isEmpty()) {
statement = new RunAfters(statement, afterMethods, test);
}
return statement;
}
use of org.junit.internal.runners.statements.Fail in project android by JetBrains.
the class GuiTestRunner method methodBlock.
@Override
protected Statement methodBlock(FrameworkMethod method) {
if (GraphicsEnvironment.isHeadless()) {
// checked first because IdeTestApplication.getInstance below (indirectly) throws an AWTException in a headless environment
return falseAssumption("headless environment");
}
Method methodFromClassLoader;
try {
ClassLoader ideClassLoader = IdeTestApplication.getInstance().getIdeClassLoader();
Thread.currentThread().setContextClassLoader(ideClassLoader);
myTestClass = new TestClass(ideClassLoader.loadClass(getTestClass().getJavaClass().getName()));
methodFromClassLoader = myTestClass.getJavaClass().getMethod(method.getName());
} catch (Exception e) {
return new Fail(e);
}
return super.methodBlock(new FrameworkMethod(methodFromClassLoader));
}
use of org.junit.internal.runners.statements.Fail in project pact-jvm by DiUS.
the class InteractionRunner method interactionBlock.
protected Statement interactionBlock(final Interaction interaction) {
//1. prepare object
//2. get Target
//3. run Rule`s
//4. run Before`s
//5. run OnStateChange`s
//6. run test
//7. run After`s
final Object test;
try {
test = new ReflectiveCallable() {
@Override
protected Object runReflectiveCall() throws Throwable {
return createTest();
}
}.run();
} catch (Throwable e) {
return new Fail(e);
}
final Target target = testClass.getAnnotatedFieldValues(test, TestTarget.class, Target.class).get(0);
if (target instanceof TestClassAwareTarget) {
((TestClassAwareTarget) target).setTestClass(testClass, test);
}
Statement statement = new Statement() {
@Override
public void evaluate() throws Throwable {
target.testInteraction(pact.getConsumer().getName(), interaction);
}
};
statement = withStateChanges(interaction, test, statement);
statement = withBefores(interaction, test, statement);
statement = withRules(interaction, test, statement);
statement = withAfters(interaction, test, statement);
return statement;
}
use of org.junit.internal.runners.statements.Fail in project tomee by apache.
the class MetaRunner method methodBlock.
@Override
protected Statement methodBlock(final FrameworkMethod method) {
final Object test;
try {
test = new ReflectiveCallable() {
@Override
protected Object runReflectiveCall() throws Throwable {
return createTest();
}
}.run();
} catch (final Throwable e) {
return new Fail(e);
}
Statement statement = new MetaTest.$(method, test);
statement = withBefores(method, test, statement);
statement = withAfters(method, test, statement);
return statement;
}
use of org.junit.internal.runners.statements.Fail in project junit4 by junit-team.
the class BlockJUnit4ClassRunner method methodBlock.
/**
* Returns a Statement that, when executed, either returns normally if
* {@code method} passes, or throws an exception if {@code method} fails.
*
* Here is an outline of the default implementation:
*
* <ul>
* <li>Invoke {@code method} on the result of {@link #createTest(org.junit.runners.model.FrameworkMethod)}, and
* throw any exceptions thrown by either operation.
* <li>HOWEVER, if {@code method}'s {@code @Test} annotation has the {@link Test#expected()}
* attribute, return normally only if the previous step threw an
* exception of the correct type, and throw an exception otherwise.
* <li>HOWEVER, if {@code method}'s {@code @Test} annotation has the {@code
* timeout} attribute, throw an exception if the previous step takes more
* than the specified number of milliseconds.
* <li>ALWAYS run all non-overridden {@code @Before} methods on this class
* and superclasses before any of the previous steps; if any throws an
* Exception, stop execution and pass the exception on.
* <li>ALWAYS run all non-overridden {@code @After} methods on this class
* and superclasses after any of the previous steps; all After methods are
* always executed: exceptions thrown by previous steps are combined, if
* necessary, with exceptions from After methods into a
* {@link MultipleFailureException}.
* <li>ALWAYS allow {@code @Rule} fields to modify the execution of the
* above steps. A {@code Rule} may prevent all execution of the above steps,
* or add additional behavior before and after, or modify thrown exceptions.
* For more information, see {@link TestRule}
* </ul>
*
* This can be overridden in subclasses, either by overriding this method,
* or the implementations creating each sub-statement.
*/
protected Statement methodBlock(final FrameworkMethod method) {
Object test;
try {
test = new ReflectiveCallable() {
@Override
protected Object runReflectiveCall() throws Throwable {
return createTest(method);
}
}.run();
} catch (Throwable e) {
return new Fail(e);
}
Statement statement = methodInvoker(method, test);
statement = possiblyExpectingExceptions(method, test, statement);
statement = withPotentialTimeout(method, test, statement);
statement = withBefores(method, test, statement);
statement = withAfters(method, test, statement);
statement = withRules(method, test, statement);
statement = withInterruptIsolation(statement);
return statement;
}
Aggregations