From cfd1f79a682a5ce9cc317a6f89bf29177855c90c Mon Sep 17 00:00:00 2001 From: Kurt Alfred Kluever Date: Thu, 9 Jan 2025 11:22:27 -0800 Subject: [PATCH] Add a test for `static` `Function` lambdas that are not `UPPER_CASED`. PiperOrigin-RevId: 713736769 --- .../bugpatterns/UnnecessaryLambdaTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) 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