From 9ffebb8099ad9c023180ef8b6a51785f5ea1df0f Mon Sep 17 00:00:00 2001 From: martinfrancois Date: Tue, 11 Aug 2026 20:01:27 +0200 Subject: [PATCH] RenameMethodsNamedHashcodeEqualOrToString: add failing tests for non-compiling renames Two rename shapes produce output javac rejects, and neither is covered by the guard proposed in the open PR #974 (verified by applying its diff and rerunning): renaming both of two differently misspelled variants in one class creates two colliding declarations, and renaming an annotation type member gives the element the name of an Object method, which an annotation interface may not declare. Both tests assert the input is left unchanged and are marked ExpectedToFail. --- ...thodsNamedHashcodeEqualOrToStringTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/test/java/org/openrewrite/staticanalysis/RenameMethodsNamedHashcodeEqualOrToStringTest.java b/src/test/java/org/openrewrite/staticanalysis/RenameMethodsNamedHashcodeEqualOrToStringTest.java index 34393129e..463fca3e0 100644 --- a/src/test/java/org/openrewrite/staticanalysis/RenameMethodsNamedHashcodeEqualOrToStringTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/RenameMethodsNamedHashcodeEqualOrToStringTest.java @@ -16,6 +16,7 @@ package org.openrewrite.staticanalysis; import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.ExpectedToFail; import org.openrewrite.DocumentExample; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -86,6 +87,42 @@ public String toString() { ); } + @ExpectedToFail("Both variants are renamed to hashCode(), producing two colliding declarations") + @Test + void doNotRenameWhenTwoMisspelledVariantsWouldCollide() { + rewriteRun( + //language=java + java( + """ + class Test { + public int hashcode() { + return 1; + } + + public int hashCODE() { + return 2; + } + } + """ + ) + ); + } + + @ExpectedToFail("An annotation type member may not carry the name of an Object method") + @Test + void doNotRenameAnnotationTypeMember() { + rewriteRun( + //language=java + java( + """ + @interface Test { + int hashcode(); + } + """ + ) + ); + } + @Test void compliantWhenHasMismatchingTypeInformation() { rewriteRun(