Search in sources :

Example 31 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project sling by apache.

the class RunAfters method evaluate.

@Override
public void evaluate() throws Throwable {
    List<Throwable> errors = new ArrayList<Throwable>();
    try {
        next.evaluate();
    } catch (Throwable e) {
        errors.add(e);
    } finally {
        for (FrameworkMethod each : afters) {
            try {
                each.invokeExplosively(target);
            } catch (Throwable e) {
                errors.add(e);
            }
        }
    }
    MultipleFailureException.assertEmpty(errors);
}
Also used : ArrayList(java.util.ArrayList) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 32 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project sling by apache.

the class PerformanceRunner method readListenersFromStaticMethods.

private List<Listener> readListenersFromStaticMethods() throws Throwable {
    List<Listener> listeners = new ArrayList<Listener>();
    for (FrameworkMethod method : getTestClass().getAnnotatedMethods(Listen.class)) {
        Listener listener = (Listener) method.invokeExplosively(null);
        if (listener == null) {
            throw new IllegalArgumentException("Method " + method.getName() + "() should not return null");
        }
        listeners.add(listener);
    }
    return listeners;
}
Also used : ArrayList(java.util.ArrayList) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 33 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project java-crud-api by kolchagov.

the class OrderedTestRunner method computeTestMethods.

/*
     * (non-Javadoc)
     * 
     * @see org.junit.runners.BlockJUnit4ClassRunner#computeTestMethods()
     */
@Override
protected List<FrameworkMethod> computeTestMethods() {
    // get all methods to be tested
    List<FrameworkMethod> toSort = super.computeTestMethods();
    if (toSort.isEmpty())
        return toSort;
    // a map containing <line_number, method>
    final Map<Integer, FrameworkMethod> testMethods = new TreeMap<>();
    // check that all methods here are declared in the same class, we don't
    // deal with test methods from superclasses that haven't been overridden
    Class<?> clazz = getDeclaringClass(toSort);
    if (clazz == null) {
        // fail explicitly
        System.err.println("OrderedTestRunner can only run test classes that" + " don't have test methods inherited from superclasses");
        return Collections.emptyList();
    }
    // use Javassist to figure out line numbers for methods
    ClassPool pool = ClassPool.getDefault();
    try {
        CtClass cc = pool.get(clazz.getName());
        // all methods in toSort are declared in the same class, we checked
        for (FrameworkMethod m : toSort) {
            String methodName = m.getName();
            CtMethod method = cc.getDeclaredMethod(methodName);
            testMethods.put(method.getMethodInfo().getLineNumber(0), m);
        }
    } catch (NotFoundException e) {
        e.printStackTrace();
    }
    return new ArrayList<>(testMethods.values());
}
Also used : CtClass(javassist.CtClass) ClassPool(javassist.ClassPool) NotFoundException(javassist.NotFoundException) FrameworkMethod(org.junit.runners.model.FrameworkMethod) CtMethod(javassist.CtMethod)

Example 34 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod 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 {
                    start(getTestClass().getJavaClass());
                    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 35 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project tomee by apache.

the class ApplicationComposer method rules.

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

        public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
            return new DeployApplication(target, base, delegate);
        }
    });
    return rules;
}
Also used : MethodRule(org.junit.rules.MethodRule) Statement(org.junit.runners.model.Statement) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Aggregations

FrameworkMethod (org.junit.runners.model.FrameworkMethod)59 ArrayList (java.util.ArrayList)15 Statement (org.junit.runners.model.Statement)13 TestClass (org.junit.runners.model.TestClass)13 Test (org.junit.Test)11 Method (java.lang.reflect.Method)10 MethodRule (org.junit.rules.MethodRule)5 Fail (org.junit.internal.runners.statements.Fail)4 RunBefores (org.junit.internal.runners.statements.RunBefores)4 TestRule (org.junit.rules.TestRule)4 Parameterized (org.junit.runners.Parameterized)3 Interaction (au.com.dius.pact.model.Interaction)2 ConsumerInfo (au.com.dius.pact.provider.ConsumerInfo)2 ProviderInfo (au.com.dius.pact.provider.ProviderInfo)2 ProviderVerifier (au.com.dius.pact.provider.ProviderVerifier)2 Provider (au.com.dius.pact.provider.junit.Provider)2 TargetRequestFilter (au.com.dius.pact.provider.junit.TargetRequestFilter)2 BounceMemberRule (com.hazelcast.test.bounce.BounceMemberRule)2 EmptyStatement (com.hazelcast.util.EmptyStatement)2 URL (java.net.URL)2