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) {
303
303
sym .getRawAttributes ().stream ()
304
304
.filter (a -> a .type .tsym .getQualifiedName ().equals (name ))
305
305
.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 )
310
314
// remove all potentially unused methods referenced by the @MethodSource
311
315
.ifPresent (
312
316
referencedNames ->
Original file line number Diff line number Diff line change @@ -339,6 +339,36 @@ private static Stream<String> parameters() {
339
339
.doTest ();
340
340
}
341
341
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
+
342
372
@ Test
343
373
public void qualifiedMethodSource () {
344
374
helper
You can’t perform that action at this time.
0 commit comments