use of org.junit.runners.model.Statement in project tomee by apache.
the class ScopesRule method apply.
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final CdiScopes annotation = description.getAnnotation(CdiScopes.class);
if (annotation == null) {
base.evaluate();
return;
}
final WebBeansContext wbc = WebBeansContext.currentInstance();
final Map<Class<?>, Object> init = new HashMap<>();
Class<? extends Annotation>[] scopes = annotation.value();
for (final Class<? extends Annotation> c : scopes) {
final Object o = param(c);
if (o != null) {
init.put(c, o);
}
wbc.getContextsService().startContext(c, o);
}
try {
base.evaluate();
} finally {
for (final Class<? extends Annotation> c : scopes) {
wbc.getContextsService().endContext(c, init.get(c));
}
}
}
};
}
use of org.junit.runners.model.Statement in project tomee by apache.
the class TransactionRule method apply.
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final TransactionAttribute annotation = description.getAnnotation(TransactionAttribute.class);
final Transactional annotation2 = description.getAnnotation(Transactional.class);
if (annotation == null && annotation2 == null) {
base.evaluate();
return;
}
final BeanContext beanContext = getBeanContext();
final Method method = beanContext.getManagedClass().getMethod(description.getMethodName());
final TransactionType transactionType = TransactionType.get(annotation == null ? TransactionAttributeType.valueOf(annotation2.value().name()) : annotation.value());
beanContext.getMethodContext(method).setTransactionType(transactionType);
ThreadContext tc = ThreadContext.getThreadContext();
final boolean tcCreated;
if (tc == null) {
tcCreated = true;
tc = ThreadContext.enter(new ThreadContext(beanContext, null));
} else {
tcCreated = false;
}
final TransactionPolicy policy = EjbTransactionUtil.createTransactionPolicy(transactionType, tc);
try {
base.evaluate();
} finally {
if (rollback) {
policy.setRollbackOnly();
}
EjbTransactionUtil.afterInvoke(policy, tc);
if (tcCreated) {
ThreadContext.exit(tc);
}
}
}
};
}
use of org.junit.runners.model.Statement in project junit4 by junit-team.
the class ParentRunner method run.
@Override
public void run(final RunNotifier notifier) {
EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription());
testNotifier.fireTestSuiteStarted();
try {
Statement statement = classBlock(notifier);
statement.evaluate();
} catch (AssumptionViolatedException e) {
testNotifier.addFailedAssumption(e);
} catch (StoppedByUserException e) {
throw e;
} catch (Throwable e) {
testNotifier.addFailure(e);
} finally {
testNotifier.fireTestSuiteFinished();
}
}
use of org.junit.runners.model.Statement in project junit4 by junit-team.
the class BlockJUnit4ClassRunner method runChild.
//
// Implementation of ParentRunner
//
@Override
protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
Description description = describeChild(method);
if (isIgnored(method)) {
notifier.fireTestIgnored(description);
} else {
Statement statement;
try {
statement = methodBlock(method);
} catch (Throwable ex) {
statement = new Fail(ex);
}
runLeaf(statement, description, notifier);
}
}
use of org.junit.runners.model.Statement in project junit4 by junit-team.
the class ExpectExceptionTest method whenExpectingAssumptionViolatedExceptionStatementsThrowingDifferentExceptionShouldFail.
@Test
public void whenExpectingAssumptionViolatedExceptionStatementsThrowingDifferentExceptionShouldFail() {
Statement delegate = new Fail(new SomeException("not expected"));
ExpectException expectException = new ExpectException(delegate, AssumptionViolatedException.class);
try {
expectException.evaluate();
fail("should throw 'Unexpected exception' when statement throws an exception which is not the one expected");
} catch (Exception e) {
assertThat(e.getMessage(), equalTo("Unexpected exception, expected<org.junit.internal.AssumptionViolatedException> " + "but was<org.junit.internal.runners.statements.ExpectExceptionTest$SomeException>"));
}
}
Aggregations