Search in sources :

Example 1 with RunAfters

use of org.junit.internal.runners.statements.RunAfters in project intellij-community by JetBrains.

the class GuiTestRunner method methodBlock.

@Override
protected Statement methodBlock(FrameworkMethod method) {
    FrameworkMethod newMethod;
    try {
        if (Arrays.stream(getTestClass().getAnnotations()).anyMatch(annotation -> annotation instanceof ParentPlugin)) {
            loadClassesWithNewPluginClassLoader();
        } else {
            loadClassesWithIdeClassLoader();
        }
        Method methodFromClassLoader = myTestClass.getJavaClass().getMethod(method.getName());
        newMethod = new FrameworkMethod(methodFromClassLoader);
    } catch (Exception e) {
        return new Fail(e);
    }
    Object test;
    try {
        test = new ReflectiveCallable() {

            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (Throwable e) {
        return new Fail(e);
    }
    Statement statement = methodInvoker(newMethod, test);
    List<FrameworkMethod> beforeMethods = myTestClass.getAnnotatedMethods(Before.class);
    if (!beforeMethods.isEmpty()) {
        statement = new RunBefores(statement, beforeMethods, test);
    }
    List<FrameworkMethod> afterMethods = myTestClass.getAnnotatedMethods(After.class);
    if (!afterMethods.isEmpty()) {
        statement = new RunAfters(statement, afterMethods, test);
    }
    return statement;
}
Also used : RunAfters(org.junit.internal.runners.statements.RunAfters) ReflectiveCallable(org.junit.internal.runners.model.ReflectiveCallable) Statement(org.junit.runners.model.Statement) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) RunBefores(org.junit.internal.runners.statements.RunBefores) FrameworkMethod(org.junit.runners.model.FrameworkMethod) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Fail(org.junit.internal.runners.statements.Fail)

Example 2 with RunAfters

use of org.junit.internal.runners.statements.RunAfters 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)

Aggregations

RunAfters (org.junit.internal.runners.statements.RunAfters)2 FrameworkMethod (org.junit.runners.model.FrameworkMethod)2 Statement (org.junit.runners.model.Statement)2 BounceMemberRule (com.hazelcast.test.bounce.BounceMemberRule)1 EmptyStatement (com.hazelcast.util.EmptyStatement)1 Method (java.lang.reflect.Method)1 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)1 ReflectiveCallable (org.junit.internal.runners.model.ReflectiveCallable)1 Fail (org.junit.internal.runners.statements.Fail)1 RunBefores (org.junit.internal.runners.statements.RunBefores)1 TestRule (org.junit.rules.TestRule)1