From 41d664b1ad2400f2f6f3ac3a62da82e72bab721b Mon Sep 17 00:00:00 2001 From: martinfrancois Date: Tue, 11 Aug 2026 20:21:24 +0200 Subject: [PATCH] PrimitiveWrapperClassConstructorToValueOf: add failing tests for dropped comments and missing Groovy cast preserveCommentsWithinNewClass pins that comments between 'new' and the argument list are dropped when the constructor is replaced with valueOf. groovyCompoundDoubleToFloat pins that a compound double argument in Groovy gets no (float) cast because its type is not resolved. Both are marked @ExpectedToFail; related: #970. --- ...eWrapperClassConstructorToValueOfTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/test/java/org/openrewrite/staticanalysis/PrimitiveWrapperClassConstructorToValueOfTest.java b/src/test/java/org/openrewrite/staticanalysis/PrimitiveWrapperClassConstructorToValueOfTest.java index 31e83bb23..939e682ca 100644 --- a/src/test/java/org/openrewrite/staticanalysis/PrimitiveWrapperClassConstructorToValueOfTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/PrimitiveWrapperClassConstructorToValueOfTest.java @@ -16,11 +16,13 @@ package org.openrewrite.staticanalysis; import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.ExpectedToFail; import org.openrewrite.DocumentExample; import org.openrewrite.Issue; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; +import static org.openrewrite.groovy.Assertions.groovy; import static org.openrewrite.java.Assertions.java; @SuppressWarnings({ @@ -217,6 +219,46 @@ Double getD() { ); } + @ExpectedToFail("Comments between `new` and the argument list are dropped when replacing the constructor") + @Test + void preserveCommentsWithinNewClass() { + rewriteRun( + //language=java + java( + """ + class A { + Integer i = new /* keep me */ Integer(42); + } + """, + """ + class A { + Integer i = /* keep me */ Integer.valueOf(42); + } + """ + ) + ); + } + + @ExpectedToFail("The Groovy parser attributes a compound double argument as java.lang.Object, so no (float) cast is added") + @Test + void groovyCompoundDoubleToFloat() { + rewriteRun( + //language=groovy + groovy( + """ + double d1 = 1.0d + double d2 = 2.0d + Float sum = new Float(d1 + d2) + """, + """ + double d1 = 1.0d + double d2 = 2.0d + Float sum = Float.valueOf((float) (d1 + d2)) + """ + ) + ); + } + @Test void withinEnum() { rewriteRun(