From f56c8b2450fed455910a182d6d3abf498e59527c Mon Sep 17 00:00:00 2001 From: cpovirk Date: Wed, 31 Jul 2024 05:36:04 -0700 Subject: [PATCH] Confirm that https://errorprone.info/bugpattern/CannotMockFinalClass covers records. Relevant to https://github.com/google/error-prone/pull/4384. PiperOrigin-RevId: 657972168 --- .../bugpatterns/CannotMockFinalClassTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java index dd6264f25db..e22105d689e 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java @@ -16,7 +16,10 @@ package com.google.errorprone.bugpatterns; +import static org.junit.Assume.assumeTrue; + import com.google.errorprone.CompilationTestHelper; +import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -36,6 +39,26 @@ public void positiveCase() { compilationHelper.addSourceFile("CannotMockFinalClassPositiveCases.java").doTest(); } + @Test + public void positiveCase_record() { + assumeTrue(RuntimeVersion.isAtLeast16()); + + compilationHelper + .addSourceLines( + "Test.java", + "import org.junit.runner.RunWith;", + "import org.junit.runners.JUnit4;", + "import org.mockito.Mock;", + "import org.mockito.Mockito;", + "@RunWith(JUnit4.class)", + "public class Test {", + " record Record() {}", + " // BUG: Diagnostic contains: ", + " @Mock Record record;", + "}") + .doTest(); + } + @Test public void negativeCase() { compilationHelper.addSourceFile("CannotMockFinalClassNegativeCases.java").doTest();