use of org.junit.runners.model.Statement in project randomizedtesting by randomizedtesting.
the class RandomizedRunner method wrapExpectedExceptions.
/**
* Wrap the given statement into another catching the expected exception, if declared.
*/
private Statement wrapExpectedExceptions(final Statement s, TestCandidate c) {
Test ann = c.method.getAnnotation(Test.class);
if (ann == null) {
return s;
}
// If there's no expected class, don't wrap. Eh, None is package-private...
final Class<? extends Throwable> expectedClass = ann.expected();
if (expectedClass.getName().equals("org.junit.Test$None")) {
return s;
}
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
s.evaluate();
} catch (Throwable t) {
if (!expectedClass.isInstance(t)) {
throw t;
}
// We caught something that was expected. No worries then.
return;
}
// If we're here this means we passed the test that expected a failure.
Assert.fail("Expected an exception but the test passed: " + expectedClass.getName());
}
};
}
use of org.junit.runners.model.Statement in project robolectric by robolectric.
the class SandboxTestRunner method classBlock.
@Override
protected Statement classBlock(RunNotifier notifier) {
final Statement statement = childrenInvoker(notifier);
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
statement.evaluate();
for (Class<?> testClass : loadedTestClasses) {
invokeAfterClass(testClass);
}
} finally {
afterClass();
loadedTestClasses.clear();
}
}
};
}
use of org.junit.runners.model.Statement in project neo4j by neo4j.
the class GraphStoreFixture method apply.
@Override
public Statement apply(final Statement base, Description description) {
final TestDirectory directory = TestDirectory.testDirectory(description.getTestClass());
return super.apply(directory.apply(new Statement() {
@Override
public void evaluate() throws Throwable {
GraphStoreFixture.this.directory = directory.graphDbDir();
try {
generateInitialData();
start(GraphStoreFixture.this.directory);
try {
base.evaluate();
} finally {
stop();
}
} finally {
GraphStoreFixture.this.directory = null;
}
}
}, description), description);
}
use of org.junit.runners.model.Statement in project pinpoint by naver.
the class PinpointPluginTestSuite method classBlock.
protected Statement classBlock(final RunNotifier notifier) {
Statement statement = childrenInvoker(notifier);
if (!areAllChildrenIgnored()) {
statement = withBeforeClasses(statement);
statement = withAfterClasses(statement);
statement = withClassRules(statement);
}
return statement;
}
use of org.junit.runners.model.Statement in project pinpoint by naver.
the class ForkedPinpointPluginTestRunner method methodBlock.
@Override
protected Statement methodBlock(FrameworkMethod method) {
final Statement fromSuper = super.methodBlock(method);
final boolean manageTraceObject = this.manageTraceObject && (method.getAnnotation(TraceObjectManagable.class) == null);
return new Statement() {
@Override
public void evaluate() throws Throwable {
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.initialize(manageTraceObject);
try {
fromSuper.evaluate();
} finally {
verifier.cleanUp(manageTraceObject);
}
}
};
}
Aggregations