Search in sources :

Example 1 with FrameworkMethod

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

the class CustomParameterized method concatNames.

private String concatNames(List<FrameworkMethod> parametersMethods) {
    StringBuilder sb = new StringBuilder();
    for (FrameworkMethod method : parametersMethods) {
        Parameterized.Parameters parameters = method.getAnnotation(Parameterized.Parameters.class);
        if (sb.length() != 0) {
            sb.append(", ");
        }
        sb.append(parameters.name());
    }
    return sb.toString();
}
Also used : Parameterized(org.junit.runners.Parameterized) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 2 with FrameworkMethod

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

the class CustomRunner method doComputation.

protected List<FrameworkMethod> doComputation() {
    // Next, get all the test methods as understood by JUnit
    final List<FrameworkMethod> methods = super.computeTestMethods();
    // Now process that full list of test methods and build our custom result
    final List<FrameworkMethod> result = new ArrayList<FrameworkMethod>();
    final boolean doValidation = Boolean.getBoolean(Helper.VALIDATE_FAILURE_EXPECTED);
    int testCount = 0;
    Ignore virtualIgnore;
    for (FrameworkMethod frameworkMethod : methods) {
        // potentially ignore based on expected failure
        final FailureExpected failureExpected = Helper.locateAnnotation(FailureExpected.class, frameworkMethod, getTestClass());
        if (failureExpected != null && !doValidation) {
            virtualIgnore = new IgnoreImpl(Helper.extractIgnoreMessage(failureExpected, frameworkMethod));
        } else {
            virtualIgnore = convertSkipToIgnore(frameworkMethod);
        }
        testCount++;
        log.trace("adding test " + Helper.extractTestName(frameworkMethod) + " [#" + testCount + "]");
        result.add(new ExtendedFrameworkMethod(frameworkMethod, virtualIgnore, failureExpected));
    }
    return result;
}
Also used : Ignore(org.junit.Ignore) ArrayList(java.util.ArrayList) FailureExpected(org.hibernate.testing.FailureExpected) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 3 with FrameworkMethod

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

the class ConcurrentParameterizedRunner method runChild.

@Override
protected void runChild(final FrameworkMethod method, final RunNotifier notifier) {
    notifier.fireTestStarted(describeChild(method));
    final Object testInstance;
    try {
        // get the test parameter iterator first
        final List<FrameworkMethod> parameterMethods = getTestClass().getAnnotatedMethods(Parameterized.Parameters.class);
        final Iterable<Object[]> parameters = (Iterable<Object[]>) parameterMethods.get(0).getMethod().invoke(null);
        // then create the test instance
        testInstance = super.createTest();
        // now run the before methods
        List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(Before.class);
        for (FrameworkMethod before : befores) {
            before.getMethod().invoke(testInstance);
        }
        // and launch as meny test method invocations as many parameters is available
        final Iterator<Object[]> paramIterator = parameters.iterator();
        final Method javaTestMethod = method.getMethod();
        final AtomicInteger submitted = new AtomicInteger(0);
        while (paramIterator.hasNext()) {
            final Object[] javaMethodArgs = paramIterator.next();
            submitted.incrementAndGet();
            executor.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        javaTestMethod.invoke(testInstance, javaMethodArgs);
                    } catch (IllegalAccessException ex) {
                        notifier.fireTestFailure(new Failure(describeChild(method), ex));
                    } catch (IllegalArgumentException ex) {
                        notifier.fireTestFailure(new Failure(describeChild(method), ex));
                    } catch (InvocationTargetException ex) {
                        notifier.fireTestFailure(new Failure(describeChild(method), ex));
                    } finally {
                        submitted.decrementAndGet();
                    }
                }
            });
        }
        // wait until everything is done
        while (submitted.intValue() > 0) {
            LOGGER.info(String.format("Waiting for %d requests to finish...%n", submitted.intValue()));
            try {
                Thread.sleep(FINISH_WAIT_CYCLE_MS);
            } catch (InterruptedException e) {
            }
        }
        // and launch the after party..
        List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods(After.class);
        for (FrameworkMethod after : afters) {
            after.getMethod().invoke(testInstance);
        }
    } catch (Exception ex) {
        notifier.fireTestFailure(new Failure(describeChild(method), ex));
        return;
    }
    notifier.fireTestFinished(describeChild(method));
}
Also used : FrameworkMethod(org.junit.runners.model.FrameworkMethod) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Parameterized(org.junit.runners.Parameterized) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Failure(org.junit.runner.notification.Failure)

Example 4 with FrameworkMethod

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

the class ConcurrentRunner method runThemAll.

private void runThemAll(final List<FrameworkMethod> methods, final RunNotifier notifier) {
    final Object testInstance;
    try {
        testInstance = super.createTest();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    // run the before methods
    List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(Before.class);
    for (FrameworkMethod before : befores) {
        try {
            before.getMethod().invoke(testInstance);
        } catch (Exception ex) {
            LOGGER.log(java.util.logging.Level.SEVERE, null, ex);
        }
        final AtomicInteger submitted = new AtomicInteger(0);
        for (final FrameworkMethod method : methods) {
            try {
                notifier.fireTestStarted(describeChild(method));
                final Method javaTestMethod = method.getMethod();
                final Object[] javaMethodArgs = new Object[] {};
                submitted.incrementAndGet();
                executor.submit(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            javaTestMethod.invoke(testInstance, javaMethodArgs);
                        } catch (Exception ex) {
                            notifier.fireTestFailure(new Failure(describeChild(method), ex));
                        } finally {
                            submitted.decrementAndGet();
                        }
                    }
                });
            } catch (Exception ex) {
                notifier.fireTestFailure(new Failure(describeChild(method), ex));
                return;
            }
            notifier.fireTestFinished(describeChild(method));
        }
        // wait until everything is done
        while (submitted.intValue() > 0) {
            LOGGER.info(String.format("Waiting for %d requests to finish...%n", submitted.intValue()));
            try {
                Thread.sleep(FINISH_WAIT_CYCLE_MS);
            } catch (InterruptedException e) {
            }
        }
        // and launch the after party..
        List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods(After.class);
        for (FrameworkMethod after : afters) {
            try {
                after.getMethod().invoke(testInstance);
            } catch (Exception ex) {
                LOGGER.log(Level.SEVERE, null, ex);
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Failure(org.junit.runner.notification.Failure)

Example 5 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project junit4 by junit-team.

the class CategoryValidatorTest method errorIsAddedWhenCategoryIsUsedWithBefore.

@Test
public void errorIsAddedWhenCategoryIsUsedWithBefore() {
    FrameworkMethod method = new TestClass(CategoryTest.class).getAnnotatedMethods(Before.class).get(0);
    testAndAssertErrorMessage(method, "@Before can not be combined with @Category");
}
Also used : Before(org.junit.Before) TestClass(org.junit.runners.model.TestClass) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Test(org.junit.Test)

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