Search in sources :

Example 1 with MethodRule

use of org.junit.rules.MethodRule in project spock by spockframework.

the class MethodRuleInterceptor method intercept.

@Override
public void intercept(final IMethodInvocation invocation) throws Throwable {
    Statement statement = createBaseStatement(invocation);
    FrameworkMethod method = createFrameworkMethod(invocation);
    for (FieldInfo field : ruleFields) {
        MethodRule rule = (MethodRule) getRuleInstance(field, invocation.getInstance());
        statement = rule.apply(statement, method, invocation.getInstance());
    }
    statement.evaluate();
}
Also used : MethodRule(org.junit.rules.MethodRule) FieldInfo(org.spockframework.runtime.model.FieldInfo)

Example 2 with MethodRule

use of org.junit.rules.MethodRule in project querydsl by querydsl.

the class HibernateTestRunner method rules.

@Override
protected List<MethodRule> rules(Object test) {
    assertTrue(String.format("In order to use the %s for %s, it should (directly or indirectly) implement %s", HibernateTestRunner.class.getSimpleName(), test.getClass(), HibernateTest.class), test instanceof HibernateTest);
    List<MethodRule> rules = super.rules(test);
    rules.add(new MethodRule() {

        @Override
        public Statement apply(final Statement base, FrameworkMethod method, final Object target) {
            return new Statement() {

                @Override
                public void evaluate() throws Throwable {
                    ((HibernateTest) target).setSession(session);
                    base.evaluate();
                }
            };
        }
    });
    return rules;
}
Also used : MethodRule(org.junit.rules.MethodRule) Statement(org.junit.runners.model.Statement) HibernateTest(com.querydsl.jpa.HibernateTest) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 3 with MethodRule

use of org.junit.rules.MethodRule in project querydsl by querydsl.

the class JPATestRunner method rules.

@Override
protected List<MethodRule> rules(Object test) {
    Assert.assertTrue(String.format("In order to use the %s for %s, it should (directly or indirectly) implement %s", JPATestRunner.class.getSimpleName(), test.getClass(), JPATest.class), test instanceof JPATest);
    List<MethodRule> rules = super.rules(test);
    rules.add(new MethodRule() {

        @Override
        public Statement apply(final Statement base, FrameworkMethod method, final Object target) {
            return new Statement() {

                @Override
                public void evaluate() throws Throwable {
                    ((JPATest) target).setEntityManager(entityManager);
                    base.evaluate();
                }
            };
        }
    });
    return rules;
}
Also used : JPATest(com.querydsl.jpa.JPATest) MethodRule(org.junit.rules.MethodRule) Statement(org.junit.runners.model.Statement) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 4 with MethodRule

use of org.junit.rules.MethodRule in project tomee by apache.

the class TomEEEmbeddedSingleRunner method rules.

@Override
protected List<MethodRule> rules(final Object test) {
    final List<MethodRule> rules = super.rules(test);
    rules.add(new MethodRule() {

        @Override
        public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
            return new Statement() {

                @Override
                public void evaluate() throws Throwable {
                    BASE.start(test);
                    BASE.composerInject(target);
                    base.evaluate();
                }
            };
        }
    });
    return rules;
}
Also used : MethodRule(org.junit.rules.MethodRule) Statement(org.junit.runners.model.Statement) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 5 with MethodRule

use of org.junit.rules.MethodRule in project tomee by apache.

the class SingleApplicationComposerRunner method rules.

@Override
protected List<MethodRule> rules(final Object test) {
    final List<MethodRule> rules = super.rules(test);
    rules.add(new MethodRule() {

        @Override
        public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
            return new Statement() {

                @Override
                public void evaluate() throws Throwable {
                    BASE.start(getTestClass().getJavaClass());
                    BASE.composerInject(target);
                    base.evaluate();
                }
            };
        }
    });
    return rules;
}
Also used : MethodRule(org.junit.rules.MethodRule) Statement(org.junit.runners.model.Statement) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Aggregations

MethodRule (org.junit.rules.MethodRule)9 FrameworkMethod (org.junit.runners.model.FrameworkMethod)5 Statement (org.junit.runners.model.Statement)5 TestRule (org.junit.rules.TestRule)2 FieldInfo (org.spockframework.runtime.model.FieldInfo)2 HibernateTest (com.querydsl.jpa.HibernateTest)1 JPATest (com.querydsl.jpa.JPATest)1 ArrayList (java.util.ArrayList)1