Skip to content

Commit

Permalink
apply suggestions based on #3787 comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Madalin Giurca committed Apr 19, 2024
1 parent 46731e6 commit f1046d2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
*/
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(CSVSources.class)
@Repeatable(CsvSources.class)
@Documented
@API(status = STABLE, since = "5.7")
@ArgumentsSource(CsvArgumentsProvider.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@API(status = STABLE, since = "5.7")
public @interface CSVSources {
@API(status = STABLE, since = "5.11")
public @interface CsvSources {
CsvSource[] value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.junit.jupiter.params.support.AnnotationConsumer;
import org.junit.platform.commons.util.Preconditions;

@API(status = EXPERIMENTAL, since = "5.10")
@API(status = EXPERIMENTAL, since = "5.11")
public abstract class RepeatableAnnotationArgumentsProvider<A extends Annotation>
implements ArgumentsProvider, AnnotationConsumer<A> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.junit.jupiter.params.support;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.apiguardian.api.API.Status.INTERNAL;
import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;
import static org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnnotations;
Expand All @@ -21,11 +22,9 @@
import java.lang.annotation.Repeatable;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apiguardian.api.API;
import org.junit.platform.commons.JUnitException;
Expand All @@ -52,7 +51,7 @@ private AnnotationConsumerInitializer() {
public static <T> T initialize(AnnotatedElement annotatedElement, T annotationConsumerInstance) {
if (annotationConsumerInstance instanceof AnnotationConsumer) {
Class<? extends Annotation> annotationType = findConsumedAnnotationType(annotationConsumerInstance);
List<? extends Annotation> annotations = streamAnnotations(annotatedElement, annotationType);
List<? extends Annotation> annotations = findAnnotations(annotatedElement, annotationType);

if (annotations.isEmpty()) {
throw new JUnitException(annotationConsumerInstance.getClass().getName()
Expand All @@ -65,13 +64,12 @@ public static <T> T initialize(AnnotatedElement annotatedElement, T annotationCo
return annotationConsumerInstance;
}

private static List<? extends Annotation> streamAnnotations(AnnotatedElement annotatedElement,
Class<? extends Annotation> annotationType) {
private static <T extends Annotation> List<T> findAnnotations(AnnotatedElement annotatedElement,
Class<T> annotationType) {

return annotationType.isAnnotationPresent(Repeatable.class)
? findRepeatableAnnotations(annotatedElement, annotationType)
: Stream.of(findAnnotation(annotatedElement, annotationType)).filter(Optional::isPresent).map(
Optional::get).collect(Collectors.toList());
: findAnnotation(annotatedElement, annotationType).map(Collections::singletonList).orElse(emptyList());
}

private static <T> Class<? extends Annotation> findConsumedAnnotationType(T annotationConsumerInstance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ void executesWithCsvSource() {
@Test
void executesWithRepeatableCsvSource() {
var results = execute("testWithRepeatableCsvSource", String.class);
results.allEvents().assertThatEvents().haveExactly(1,
event(test(), displayName("[1] argument=a"), finishedWithFailure(message("a")))).haveExactly(1,
event(test(), displayName("[2] argument=b"), finishedWithFailure(message("b"))));
results.allEvents().assertThatEvents() //
.haveExactly(1, event(test(), displayName("[1] argument=a"), finishedWithFailure(message("a")))) //
.haveExactly(1, event(test(), displayName("[2] argument=b"), finishedWithFailure(message("b"))));
}

@Test
Expand Down

0 comments on commit f1046d2

Please sign in to comment.