Search in sources :

Example 6 with Fail

use of org.junit.internal.runners.statements.Fail in project android by JetBrains.

the class GuiTestRunner method methodBlock.

@Override
protected Statement methodBlock(FrameworkMethod method) {
    if (GraphicsEnvironment.isHeadless()) {
        // checked first because IdeTestApplication.getInstance below (indirectly) throws an AWTException in a headless environment
        return falseAssumption("headless environment");
    }
    Method methodFromClassLoader;
    try {
        ClassLoader ideClassLoader = IdeTestApplication.getInstance().getIdeClassLoader();
        Thread.currentThread().setContextClassLoader(ideClassLoader);
        myTestClass = new TestClass(ideClassLoader.loadClass(getTestClass().getJavaClass().getName()));
        methodFromClassLoader = myTestClass.getJavaClass().getMethod(method.getName());
    } catch (Exception e) {
        return new Fail(e);
    }
    return super.methodBlock(new FrameworkMethod(methodFromClassLoader));
}
Also used : TestClass(org.junit.runners.model.TestClass) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Method(java.lang.reflect.Method) AssumptionViolatedException(org.junit.AssumptionViolatedException) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Fail(org.junit.internal.runners.statements.Fail)

Example 7 with Fail

use of org.junit.internal.runners.statements.Fail in project pact-jvm by DiUS.

the class InteractionRunner method interactionBlock.

protected Statement interactionBlock(final Interaction interaction) {
    //1. prepare object
    //2. get Target
    //3. run Rule`s
    //4. run Before`s
    //5. run OnStateChange`s
    //6. run test
    //7. run After`s
    final Object test;
    try {
        test = new ReflectiveCallable() {

            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (Throwable e) {
        return new Fail(e);
    }
    final Target target = testClass.getAnnotatedFieldValues(test, TestTarget.class, Target.class).get(0);
    if (target instanceof TestClassAwareTarget) {
        ((TestClassAwareTarget) target).setTestClass(testClass, test);
    }
    Statement statement = new Statement() {

        @Override
        public void evaluate() throws Throwable {
            target.testInteraction(pact.getConsumer().getName(), interaction);
        }
    };
    statement = withStateChanges(interaction, test, statement);
    statement = withBefores(interaction, test, statement);
    statement = withRules(interaction, test, statement);
    statement = withAfters(interaction, test, statement);
    return statement;
}
Also used : TestClassAwareTarget(au.com.dius.pact.provider.junit.target.TestClassAwareTarget) TestTarget(au.com.dius.pact.provider.junit.target.TestTarget) Target(au.com.dius.pact.provider.junit.target.Target) ReflectiveCallable(org.junit.internal.runners.model.ReflectiveCallable) TestTarget(au.com.dius.pact.provider.junit.target.TestTarget) Statement(org.junit.runners.model.Statement) Fail(org.junit.internal.runners.statements.Fail) TestClassAwareTarget(au.com.dius.pact.provider.junit.target.TestClassAwareTarget)

Example 8 with Fail

use of org.junit.internal.runners.statements.Fail in project tomee by apache.

the class MetaRunner method methodBlock.

@Override
protected Statement methodBlock(final FrameworkMethod method) {
    final Object test;
    try {
        test = new ReflectiveCallable() {

            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (final Throwable e) {
        return new Fail(e);
    }
    Statement statement = new MetaTest.$(method, test);
    statement = withBefores(method, test, statement);
    statement = withAfters(method, test, statement);
    return statement;
}
Also used : ReflectiveCallable(org.junit.internal.runners.model.ReflectiveCallable) Statement(org.junit.runners.model.Statement) Fail(org.junit.internal.runners.statements.Fail)

Example 9 with Fail

use of org.junit.internal.runners.statements.Fail 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);
    }
}
Also used : Description(org.junit.runner.Description) Statement(org.junit.runners.model.Statement) Fail(org.junit.internal.runners.statements.Fail)

Example 10 with Fail

use of org.junit.internal.runners.statements.Fail in project pact-jvm by DiUS.

the class InteractionRunner method withStateChanges.

protected Statement withStateChanges(final Interaction interaction, final Object target, final Statement statement) {
    if (StringUtils.isNotEmpty(interaction.getProviderState())) {
        final String state = interaction.getProviderState();
        final List<FrameworkMethod> onStateChange = new ArrayList<FrameworkMethod>();
        for (FrameworkMethod ann : testClass.getAnnotatedMethods(State.class)) {
            for (String annotationState : ann.getAnnotation(State.class).value()) {
                if (annotationState.equalsIgnoreCase(state)) {
                    onStateChange.add(ann);
                    break;
                }
            }
        }
        if (onStateChange.isEmpty()) {
            return new Fail(new MissingStateChangeMethod("MissingStateChangeMethod: Did not find a test class method annotated with @State(\"" + state + "\")"));
        }
        return new RunBefores(statement, onStateChange, target);
    } else {
        return statement;
    }
}
Also used : ArrayList(java.util.ArrayList) RunBefores(org.junit.internal.runners.statements.RunBefores) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Fail(org.junit.internal.runners.statements.Fail)

Aggregations

Fail (org.junit.internal.runners.statements.Fail)12 Statement (org.junit.runners.model.Statement)9 ReflectiveCallable (org.junit.internal.runners.model.ReflectiveCallable)6 FrameworkMethod (org.junit.runners.model.FrameworkMethod)4 Method (java.lang.reflect.Method)3 Description (org.junit.runner.Description)3 RunBefores (org.junit.internal.runners.statements.RunBefores)2 Target (au.com.dius.pact.provider.junit.target.Target)1 TestClassAwareTarget (au.com.dius.pact.provider.junit.target.TestClassAwareTarget)1 TestTarget (au.com.dius.pact.provider.junit.target.TestTarget)1 ArrayList (java.util.ArrayList)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1 Test (org.junit.Test)1 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)1 RunAfters (org.junit.internal.runners.statements.RunAfters)1 MultipleFailureException (org.junit.runners.model.MultipleFailureException)1 TestClass (org.junit.runners.model.TestClass)1