diff --git a/src/test/java/org/openrewrite/staticanalysis/ReplaceStringConcatenationWithStringValueOfTest.java b/src/test/java/org/openrewrite/staticanalysis/ReplaceStringConcatenationWithStringValueOfTest.java index 9a341a68e..0b510d0c7 100644 --- a/src/test/java/org/openrewrite/staticanalysis/ReplaceStringConcatenationWithStringValueOfTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/ReplaceStringConcatenationWithStringValueOfTest.java @@ -17,9 +17,11 @@ import org.junit.jupiter.api.Nested; 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; +import org.openrewrite.test.TypeValidation; import static org.openrewrite.java.Assertions.java; @@ -323,5 +325,40 @@ void method() { ) ); } + + @ExpectedToFail("visitParentheses unwraps pre-existing (String.valueOf(..)) even when no concatenation was rewritten") + @Test + void doNotChangeParenthesizedValueOfWithoutConcatenation() { + rewriteRun( + //language=java + java( + """ + class Test { + String method(Object o) { + return (String.valueOf(o)); + } + } + """ + ) + ); + } + + @ExpectedToFail("Operand without type attribution is still rewritten; not value-preserving if it is really a char[]") + @Test + void doNotChangeWhenOperandTypeIsMissing() { + rewriteRun( + spec -> spec.typeValidationOptions(TypeValidation.none()), + //language=java + java( + """ + class Test { + String method(Unresolved holder) { + return "" + holder.chars(); + } + } + """ + ) + ); + } } }