Search in sources :

Example 1 with CollectionUtils

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

the class MethodArgumentsProvider method provideArguments.

@Override
public Stream<Arguments> provideArguments(ExtensionContext context) {
    Class<?> testClass = context.getRequiredTestClass();
    Object testInstance = context.getTestInstance().orElse(null);
    // @formatter:off
    return Arrays.stream(this.methodNames).map(methodName -> StringUtils.isNotBlank(methodName) ? methodName : context.getRequiredTestMethod().getName()).map(methodName -> ReflectionUtils.findMethod(testClass, methodName).orElseThrow(() -> new JUnitException(format("Could not find factory method [%s] in class [%s]", methodName, testClass.getName())))).map(method -> ReflectionUtils.invokeMethod(method, testInstance)).flatMap(CollectionUtils::toStream).map(MethodArgumentsProvider::toArguments);
// @formatter:on
}
Also used : Arrays(java.util.Arrays) Stream(java.util.stream.Stream) CollectionUtils(org.junit.platform.commons.util.CollectionUtils) JUnitException(org.junit.platform.commons.JUnitException) StringUtils(org.junit.platform.commons.util.StringUtils) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) AnnotationConsumer(org.junit.jupiter.params.support.AnnotationConsumer) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) String.format(java.lang.String.format) JUnitException(org.junit.platform.commons.JUnitException)

Aggregations

String.format (java.lang.String.format)1 Arrays (java.util.Arrays)1 Stream (java.util.stream.Stream)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 AnnotationConsumer (org.junit.jupiter.params.support.AnnotationConsumer)1 JUnitException (org.junit.platform.commons.JUnitException)1 CollectionUtils (org.junit.platform.commons.util.CollectionUtils)1 ReflectionUtils (org.junit.platform.commons.util.ReflectionUtils)1 StringUtils (org.junit.platform.commons.util.StringUtils)1