/** * Perform the same logic as * {@link BlockJUnit4ClassRunner#runChild(FrameworkMethod, RunNotifier)}, * except that tests are determined to be <em>ignored</em> by * {@link #isTestMethodIgnored(FrameworkMethod)}. */ @Override protected void runChild(FrameworkMethod frameworkMethod, RunNotifier notifier) { Description description = describeChild(frameworkMethod); if (isTestMethodIgnored(frameworkMethod)) { notifier.fireTestIgnored(description); } else { Statement statement; try { statement = methodBlock(frameworkMethod); } catch (Throwable ex) { statement = new Fail(ex); } runLeaf(statement, description, notifier); } }
/** * If an instanciation exception occured, we don't run the * actual tests! */ @Override protected Statement methodBlock(FrameworkMethod method) { Statement statement = super.methodBlock(method); if(statement instanceof Fail) { try { ((Fail)statement).evaluate(); } catch(Throwable ex) { this.exceptionInBeforeClass = new Exception(ex); } } if(isExpectingInstanciationException() && this.exceptionInBeforeClass != null) { statement = new Statement() { @Override public void evaluate() throws Throwable { // ok } }; } return statement; }
return new Fail(ex);
return new Fail(e);
return new Fail(e);
if (someError) return new Fail(1); else return new Okay(true);
/** * Get current test object * * @return test object. */ public Object getTestObject() { Object testObject = testObjectMap.get(getTestClass()); if (testObject == null) { try { ReflectiveCallable reflectiveCallable = new ReflectiveCallable() { @Override protected Object runReflectiveCall() throws Throwable { return createTest(); } }; testObject = reflectiveCallable.run(); testObjectMap.put(getTestClass(), testObject); } catch (Throwable e) { return new Fail(e); } } return testObject; }
/** * Override to avoid running Before, After and Rule methods by the driver. They shall only be * run by the container when using a probe invoker. */ protected Statement methodBlock(FrameworkMethod method) { Object test; try { ReflectiveCallable reflectiveCallable = new ReflectiveCallable() { @Override // CHECKSTYLE:SKIP : Base class API protected Object runReflectiveCall() throws Throwable { return createTest(); } }; test = reflectiveCallable.run(); } // CHECKSTYLE:SKIP : ReflectiveCallable API catch (Throwable e) { return new Fail(e); } Statement statement = methodInvoker(method, test); return statement; }
/** * Override to avoid running Before, After and Rule methods by the driver. They shall only be * run by the container when using a probe invoker. */ @Override protected Statement methodBlock(FrameworkMethod method) { Object test; try { ReflectiveCallable reflectiveCallable = new ReflectiveCallable() { @Override // CHECKSTYLE:SKIP : Base class API protected Object runReflectiveCall() throws Throwable { return createTest(); } }; test = reflectiveCallable.run(); } // CHECKSTYLE:SKIP : ReflectiveCallable API catch (Throwable e) { return new Fail(e); } Statement statement = methodInvoker(method, test); return statement; }
return new Fail(e);
/** * Creates a new test instance * * @return new instance */ private Object newTestInstance() { try { return new ReflectiveCallable() { @Override protected Object runReflectiveCall() throws Throwable { return createTest(); } }.run(); } catch (final Throwable e) { return new Fail(e); } }
/** * Creates a new test instance * * @return new instance */ private Object newTestInstance() { try { return new ReflectiveCallable() { @Override protected Object runReflectiveCall() throws Throwable { return createTest(); } }.run(); } catch (final Throwable e) { return new Fail(e); } }
public Statement createStatement(final TestClass testClass, final FrameworkMethod method, final Object target, final Statement next, final Description description, final RunNotifier notifier) { Statement statement = next; try { for (Object instance = target; instance != null; instance = getEnclosingInstance(instance)) { final TestClass instanceTestClass = TestClassPool.forClass(instance.getClass()); final List<FrameworkMethod> afterMethods = instanceTestClass.getAnnotatedMethods(After.class); statement = afterMethods.isEmpty() ? statement : new RunAfters(statement, afterMethods, instance); } } catch (final IllegalAccessException e) { statement = new Fail(e); } return statement; } }
public Statement createStatement(final TestClass testClass, final FrameworkMethod method, final Object target, final Statement next, final Description description, final RunNotifier notifier) { Statement statement = next; try { for (Object instance = target; instance != null; instance = getEnclosingInstance(instance)) { final TestClass instanceTestClass = TestClassPool.forClass(instance.getClass()); final List<FrameworkMethod> beforeMethods = instanceTestClass.getAnnotatedMethods(Before.class); statement = beforeMethods.isEmpty() ? statement : new RunBefores(statement, beforeMethods, instance); } } catch (final IllegalAccessException e) { statement = new Fail(e); } return statement; } }
@Override protected Statement methodBlock(FrameworkMethod method) { if (!useDelegate) { return super.methodBlock(method); } 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(method, test); return statement; }
public void run(final TestClass testClass, final Class<?> clazz, final RunNotifier notifier) { try { new HierarchicalContextRunner(clazz).run(notifier); } catch (final Throwable t) { statementExecutor.execute(new Fail(t), notifier, describer.describe(clazz)); } } }
/** * Returns this statement, amended with any test rule statements if * existent. * * @param testClass the class from which to retrieve the test rules * * @return this, amended with any test rule statements if existent */ public Statement getMethodBlock(final TestClass testClass) { Object testInstance; try { testInstance = new ReflectiveCallable() { @Override protected Object runReflectiveCall() throws Throwable { return testClass.getOnlyConstructor().newInstance(); } } .run(); } catch (Throwable e) { return new Fail( e ); } List<TestRule> testRules = testClass.getAnnotatedFieldValues( testInstance, Rule.class, TestRule.class ); return withTestRules( testRules ); }
protected Statement withStateChanges(final Interaction interaction, final Object target, final Statement prevStatement) { if (!interaction.getProviderStates().isEmpty()) { Statement stateChange = prevStatement; for (ProviderState state: interaction.getProviderStates()) { List<Pair<FrameworkMethod, State>> methods = getAnnotatedMethods(testClass, State.class) .stream() .map(method -> { final State annotation = method.getAnnotation(State.class); return new Pair<>(method, annotation); }) .filter(method -> ArrayUtils.contains(method.getSecond().value(), state.getName())) .collect(Collectors.toList()); if (methods.isEmpty()) { return new Fail(new MissingStateChangeMethod("MissingStateChangeMethod: Did not find a test class method annotated with @State(\"" + state.getName() + "\")")); } else { stateChange = new RunStateChanges(stateChange, methods, target, state); } } return stateChange; } else { return prevStatement; } }