use of org.junit.runners.model.Statement in project buck by facebook.
the class BuckBlockJUnit4ClassRunner method methodBlock.
/**
* Override the default timeout behavior so that when no timeout is specified in the {@link Test}
* annotation, the timeout specified by the constructor will be used (if it has been set).
*/
@Override
protected Statement methodBlock(FrameworkMethod method) {
Statement statement = super.methodBlock(method);
// If the test class has a Timeout @Rule, then that should supersede the default timeout. The
// same applies if it has a timeout value for the @Test annotation.
long timeout = getTimeout(method);
return new SameThreadFailOnTimeout(executor.get(), timeout, testName(method), statement);
}
use of org.junit.runners.model.Statement in project hibernate-orm by hibernate.
the class CustomRunner method methodBlock.
@Override
protected Statement methodBlock(FrameworkMethod method) {
log.info(Test.class.getSimpleName() + ": " + method.getName());
final Statement originalMethodBlock = super.methodBlock(method);
final ExtendedFrameworkMethod extendedFrameworkMethod = (ExtendedFrameworkMethod) method;
return new FailureExpectedHandler(originalMethodBlock, testClassMetadata, extendedFrameworkMethod, testInstance);
}
use of org.junit.runners.model.Statement in project jsonschema2pojo by joelittlejohn.
the class Jsonschema2PojoRule method apply.
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
active = true;
diagnostics = new ArrayList<Diagnostic<? extends JavaFileObject>>();
boolean captureDiagnosticsStart = captureDiagnostics;
try {
File testRoot = methodNameDir(classNameDir(rootDirectory(), description.getClassName()), description.getMethodName());
generateDir = new File(testRoot, "generate");
compileDir = new File(testRoot, "compile");
base.evaluate();
} finally {
generateDir = null;
compileDir = null;
classLoader = null;
sourceDirInitialized = false;
classesDirInitialized = false;
captureDiagnostics = captureDiagnosticsStart;
diagnostics = null;
active = false;
}
}
};
}
use of org.junit.runners.model.Statement in project junit4 by junit-team.
the class ExpectExceptionTest method whenExpectingAssumptionViolatedExceptionStatementsThrowingSubclassShouldPass.
@Test
public void whenExpectingAssumptionViolatedExceptionStatementsThrowingSubclassShouldPass() {
Statement delegate = new Fail(new AssumptionViolatedExceptionSubclass("expected"));
ExpectException expectException = new ExpectException(delegate, AssumptionViolatedException.class);
try {
expectException.evaluate();
// then no exception should be thrown
} catch (Throwable e) {
fail("should not throw anything, but was thrown: " + e);
}
}
use of org.junit.runners.model.Statement in project junit4 by junit-team.
the class ExternalResourceRuleTest method shouldThrowMultipleFailureExceptionWhenTestFailsAndClosingResourceFails.
@Test
public void shouldThrowMultipleFailureExceptionWhenTestFailsAndClosingResourceFails() throws Throwable {
// given
ExternalResource resourceRule = new ExternalResource() {
@Override
protected void after() {
throw new RuntimeException("simulating resource tear down failure");
}
};
Statement failingTest = new Fail(new RuntimeException("simulated test failure"));
Description dummyDescription = Description.createTestDescription("dummy test class name", "dummy test name");
try {
resourceRule.apply(failingTest, dummyDescription).evaluate();
fail("ExternalResource should throw");
} catch (MultipleFailureException e) {
assertThat(e.getMessage(), allOf(containsString("simulated test failure"), containsString("simulating resource tear down failure")));
}
}
Aggregations