@Override public <A extends Annotation> List<A> findRepeatableAnnotations(Class<A> annotationType) { return AnnotationUtils.findRepeatableAnnotations(getEffectiveAnnotatedParameter(), annotationType); }
protected static Set<TestTag> getTags(AnnotatedElement element) { // @formatter:off return findRepeatableAnnotations(element, Tag.class).stream() .map(Tag::value) .filter(tag -> { boolean isValid = TestTag.isValid(tag); if (!isValid) { // TODO [#242] Replace logging with precondition check once we have a proper mechanism for // handling validation exceptions during the TestEngine discovery phase. // // As an alternative to a precondition check here, we could catch any // PreconditionViolationException thrown by TestTag::create. logger.warn(() -> String.format( "Configuration error: invalid tag syntax in @Tag(\"%s\") declaration on [%s]. Tag will be ignored.", tag, element)); } return isValid; }) .map(TestTag::create) .collect(collectingAndThen(toCollection(LinkedHashSet::new), Collections::unmodifiableSet)); // @formatter:on }
protected Set<ExclusiveResource> getExclusiveResourcesFromAnnotation(AnnotatedElement element) { // @formatter:off return findRepeatableAnnotations(element, ResourceLock.class).stream() .map(resource -> new ExclusiveResource(resource.value(), toLockMode(resource.mode()))) .collect(toSet()); // @formatter:on }
@Override public <A extends Annotation> List<A> findRepeatableAnnotations(Class<A> annotationType) { Preconditions.notNull(annotationType, "annotationType must not be null"); return AnnotationUtils.findRepeatableAnnotations(getMethod(), annotationType); }
/** * Populate a new {@link ExtensionRegistry} from extension types declared via * {@link ExtendWith @ExtendWith} on the supplied {@link AnnotatedElement}. * * @param parentRegistry the parent extension registry to set in the newly * created registry; never {@code null} * @param annotatedElement the annotated element on which to search for * declarations of {@code @ExtendWith}; never {@code null} * * @return the new extension registry; never {@code null} * @since 5.0 */ static ExtensionRegistry populateNewExtensionRegistryFromExtendWithAnnotation(ExtensionRegistry parentRegistry, AnnotatedElement annotatedElement) { Preconditions.notNull(annotatedElement, "AnnotatedElement must not be null"); Preconditions.notNull(parentRegistry, "Parent ExtensionRegistry must not be null"); // @formatter:off List<Class<? extends Extension>> extensionTypes = findRepeatableAnnotations(annotatedElement, ExtendWith.class).stream() .map(ExtendWith::value) .flatMap(Arrays::stream) .collect(toList()); // @formatter:on return ExtensionRegistry.createRegistryFrom(parentRegistry, extensionTypes); }
@Override public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts( ExtensionContext extensionContext) { Method templateMethod = extensionContext.getRequiredTestMethod(); String displayName = extensionContext.getDisplayName(); ParameterizedTestMethodContext methodContext = getStore(extensionContext)// .get(METHOD_CONTEXT_KEY, ParameterizedTestMethodContext.class); ParameterizedTestNameFormatter formatter = createNameFormatter(templateMethod, displayName); AtomicLong invocationCount = new AtomicLong(0); // @formatter:off return findRepeatableAnnotations(templateMethod, ArgumentsSource.class) .stream() .map(ArgumentsSource::value) .map(this::instantiateArgumentsProvider) .map(provider -> AnnotationConsumerInitializer.initialize(templateMethod, provider)) .flatMap(provider -> arguments(provider, extensionContext)) .map(Arguments::get) .map(arguments -> consumedArguments(arguments, methodContext)) .map(arguments -> createInvocationContext(formatter, methodContext, arguments)) .peek(invocationContext -> invocationCount.incrementAndGet()) .onClose(() -> Preconditions.condition(invocationCount.get() > 0, "Configuration error: You must configure at least one set of arguments for this @ParameterizedTest")); // @formatter:on }
static ExtensionRegistry populateNewExtensionRegistryFromExtendWithAnnotation(ExtensionRegistry parentRegistry, AnnotatedElement annotatedElement) { List<Class<? extends Extension>> extensionTypes = AnnotationUtils.findRepeatableAnnotations(annotatedElement, ExtendWith.class) .stream() .map(ExtendWith::value) .flatMap(Arrays::stream) .collect(Collectors.toList()); return ExtensionRegistry.createRegistryFrom(parentRegistry, extensionTypes); } }
@Override public boolean supportsTestTemplate(ExtensionContext context) { List<WithFixture> fixtures = AnnotationUtils.findRepeatableAnnotations( context.getRequiredTestClass(), WithFixture.class); return !fixtures.isEmpty(); }
protected static Set<TestTag> getTags(AnnotatedElement element) { return AnnotationUtils.findRepeatableAnnotations(element, Tag.class).stream().map(Tag::value).filter((tag) -> { boolean isValid = TestTag.isValid(tag); if (!isValid) { logger.warn(() -> String.format("Configuration error: invalid tag syntax in @Tag(\"%s\") declaration on [%s]. Tag will be ignored.", tag, element)); } return isValid; }).map(TestTag::create) .collect(Collectors.collectingAndThen(Collectors.toCollection(LinkedHashSet::new), Collections::unmodifiableSet)); } }
@Override public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts( ExtensionContext context) { return AnnotationUtils.findRepeatableAnnotations( context.getRequiredTestClass(), WithFixture.class) .stream()