Search in sources :

Example 46 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project hazelcast by hazelcast.

the class AbstractHazelcastClassRunner method withBefores.

// Override withBefores to accommodate spawning the member bouncing thread after @Before's have been executed and before @Test
// when MemberBounceRule is in use
@Override
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
    List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(Before.class);
    List<TestRule> testRules = getTestRules(target);
    Statement nextStatement = statement;
    if (!testRules.isEmpty()) {
        for (TestRule rule : testRules) {
            if (rule instanceof BounceMemberRule) {
                nextStatement = ((BounceMemberRule) rule).startBouncing(statement);
            }
        }
    }
    return befores.isEmpty() ? nextStatement : new RunBefores(nextStatement, befores, target);
}
Also used : TestRule(org.junit.rules.TestRule) Statement(org.junit.runners.model.Statement) EmptyStatement(com.hazelcast.util.EmptyStatement) BounceMemberRule(com.hazelcast.test.bounce.BounceMemberRule) RunBefores(org.junit.internal.runners.statements.RunBefores) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 47 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project hazelcast by hazelcast.

the class AbstractHazelcastClassRunner method withAfters.

@Override
protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) {
    List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods(After.class);
    Statement nextStatement = statement;
    List<TestRule> testRules = getTestRules(target);
    if (!testRules.isEmpty()) {
        for (TestRule rule : testRules) {
            if (rule instanceof BounceMemberRule) {
                nextStatement = ((BounceMemberRule) rule).stopBouncing(statement);
            }
        }
    }
    if (THREAD_DUMP_ON_FAILURE) {
        return new ThreadDumpAwareRunAfters(method, nextStatement, afters, target);
    }
    if (afters.isEmpty()) {
        return nextStatement;
    } else {
        return new RunAfters(nextStatement, afters, target);
    }
}
Also used : TestRule(org.junit.rules.TestRule) RunAfters(org.junit.internal.runners.statements.RunAfters) Statement(org.junit.runners.model.Statement) EmptyStatement(com.hazelcast.util.EmptyStatement) BounceMemberRule(com.hazelcast.test.bounce.BounceMemberRule) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 48 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project hibernate-orm by hibernate.

the class CustomParameterized method getParametersMethods.

private List<FrameworkMethod> getParametersMethods() throws Exception {
    List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(Parameterized.Parameters.class);
    SortedMap<Integer, FrameworkMethod> sortedMethods = new TreeMap<Integer, FrameworkMethod>();
    for (FrameworkMethod each : methods) {
        if (each.isPublic()) {
            if (!each.isStatic()) {
                if (getTestClass().getOnlyConstructor().getParameterCount() != 0) {
                    throw new Exception("Method " + each.getMethod() + " is annotated with @Parameters, it is not static and there is no parameter-less constructor!");
                }
            }
            Order order = each.getAnnotation(Order.class);
            int value = order == null ? 0 : order.value();
            FrameworkMethod prev = sortedMethods.put(value, each);
            if (prev != null) {
                throw new Exception(String.format("There are more methods annotated with @Parameters and @Order(value=%d): %s (%s) and %s (%s)", value, prev.getMethod(), prev.getAnnotation(Order.class), each.getMethod(), order));
            }
        } else {
            throw new Exception("Method " + each.getMethod() + " is annotated with @Parameters but it is not public!");
        }
    }
    if (sortedMethods.isEmpty()) {
        throw new Exception("No public static parameters method on class " + getTestClass().getName());
    }
    return new ArrayList<FrameworkMethod>(sortedMethods.values());
}
Also used : Parameterized(org.junit.runners.Parameterized) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) FrameworkMethod(org.junit.runners.model.FrameworkMethod) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException)

Example 49 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project hibernate-orm by hibernate.

the class CustomParameterized method allParameters.

private Iterable<Object[]> allParameters(List<FrameworkMethod> parametersMethods) throws Throwable {
    ArrayList<Iterable<Object[]>> returnedParameters = new ArrayList<Iterable<Object[]>>();
    ArrayList<Object[]> allParameters = new ArrayList<Object[]>();
    Object cachedInstance = null;
    for (FrameworkMethod method : parametersMethods) {
        Object parameters;
        if (method.isStatic()) {
            parameters = method.invokeExplosively(null);
        } else {
            if (cachedInstance == null) {
                cachedInstance = getTestClass().getOnlyConstructor().newInstance();
            }
            parameters = method.invokeExplosively(cachedInstance);
        }
        if (parameters instanceof Iterable) {
            returnedParameters.add((Iterable<Object[]>) parameters);
        } else {
            throw parametersMethodReturnedWrongType(method);
        }
    }
    for (Iterable<Object[]> parameters : returnedParameters) {
        if (allParameters.isEmpty()) {
            for (Object[] array : parameters) {
                allParameters.add(array);
            }
        } else {
            ArrayList<Object[]> newAllParameters = new ArrayList<Object[]>();
            for (Object[] prev : allParameters) {
                for (Object[] array : parameters) {
                    Object[] next = Arrays.copyOf(prev, prev.length + array.length);
                    System.arraycopy(array, 0, next, prev.length, array.length);
                    newAllParameters.add(next);
                }
            }
            allParameters = newAllParameters;
        }
    }
    return allParameters;
}
Also used : ArrayList(java.util.ArrayList) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 50 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project spring-framework by spring-projects.

the class SpringJUnit4ClassRunnerTests method getSpringTimeoutViaMetaAnnotation.

@Test
public void getSpringTimeoutViaMetaAnnotation() throws Exception {
    SpringJUnit4ClassRunner runner = new SpringJUnit4ClassRunner(getClass());
    long timeout = runner.getSpringTimeout(new FrameworkMethod(getClass().getDeclaredMethod("springTimeoutWithMetaAnnotation")));
    assertEquals(10, timeout);
}
Also used : FrameworkMethod(org.junit.runners.model.FrameworkMethod) Test(org.junit.Test)

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