Search in sources :

Example 1 with ReflectionUtils

use of org.junit.platform.commons.util.ReflectionUtils in project junit5 by junit-team.

the class ParameterizedTestExtension method provideTestTemplateInvocationContexts.

@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
    Method templateMethod = context.getRequiredTestMethod();
    ParameterizedTestNameFormatter formatter = createNameFormatter(templateMethod);
    AtomicLong invocationCount = new AtomicLong(0);
    // @formatter:off
    return findRepeatableAnnotations(templateMethod, ArgumentsSource.class).stream().map(ArgumentsSource::value).map(ReflectionUtils::newInstance).map(provider -> AnnotationConsumerInitializer.initialize(templateMethod, provider)).flatMap(provider -> arguments(provider, context)).map(Arguments::get).map(arguments -> consumedArguments(arguments, templateMethod)).map(arguments -> createInvocationContext(formatter, arguments)).peek(invocationContext -> invocationCount.incrementAndGet()).onClose(() -> Preconditions.condition(invocationCount.get() > 0, () -> "Configuration error: You must provide at least one argument for this @" + ParameterizedTest.class.getSimpleName()));
// @formatter:on
}
Also used : AnnotationConsumerInitializer(org.junit.jupiter.params.support.AnnotationConsumerInitializer) Preconditions(org.junit.platform.commons.util.Preconditions) Arrays(java.util.Arrays) AnnotationUtils.isAnnotated(org.junit.platform.commons.util.AnnotationUtils.isAnnotated) AnnotationUtils.findAnnotation(org.junit.platform.commons.util.AnnotationUtils.findAnnotation) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Arguments(org.junit.jupiter.params.provider.Arguments) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) AtomicLong(java.util.concurrent.atomic.AtomicLong) Stream(java.util.stream.Stream) TestTemplateInvocationContext(org.junit.jupiter.api.extension.TestTemplateInvocationContext) ExceptionUtils(org.junit.platform.commons.util.ExceptionUtils) TestTemplateInvocationContextProvider(org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider) AnnotationUtils.findRepeatableAnnotations(org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnnotations) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) Method(java.lang.reflect.Method) AtomicLong(java.util.concurrent.atomic.AtomicLong) Arguments(org.junit.jupiter.params.provider.Arguments) Method(java.lang.reflect.Method) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Aggregations

Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Stream (java.util.stream.Stream)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 TestTemplateInvocationContext (org.junit.jupiter.api.extension.TestTemplateInvocationContext)1 TestTemplateInvocationContextProvider (org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider)1 Arguments (org.junit.jupiter.params.provider.Arguments)1 ArgumentsProvider (org.junit.jupiter.params.provider.ArgumentsProvider)1 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)1 AnnotationConsumerInitializer (org.junit.jupiter.params.support.AnnotationConsumerInitializer)1 AnnotationUtils.findAnnotation (org.junit.platform.commons.util.AnnotationUtils.findAnnotation)1 AnnotationUtils.findRepeatableAnnotations (org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnnotations)1 AnnotationUtils.isAnnotated (org.junit.platform.commons.util.AnnotationUtils.isAnnotated)1 ExceptionUtils (org.junit.platform.commons.util.ExceptionUtils)1 Preconditions (org.junit.platform.commons.util.Preconditions)1 ReflectionUtils (org.junit.platform.commons.util.ReflectionUtils)1