Search in sources :

Example 1 with TestClassAwareTarget

use of au.com.dius.pact.provider.junit.target.TestClassAwareTarget 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)

Aggregations

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 ReflectiveCallable (org.junit.internal.runners.model.ReflectiveCallable)1 Fail (org.junit.internal.runners.statements.Fail)1 Statement (org.junit.runners.model.Statement)1