File tree Expand file tree Collapse file tree 2 files changed +38
-4
lines changed
main/java/com/google/errorprone/bugpatterns
test/java/com/google/errorprone/bugpatterns Expand file tree Collapse file tree 2 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -303,10 +303,14 @@ private void handleMethodSource(MethodTree tree) {
303303 sym .getRawAttributes ().stream ()
304304 .filter (a -> a .type .tsym .getQualifiedName ().equals (name ))
305305 .findAny ()
306- // get the annotation value array as a set of Names
307- .flatMap (a -> getAnnotationValue (a , "value" ))
308- .map (
309- y -> asStrings (y ).map (state ::getName ).map (Name ::toString ).collect (toImmutableSet ()))
306+ // get the annotation value array as a set of Names,
307+ // normalizing unset value to the empty value
308+ .map (a -> getAnnotationValue (a , "value" )
309+ .map (y -> asStrings (y ).map (state ::getName ).map (Name ::toString ).collect (toImmutableSet ()))
310+ .orElse (ImmutableSet .of ())
311+ )
312+ // if no explicit method sources were specified, use method name instead
313+ .map (names -> names .isEmpty () ? Set .of (sym .name .toString ()) : names )
310314 // remove all potentially unused methods referenced by the @MethodSource
311315 .ifPresent (
312316 referencedNames ->
Original file line number Diff line number Diff line change @@ -339,6 +339,36 @@ private static Stream<String> parameters() {
339339 .doTest ();
340340 }
341341
342+ @ Test
343+ public void implicitMethodSource () {
344+ helper
345+ .addSourceLines (
346+ "MethodSource.java" ,
347+ """
348+ package org.junit.jupiter.params.provider;
349+
350+ public @interface MethodSource {
351+ String[] value();
352+ }
353+ """ )
354+ .addSourceLines (
355+ "Test.java" ,
356+ """
357+ import java.util.stream.Stream;
358+ import org.junit.jupiter.params.provider.MethodSource;
359+
360+ class Test {
361+ @MethodSource
362+ void test() {}
363+
364+ private static Stream<String> test() {
365+ return Stream.of();
366+ }
367+ }
368+ """ )
369+ .doTest ();
370+ }
371+
342372 @ Test
343373 public void qualifiedMethodSource () {
344374 helper
You can’t perform that action at this time.
0 commit comments