Java Code Examples for org.junit.runners.model.FrameworkMethod#getMethod()
The following examples show how to use
org.junit.runners.model.FrameworkMethod#getMethod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JGivenMethodRule.java From JGiven with Apache License 2.0 | 6 votes |
@VisibleForTesting static List<NamedArgument> getNamedArguments( Statement base, FrameworkMethod method, Object target ) { AccessibleObject constructorOrMethod = method.getMethod(); List<Object> arguments = Collections.emptyList(); if( DATAPROVIDER_FRAMEWORK_METHOD.equals( method.getClass().getCanonicalName() ) ) { arguments = getArgumentsFrom( method, "parameters" ); } if( JUNITPARAMS_STATEMENT.equals( base.getClass().getCanonicalName() ) ) { arguments = getArgumentsFrom( base, "params" ); } if( isParameterizedTest( target ) ) { Constructor<?> constructor = getOnlyConstructor( target.getClass() ); constructorOrMethod = constructor; arguments = getArgumentsFrom( constructor, target ); } return ParameterNameUtil.mapArgumentsWithParameterNames( constructorOrMethod, arguments ); }
Example 2
Source File: BurstJUnit4.java From burst with Apache License 2.0 | 6 votes |
static List<Runner> explode(Class<?> cls) throws InitializationError { checkNotNull(cls, "cls"); TestClass testClass = new TestClass(cls); List<FrameworkMethod> testMethods = testClass.getAnnotatedMethods(Test.class); List<FrameworkMethod> burstMethods = new ArrayList<>(testMethods.size()); for (FrameworkMethod testMethod : testMethods) { Method method = testMethod.getMethod(); for (Enum<?>[] methodArgs : Burst.explodeArguments(method)) { burstMethods.add(new BurstMethod(method, methodArgs)); } } TestConstructor constructor = BurstableConstructor.findSingle(cls); Enum<?>[][] constructorArgsList = Burst.explodeArguments(constructor); List<Runner> burstRunners = new ArrayList<>(constructorArgsList.length); for (Enum<?>[] constructorArgs : constructorArgsList) { burstRunners.add(new BurstRunner(cls, constructor, constructorArgs, burstMethods)); } return unmodifiableList(burstRunners); }
Example 3
Source File: BytecoderUnitTestRunner.java From Bytecoder with Apache License 2.0 | 6 votes |
private void testJVMBackendFrameworkMethod(final FrameworkMethod aFrameworkMethod, final RunNotifier aRunNotifier) { if ("".equals(System.getProperty("BYTECODER_DISABLE_JVMTESTS", ""))) { final TestClass testClass = getTestClass(); final Description theDescription = Description.createTestDescription(testClass.getJavaClass(), aFrameworkMethod.getName() + " JVM Target"); aRunNotifier.fireTestStarted(theDescription); try { // Simply invoke using reflection final Object theInstance = testClass.getJavaClass().getDeclaredConstructor().newInstance(); final Method theMethod = aFrameworkMethod.getMethod(); theMethod.invoke(theInstance); aRunNotifier.fireTestFinished(theDescription); } catch (final Exception e) { aRunNotifier.fireTestFailure(new Failure(theDescription, e)); } } }
Example 4
Source File: TestGenerator.java From junit-dataprovider with Apache License 2.0 | 6 votes |
private List<FrameworkMethod> explodeTestMethod(FrameworkMethod testMethod, Object data, DataProvider dataProvider) { Method method = testMethod.getMethod(); List<Object[]> converted = dataConverter.convert(data, method.isVarArgs(), method.getParameterTypes(), dataProvider); if (converted.isEmpty()) { throw new IllegalArgumentException("Could not create test methods using probably 'null' or 'empty' dataprovider"); } int idx = 0; List<FrameworkMethod> result = new ArrayList<FrameworkMethod>(); for (Object[] parameters : converted) { result.add(new DataProviderFrameworkMethod(method, idx++, parameters, dataProvider.format(), dataProvider.formatter())); } return result; }
Example 5
Source File: BaseRunner.java From baratine with GNU General Public License v2.0 | 6 votes |
@Override protected void scanAnnotatedMembers(Map<Class<? extends Annotation>,List<FrameworkMethod>> methodsForAnnotations, Map<Class<? extends Annotation>,List<FrameworkField>> fieldsForAnnotations) { super.scanAnnotatedMembers(methodsForAnnotations, fieldsForAnnotations); for (Map.Entry<Class<? extends Annotation>,List<FrameworkMethod>> entry : methodsForAnnotations.entrySet()) { if (Test.class.equals(entry.getKey())) { List<FrameworkMethod> methods = new ArrayList<>(); for (FrameworkMethod method : entry.getValue()) { Method javaMethod = method.getMethod(); if (javaMethod.getParameterTypes().length > 0) { methods.add(new BaratineFrameworkMethod(javaMethod)); } else { methods.add(method); } } entry.setValue(methods); } } }
Example 6
Source File: SpringMethodRule.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Wrap the supplied {@link Statement} with a {@code RunAfterTestMethodCallbacks} statement. * @see RunAfterTestMethodCallbacks */ private Statement withAfterTestMethodCallbacks(Statement statement, FrameworkMethod frameworkMethod, Object testInstance, TestContextManager testContextManager) { return new RunAfterTestMethodCallbacks( statement, testInstance, frameworkMethod.getMethod(), testContextManager); }
Example 7
Source File: DesugarRunner.java From bazel with Apache License 2.0 | 5 votes |
private static void validateParameterValueSource( FrameworkMethod eachTestMethod, List<Throwable> errors) { Method reflectMethod = eachTestMethod.getMethod(); long numOfParamsWithValueRequest = Arrays.stream(reflectMethod.getParameters()) .filter(parameter -> parameter.isAnnotationPresent(FromParameterValueSource.class)) .count(); if (numOfParamsWithValueRequest > 0) { List<ParameterValueSource> parameterValueSources = new ArrayList<>(); if (reflectMethod.isAnnotationPresent(ParameterValueSource.class)) { parameterValueSources.add(reflectMethod.getDeclaredAnnotation(ParameterValueSource.class)); } if (reflectMethod.isAnnotationPresent(ParameterValueSourceSet.class)) { Collections.addAll( parameterValueSources, reflectMethod.getDeclaredAnnotation(ParameterValueSourceSet.class).value()); } for (ParameterValueSource parameterValueSource : parameterValueSources) { int valueSourceLength = parameterValueSource.value().length; if (valueSourceLength != numOfParamsWithValueRequest) { errors.add( new Exception( String.format( "Parameter value source bundle (%s) and @FromParameterValueSource-annotated" + " parameters in Method (%s) mismatch in length.", parameterValueSource, eachTestMethod))); } } } }
Example 8
Source File: SpringMethodRule.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Wrap the supplied {@link Statement} with a {@code RunBeforeTestMethodCallbacks} statement. * @see RunBeforeTestMethodCallbacks */ private Statement withBeforeTestMethodCallbacks(Statement statement, FrameworkMethod frameworkMethod, Object testInstance, TestContextManager testContextManager) { return new RunBeforeTestMethodCallbacks( statement, testInstance, frameworkMethod.getMethod(), testContextManager); }
Example 9
Source File: NamedParameterizedRunner.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
/** * Checks the parameterization method for correctness. * @param frameworkMethod the method * @throws Exception if the annotation requirements are not met */ private static void checkParameterizationMethod(FrameworkMethod frameworkMethod) throws Exception { final Method method = frameworkMethod.getMethod(); if (method.getParameterTypes().length != 0) { throw new Exception(complainingThat(method, "must take no arguments")); } final int modifiers = frameworkMethod.getMethod().getModifiers(); if (! Modifier.isPublic(modifiers)) { throw new Exception(complainingThat(method, "must be public")); } if (! Modifier.isStatic(modifiers)) { throw new Exception(complainingThat(method, "must be static")); } final Type genericRet = method.getGenericReturnType(); final String mustReturnCorrectly = "must return Collection of " + Parameterization.class; if (! (genericRet instanceof ParameterizedType)) { throw new Exception(complainingThat(method, mustReturnCorrectly)); } final ParameterizedType ret = (ParameterizedType) genericRet; if (!(ret.getRawType() instanceof Class) && Collection.class.isAssignableFrom((Class)ret.getRawType())) { throw new Exception(complainingThat(method, mustReturnCorrectly)); } if (ret.getActualTypeArguments().length != 1) { throw new Exception(complainingThat(method, mustReturnCorrectly + "; raw Collection is not allowed")); } if (!ret.getActualTypeArguments()[0].equals(Parameterization.class)) { throw new Exception(complainingThat(method, mustReturnCorrectly)); } }
Example 10
Source File: VertxUnitRunner.java From vertx-unit with Apache License 2.0 | 5 votes |
protected void invokeTestMethod(FrameworkMethod fMethod, Object test, TestContext context) throws InvocationTargetException, IllegalAccessException { Method method = fMethod.getMethod(); Class<?>[] paramTypes = method.getParameterTypes(); if (paramTypes.length == 0) { method.invoke(test); } else { method.invoke(test, context); } }
Example 11
Source File: SpringMethodRule.java From java-technology-stack with MIT License | 4 votes |
/** * Apply <em>instance-level</em> and <em>method-level</em> features of * the <em>Spring TestContext Framework</em> to the supplied {@code base} * statement. * <p>Specifically, this method invokes the * {@link TestContextManager#prepareTestInstance prepareTestInstance()}, * {@link TestContextManager#beforeTestMethod beforeTestMethod()}, and * {@link TestContextManager#afterTestMethod afterTestMethod()} methods * on the {@code TestContextManager}, potentially with Spring timeouts * and repetitions. * <p>In addition, this method checks whether the test is enabled in * the current execution environment. This prevents methods with a * non-matching {@code @IfProfileValue} annotation from running altogether, * even skipping the execution of {@code prepareTestInstance()} methods * in {@code TestExecutionListeners}. * @param base the base {@code Statement} that this rule should be applied to * @param frameworkMethod the method which is about to be invoked on the test instance * @param testInstance the current test instance * @return a statement that wraps the supplied {@code base} with instance-level * and method-level features of the Spring TestContext Framework * @see #withBeforeTestMethodCallbacks * @see #withAfterTestMethodCallbacks * @see #withPotentialRepeat * @see #withPotentialTimeout * @see #withTestInstancePreparation * @see #withProfileValueCheck */ @Override public Statement apply(Statement base, FrameworkMethod frameworkMethod, Object testInstance) { Method testMethod = frameworkMethod.getMethod(); if (logger.isDebugEnabled()) { logger.debug("Applying SpringMethodRule to test method [" + testMethod + "]"); } Class<?> testClass = testInstance.getClass(); TestContextManager testContextManager = SpringClassRule.getTestContextManager(testClass); Statement statement = base; statement = withBeforeTestMethodCallbacks(statement, testMethod, testInstance, testContextManager); statement = withAfterTestMethodCallbacks(statement, testMethod, testInstance, testContextManager); statement = withTestInstancePreparation(statement, testInstance, testContextManager); statement = withPotentialRepeat(statement, testMethod, testInstance); statement = withPotentialTimeout(statement, testMethod, testInstance); statement = withProfileValueCheck(statement, testMethod, testInstance); return statement; }
Example 12
Source File: SpringJUnit4ParameterizedClassRunner.java From tds with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Wraps the {@link Statement} returned by the parent implementation with a * {@link RunAfterTestMethodCallbacks} statement, thus preserving the * default functionality but adding support for the Spring TestContext * Framework. * * @see RunAfterTestMethodCallbacks */ @Override protected Statement withAfters(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) { Statement junitAfters = super.withAfters(frameworkMethod, testInstance, statement); return new RunAfterTestMethodCallbacks(junitAfters, testInstance, frameworkMethod.getMethod(), getTestContextManager()); }
Example 13
Source File: SpringJUnit4ParameterizedClassRunner.java From tds with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Wraps the {@link Statement} returned by the parent implementation with a * {@link RunBeforeTestMethodCallbacks} statement, thus preserving the * default functionality but adding support for the Spring TestContext * Framework. * * @see RunBeforeTestMethodCallbacks */ @Override protected Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) { Statement junitBefores = super.withBefores(frameworkMethod, testInstance, statement); return new RunBeforeTestMethodCallbacks(junitBefores, testInstance, frameworkMethod.getMethod(), getTestContextManager()); }
Example 14
Source File: SpringJUnit4ClassRunner.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Wrap the {@link Statement} returned by the parent implementation with a * {@code RunBeforeTestMethodCallbacks} statement, thus preserving the * default functionality while adding support for the Spring TestContext * Framework. * @see RunBeforeTestMethodCallbacks */ @Override protected Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) { Statement junitBefores = super.withBefores(frameworkMethod, testInstance, statement); return new RunBeforeTestMethodCallbacks(junitBefores, testInstance, frameworkMethod.getMethod(), getTestContextManager()); }
Example 15
Source File: SpringJUnit4ClassRunner.java From java-technology-stack with MIT License | 2 votes |
/** * Return {@code true} if {@link Ignore @Ignore} is present for the supplied * {@linkplain FrameworkMethod test method} or if the test method is disabled * via {@code @IfProfileValue}. * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Method, Class) */ protected boolean isTestMethodIgnored(FrameworkMethod frameworkMethod) { Method method = frameworkMethod.getMethod(); return (method.isAnnotationPresent(Ignore.class) || !ProfileValueUtils.isTestEnabledInThisEnvironment(method, getTestClass().getJavaClass())); }
Example 16
Source File: SpringJUnit4ClassRunner.java From java-technology-stack with MIT License | 2 votes |
/** * Wrap the supplied {@link Statement} with a {@code RunAfterTestExecutionCallbacks} * statement, thus preserving the default functionality while adding support for the * Spring TestContext Framework. * @see RunAfterTestExecutionCallbacks */ protected Statement withAfterTestExecutionCallbacks(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) { return new RunAfterTestExecutionCallbacks(statement, testInstance, frameworkMethod.getMethod(), getTestContextManager()); }
Example 17
Source File: SpringJUnit4ClassRunner.java From java-technology-stack with MIT License | 2 votes |
/** * Wrap the {@link Statement} returned by the parent implementation with a * {@code RunAfterTestMethodCallbacks} statement, thus preserving the * default functionality while adding support for the Spring TestContext * Framework. * @see RunAfterTestMethodCallbacks */ @Override protected Statement withAfters(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) { Statement junitAfters = super.withAfters(frameworkMethod, testInstance, statement); return new RunAfterTestMethodCallbacks(junitAfters, testInstance, frameworkMethod.getMethod(), getTestContextManager()); }
Example 18
Source File: SpringJUnit4ClassRunner.java From java-technology-stack with MIT License | 2 votes |
/** * Wrap the supplied {@link Statement} with a {@code SpringRepeat} statement. * <p>Supports Spring's {@link org.springframework.test.annotation.Repeat @Repeat} * annotation. * @see TestAnnotationUtils#getRepeatCount(Method) * @see SpringRepeat */ protected Statement withPotentialRepeat(FrameworkMethod frameworkMethod, Object testInstance, Statement next) { return new SpringRepeat(next, frameworkMethod.getMethod()); }
Example 19
Source File: SpringJUnit4ClassRunner.java From spring-analysis-note with MIT License | 2 votes |
/** * Wrap the supplied {@link Statement} with a {@code RunAfterTestExecutionCallbacks} * statement, thus preserving the default functionality while adding support for the * Spring TestContext Framework. * @see RunAfterTestExecutionCallbacks */ protected Statement withAfterTestExecutionCallbacks(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) { return new RunAfterTestExecutionCallbacks(statement, testInstance, frameworkMethod.getMethod(), getTestContextManager()); }
Example 20
Source File: SpringJUnit4ClassRunner.java From spring-analysis-note with MIT License | 2 votes |
/** * Return {@code true} if {@link Ignore @Ignore} is present for the supplied * {@linkplain FrameworkMethod test method} or if the test method is disabled * via {@code @IfProfileValue}. * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Method, Class) */ protected boolean isTestMethodIgnored(FrameworkMethod frameworkMethod) { Method method = frameworkMethod.getMethod(); return (method.isAnnotationPresent(Ignore.class) || !ProfileValueUtils.isTestEnabledInThisEnvironment(method, getTestClass().getJavaClass())); }