use of org.junit.runners.model.Statement in project neo4j by neo4j.
the class Neo4jWithSocket method apply.
@Override
public Statement apply(final Statement statement, final Description description) {
Statement testMethod = new Statement() {
@Override
public void evaluate() throws Throwable {
// If this is used as class rule then getMethodName() returns null, so use
// getClassName() instead.
String name = description.getMethodName() != null ? description.getMethodName() : description.getClassName();
workingDirectory = testDirectory.directory(name);
ensureDatabase(settings -> {
});
try {
statement.evaluate();
} finally {
shutdownDatabase();
}
}
};
Statement testMethodWithBeforeAndAfter = super.apply(testMethod, description);
return testDirectory.apply(testMethodWithBeforeAndAfter, description);
}
use of org.junit.runners.model.Statement in project pinpoint by naver.
the class PinpointJUnit4ClassRunner method withBefores.
@Override
protected Statement withBefores(FrameworkMethod method, final Object target, Statement statement) {
Statement before = super.withBefores(method, target, statement);
BeforeCallbackStatement callbackStatement = new BeforeCallbackStatement(before, new Statement() {
@Override
public void evaluate() throws Throwable {
setupBaseTest(target);
}
});
return callbackStatement;
}
use of org.junit.runners.model.Statement in project zipkin by openzipkin.
the class ExecJarRule method apply.
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
public void evaluate() throws Throwable {
try {
ProcessBuilder bootBuilder = new ProcessBuilder("java", "-jar", execJar);
bootBuilder.environment().put("SERVER_PORT", String.valueOf(port()));
bootBuilder.environment().putAll(environment);
bootBuilder.redirectErrorStream(true);
bootApp = bootBuilder.start();
CountDownLatch startedOrCrashed = new CountDownLatch(1);
Thread consoleReader = new Thread(() -> {
boolean foundStartMessage = false;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(bootApp.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
if (line.indexOf("JVM running for") != -1) {
foundStartMessage = true;
startedOrCrashed.countDown();
}
console.add(line);
}
} catch (Exception e) {
} finally {
if (!foundStartMessage)
startedOrCrashed.countDown();
}
});
consoleReader.setDaemon(true);
consoleReader.start();
if (!startedOrCrashed.await(10, TimeUnit.SECONDS)) {
throw new AssumptionViolatedException("Took too long to start or crash");
}
base.evaluate();
} finally {
bootApp.destroy();
}
}
};
}
use of org.junit.runners.model.Statement in project querydsl by querydsl.
the class HibernateTestRunner method rules.
@Override
protected List<MethodRule> rules(Object test) {
verify(test instanceof HibernateTest, "In order to use the %s for %s, it should (directly or indirectly) implement %s", HibernateTestRunner.class.getSimpleName(), test.getClass(), HibernateTest.class);
List<MethodRule> rules = super.rules(test);
rules.add(new MethodRule() {
@Override
public Statement apply(final Statement base, FrameworkMethod method, final Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
((HibernateTest) target).setSession(session);
base.evaluate();
}
};
}
});
return rules;
}
use of org.junit.runners.model.Statement in project querydsl by querydsl.
the class JPATestRunner method rules.
@Override
protected List<MethodRule> rules(Object test) {
verify(test instanceof JPATest, "In order to use the %s for %s, it should (directly or indirectly) implement %s", JPATestRunner.class.getSimpleName(), test.getClass(), JPATest.class);
List<MethodRule> rules = super.rules(test);
rules.add(new MethodRule() {
@Override
public Statement apply(final Statement base, FrameworkMethod method, final Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
((JPATest) target).setEntityManager(entityManager);
base.evaluate();
}
};
}
});
return rules;
}
Aggregations