Search in sources :

Example 11 with Fail

use of org.junit.internal.runners.statements.Fail 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 12 with Fail

use of org.junit.internal.runners.statements.Fail in project tomee by apache.

the class ValidationRunner method methodBlock.

@Override
protected Statement methodBlock(final FrameworkMethod method) {
    final Object test;
    try {
        test = new ReflectiveCallable() {

            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (final Throwable e) {
        return new Fail(e);
    }
    Statement statement = new InvokeMethod(method, test);
    statement = withBefores(method, test, statement);
    statement = withAfters(method, test, statement);
    return statement;
}
Also used : ReflectiveCallable(org.junit.internal.runners.model.ReflectiveCallable) Statement(org.junit.runners.model.Statement) Fail(org.junit.internal.runners.statements.Fail)

Aggregations

Fail (org.junit.internal.runners.statements.Fail)12 Statement (org.junit.runners.model.Statement)9 ReflectiveCallable (org.junit.internal.runners.model.ReflectiveCallable)6 FrameworkMethod (org.junit.runners.model.FrameworkMethod)4 Method (java.lang.reflect.Method)3 Description (org.junit.runner.Description)3 RunBefores (org.junit.internal.runners.statements.RunBefores)2 Target (au.com.dius.pact.provider.junit.target.Target)1 TestClassAwareTarget (au.com.dius.pact.provider.junit.target.TestClassAwareTarget)1 TestTarget (au.com.dius.pact.provider.junit.target.TestTarget)1 ArrayList (java.util.ArrayList)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1 Test (org.junit.Test)1 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)1 RunAfters (org.junit.internal.runners.statements.RunAfters)1 MultipleFailureException (org.junit.runners.model.MultipleFailureException)1 TestClass (org.junit.runners.model.TestClass)1