use of org.junit.runners.model.Statement in project alchemy-test by SirWellington.
the class AlchemyTestRunner method withBefores.
@Override
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
Statement superStatement = super.withBefores(method, target, statement);
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (shouldInitMocks) {
MockitoAnnotations.initMocks(target);
}
TestClassInjectors.populateGeneratedFields(getTestClass(), target);
superStatement.evaluate();
}
};
}
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 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.runners.model.Statement in project beam by apache.
the class TestExecutorsTest method testSuccessfulTermination.
@Test
public void testSuccessfulTermination() throws Throwable {
ExecutorService service = Executors.newSingleThreadExecutor();
final TestExecutorService testService = TestExecutors.from(() -> service);
final AtomicBoolean taskRan = new AtomicBoolean();
testService.apply(new Statement() {
@Override
public void evaluate() throws Throwable {
testService.submit(() -> taskRan.set(true));
}
}, null).evaluate();
assertTrue(service.isTerminated());
assertTrue(taskRan.get());
}
use of org.junit.runners.model.Statement in project beam by apache.
the class TestExecutorsTest method testStatementFailurePropagatedCleanly.
@Test
public void testStatementFailurePropagatedCleanly() throws Throwable {
ExecutorService service = Executors.newSingleThreadExecutor();
final TestExecutorService testService = TestExecutors.from(() -> service);
final RuntimeException exceptionToThrow = new RuntimeException();
try {
testService.apply(new Statement() {
@Override
public void evaluate() throws Throwable {
throw exceptionToThrow;
}
}, null).evaluate();
fail();
} catch (RuntimeException thrownException) {
assertSame(exceptionToThrow, thrownException);
}
assertTrue(service.isShutdown());
}
Aggregations