Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,14 @@ private void handleMethodSource(MethodTree tree) {
sym.getRawAttributes().stream()
.filter(a -> a.type.tsym.getQualifiedName().equals(name))
.findAny()
// get the annotation value array as a set of Names
.flatMap(a -> getAnnotationValue(a, "value"))
.map(
y -> asStrings(y).map(state::getName).map(Name::toString).collect(toImmutableSet()))
// get the annotation value array as a set of Names,
// normalizing unset value to the empty value
.map(a -> getAnnotationValue(a, "value")
.map(y -> asStrings(y).map(state::getName).map(Name::toString).collect(toImmutableSet()))
.orElse(ImmutableSet.of())
)
// if no explicit method sources were specified, use method name instead
.map(names -> names.isEmpty() ? Set.of(sym.name.toString()) : names)
// remove all potentially unused methods referenced by the @MethodSource
.ifPresent(
referencedNames ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void methodSource() {
package org.junit.jupiter.params.provider;

public @interface MethodSource {
String[] value();
String[] value() default "";
}
""")
.addSourceLines(
Expand All @@ -339,6 +339,36 @@ private static Stream<String> parameters() {
.doTest();
}

@Test
public void implicitMethodSource() {
helper
.addSourceLines(
"MethodSource.java",
"""
package org.junit.jupiter.params.provider;

public @interface MethodSource {
String[] value() default "";
}
""")
.addSourceLines(
"Test.java",
"""
import java.util.stream.Stream;
import org.junit.jupiter.params.provider.MethodSource;

class Test {
@MethodSource
void test() {}

private static Stream<String> test() {
return Stream.of();
}
}
""")
.doTest();
}

@Test
public void qualifiedMethodSource() {
helper
Expand All @@ -348,7 +378,7 @@ public void qualifiedMethodSource() {
package org.junit.jupiter.params.provider;

public @interface MethodSource {
String[] value();
String[] value() default "";
}
""")
.addSourceLines(
Expand Down Expand Up @@ -378,7 +408,7 @@ public void nestedQualifiedMethodSource() {
package org.junit.jupiter.params.provider;

public @interface MethodSource {
String[] value();
String[] value() default "";
}
""")
.addSourceLines(
Expand Down