{
Method withRules = BlockJUnit4ClassRunner.class.getDeclaredMethod("withRules",
new Class[] {FrameworkMethod.class, Object.class, Statement.class});
withRules.setAccessible(true);
Statement statement = methodInvoker(method, test);
statement = possiblyExpectingExceptions(method, test, statement);
statement = withPotentialTimeout(method, test, statement);
final Object testObj = test;
final Statement testStatement = statement;
Statement arounds = withBefores(method, test, testStatement);
arounds = withAfters(method, test, arounds);
arounds = (Statement)withRules.invoke(this, new Object[] {method, test, arounds});
final Statement withArounds = arounds;
return new Statement() {
@Override
public void evaluate() throws Throwable {
List<Throwable> exceptions = new ArrayList<Throwable>();
try {
final AtomicInteger integer = new AtomicInteger();
adaptor.before(testObj, method.getMethod(), new LifecycleMethodExecutor() {
@Override
public void invoke() throws Throwable {
integer.incrementAndGet();
}
});
try {
State.caughtExceptionAfterJunit(null);
if(integer.get() > 0) {
withArounds.evaluate();
} else {
testStatement.evaluate();
}
}
catch (Throwable e) {