Search in sources :

Example 41 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project restfuse by eclipsesource.

the class HttpJUnitRunner method computeTestMethods.

@Override
protected List<FrameworkMethod> computeTestMethods() {
    ArrayList<FrameworkMethod> result = new ArrayList<FrameworkMethod>();
    result.addAll(getTestClass().getAnnotatedMethods(HttpTest.class));
    List<FrameworkMethod> testAnnotatedMethods = getTestClass().getAnnotatedMethods(Test.class);
    for (FrameworkMethod method : testAnnotatedMethods) {
        if (!result.contains(method)) {
            result.add(method);
        }
    }
    Collections.sort(result, new HttpOrderComparator());
    return result;
}
Also used : HttpTest(com.eclipsesource.restfuse.annotation.HttpTest) ArrayList(java.util.ArrayList) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 42 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project materialistic by hidroh.

the class ParameterizedTestRunner method getParametersMethod.

private FrameworkMethod getParametersMethod() throws Exception {
    TestClass testClass = getTestClass();
    List<FrameworkMethod> methods = testClass.getAnnotatedMethods(Parameters.class);
    for (FrameworkMethod each : methods) {
        int modifiers = each.getMethod().getModifiers();
        if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)) {
            return each;
        }
    }
    throw new Exception("No public static parameters method on class " + testClass.getName());
}
Also used : TestClass(org.junit.runners.model.TestClass) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 43 with FrameworkMethod

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

the class CamelCdiRunner method getChildren.

@Override
protected List<FrameworkMethod> getChildren() {
    List<FrameworkMethod> children = super.getChildren();
    boolean hasDefinedOrder = false;
    for (FrameworkMethod method : children) {
        if (method.getAnnotation(Order.class) != null) {
            hasDefinedOrder = true;
        }
    }
    if (hasDefinedOrder) {
        List<FrameworkMethod> sorted = new ArrayList<>(children);
        Collections.sort(sorted, new FrameworkMethodSorter());
        return sorted;
    }
    return children;
}
Also used : ArrayList(java.util.ArrayList) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 44 with FrameworkMethod

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

the class ParentRunnerClassLoaderTest method testBackwardCompatibilityWithOverrideGetName.

@Test
public void testBackwardCompatibilityWithOverrideGetName() throws Exception {
    final Class<TestWithClassRule> originalTestClass = TestWithClassRule.class;
    final Class<?> waitClass = ParentRunnerClassLoaderTest.class;
    ParentRunner<FrameworkMethod> subParentRunner = new BlockJUnit4ClassRunner(originalTestClass) {

        @Override
        protected String getName() {
            return waitClass.getName();
        }
    };
    Description description = subParentRunner.getDescription();
    Class<?> result = description.getTestClass();
    assertEquals("Subclass of ParentRunner can override getName method and specify another test class for run, " + "we should  maintain backwards compatibility with JUnit 4.12", waitClass, result);
}
Also used : Description(org.junit.runner.Description) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Test(org.junit.Test)

Example 45 with FrameworkMethod

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

the class AbstractHazelcastClassRunner method getTestRules.

@Override
protected List<TestRule> getTestRules(Object target) {
    List<TestRule> testRules = super.getTestRules(target);
    Set<Class<? extends TestRule>> testRuleClasses = new HashSet<Class<? extends TestRule>>();
    TestClass testClass = getTestClass();
    // find the required test rule classes from test class itself
    Annotation[] classAnnotations = testClass.getAnnotations();
    for (Annotation annotation : classAnnotations) {
        Class<? extends Annotation> annotationType = annotation.annotationType();
        AutoRegisteredTestRule autoFilterRule = annotationType.getAnnotation(AutoRegisteredTestRule.class);
        if (autoFilterRule != null) {
            Class<? extends TestRule> testRuleClass = autoFilterRule.testRule();
            testRuleClasses.add(testRuleClass);
        }
    }
    // find the required test rule classes from methods
    List<FrameworkMethod> annotatedMethods = testClass.getAnnotatedMethods();
    for (FrameworkMethod annotatedMethod : annotatedMethods) {
        Annotation[] methodAnnotations = annotatedMethod.getAnnotations();
        for (Annotation annotation : methodAnnotations) {
            Class<? extends Annotation> annotationType = annotation.annotationType();
            AutoRegisteredTestRule autoFilterRule = annotationType.getAnnotation(AutoRegisteredTestRule.class);
            if (autoFilterRule != null) {
                Class<? extends TestRule> testRuleClass = autoFilterRule.testRule();
                testRuleClasses.add(testRuleClass);
            }
        }
    }
    // create and register test rules
    for (Class<? extends TestRule> testRuleClass : testRuleClasses) {
        try {
            TestRule testRule = testRuleClass.newInstance();
            testRules.add(testRule);
        } catch (Throwable t) {
            System.err.println("Unable to create test rule instance of test rule class " + testRuleClass.getName() + " because of " + t);
        }
    }
    return testRules;
}
Also used : TestClass(org.junit.runners.model.TestClass) Annotation(java.lang.annotation.Annotation) TestRule(org.junit.rules.TestRule) TestClass(org.junit.runners.model.TestClass) FrameworkMethod(org.junit.runners.model.FrameworkMethod) HashSet(java.util.HashSet)

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