diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryLambdaTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryLambdaTest.java index c17bc87f65b..9a44ad57802 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryLambdaTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryLambdaTest.java @@ -260,6 +260,43 @@ void g() { .doTest(); } + @Test + public void variable_static_butNotUpperCased() { + testHelper + .addInputLines( + "Test.java", + """ + import java.util.function.Function; + + class Test { + private static final Function notUpperCased = x -> "hello " + x; + + void g() { + Function l = Test.notUpperCased; + System.err.println(notUpperCased.apply("world")); + } + } + """) + // TODO: b/388821905 - we should retain the camelCasing of the variable name + .addOutputLines( + "Test.java", + """ + import java.util.function.Function; + + class Test { + private static String notuppercased(String x) { + return "hello " + x; + } + + void g() { + Function l = Test::notuppercased; + System.err.println(notuppercased("world")); + } + } + """) + .doTest(); + } + @Test public void method_shapes() { testHelper