From d9daeddcfb8251945bc9dae53c5cb8a45251ceb8 Mon Sep 17 00:00:00 2001 From: Tyler Kindy Date: Fri, 14 Jun 2024 11:30:13 -0400 Subject: [PATCH] Add tests --- .../ClassInitializationDeadlockTest.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ClassInitializationDeadlockTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ClassInitializationDeadlockTest.java index b1c51f7f1d1..944937e3fc2 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ClassInitializationDeadlockTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ClassInitializationDeadlockTest.java @@ -18,6 +18,7 @@ import com.google.auto.value.processor.AutoValueProcessor; import com.google.errorprone.CompilationTestHelper; + import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -309,4 +310,63 @@ public void nonNestedSubclass() { "class B extends A {}") .doTest(); } + + @Test + public void simpleSubclassMethodReference() { + testHelper + .addSourceLines( + "Foo.java", + "import java.util.function.Supplier;", + "class A {", + " static Supplier supplier = B::new;", + "}", + "class B extends A {}") + .doTest(); + } + + @Test + public void compoundSubclassMethodReference() { + testHelper + .addSourceLines( + "Foo.java", + "import java.util.Comparator;", + "class A {", + " static Comparator comparator = Comparator.comparing(B::value);", + "}", + "class B extends A {", + " int value;", + " int value() {", + " return value;", + " }", + "}") + .doTest(); + } + + @Test + public void lambda() { + testHelper + .addSourceLines( + "Foo.java", + "import java.util.function.Supplier;", + "class A {", + " static Supplier supplier = () -> new B();", + "}", + "class B extends A {}") + .doTest(); + } + + @Test + public void subclassStaticMethod() { + testHelper + .addSourceLines( + "Foo.java", + "class A {", + " // BUG: Diagnostic contains:", + " static int value = B.value(); ", + "}", + "class B extends A {", + " static int value() { return 0; }", + "}") + .doTest(); + } }