Search in sources :

Example 56 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod 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)

Example 57 with FrameworkMethod

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

the class PerTestClassLoaderRunner method methodBlock.

@Override
protected Statement methodBlock(FrameworkMethod method) {
    FrameworkMethod newMethod = null;
    try {
        // Need the class from the custom loader now, so lets load the class.
        loadClassesWithCustomClassLoader();
        // The method as parameter is from the original class and thus not found in our
        // class loaded by the custom name (reflection is class loader sensitive)
        // So find the same method but now in the class from the class Loader.
        Method methodFromNewlyLoadedClass = testClassFromClassLoader.getJavaClass().getMethod(method.getName());
        newMethod = new FrameworkMethod(methodFromNewlyLoadedClass);
    } catch (ClassNotFoundException e) {
        // Show any problem nicely as a JUnit Test failure.
        return new Fail(e);
    } catch (SecurityException e) {
        return new Fail(e);
    } catch (NoSuchMethodException e) {
        return new Fail(e);
    }
    // We can carry out the normal JUnit functionality with our newly discovered method now.
    return super.methodBlock(newMethod);
}
Also used : FrameworkMethod(org.junit.runners.model.FrameworkMethod) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Fail(org.junit.internal.runners.statements.Fail)

Example 58 with FrameworkMethod

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

the class PerformanceRunner method validatePerformanceTestsExecutionStrategy.

private void validatePerformanceTestsExecutionStrategy(List<Throwable> errors) {
    for (FrameworkMethod method : getTestClass().getAnnotatedMethods(PerformanceTest.class)) {
        int warmUpInvocations = getWarmUpInvocations(method);
        int warmUpTime = getWarmUpTime(method);
        if (warmUpInvocations <= 0 && warmUpTime <= 0) {
            errors.add(new Error("Method " + method.getName() + "() should provide a valid warmUpInvocations or warmUpTime"));
        }
        if (warmUpInvocations > 0 && warmUpTime > 0) {
            errors.add(new Error("Method " + method.getName() + "() provides both a valid warmUpInvocations and a warmUpTime"));
        }
        int runInvocations = getRunInvocations(method);
        int runTime = getRunTime(method);
        if (runInvocations <= 0 && runTime <= 0) {
            errors.add(new Error("Method " + method.getName() + "() should provide a valid runInvocations or runTime"));
        }
        if (runInvocations > 0 && runTime > 0) {
            errors.add(new Error("Method " + method.getName() + "() provides both a valid runInvocations or runTime"));
        }
    }
}
Also used : InitializationError(org.junit.runners.model.InitializationError) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Aggregations

FrameworkMethod (org.junit.runners.model.FrameworkMethod)58 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)9 MethodRule (org.junit.rules.MethodRule)6 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