From fdf345b2f1b369f9ee902a4051fb195c2af47d1f Mon Sep 17 00:00:00 2001 From: Adam Birem Date: Wed, 30 Oct 2024 13:37:02 +0100 Subject: [PATCH 1/2] Add test case for issue #384 https://github.com/openrewrite/rewrite-static-analysis/issues/384 --- .../ReplaceDuplicateStringLiteralsTest.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java b/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java index 8fc7e44a8..9e0c02d57 100644 --- a/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java @@ -21,8 +21,7 @@ import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; -import static org.openrewrite.java.Assertions.java; -import static org.openrewrite.java.Assertions.srcTestJava; +import static org.openrewrite.java.Assertions.*; class ReplaceDuplicateStringLiteralsTest implements RewriteTest { @@ -727,4 +726,32 @@ interface A { ) ); } + + @Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/384") + @Test + void staticWithObjectArray() { + rewriteRun( + //language=java + java( + """ + class A { + public void method() { + Object[] args = null; + args = new Object[] {"value"}; + } + } + """, + """ + class A { + public void method() { + Object[] args = null; + args = new Object[] {"value"}; + } + } + """ + ) + ); + } + + } From fde902732455746d3371b811b5d3fa3a9cc2fbef Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 30 Oct 2024 14:45:57 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../ReplaceDuplicateStringLiteralsTest.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java b/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java index 9e0c02d57..51739d01b 100644 --- a/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiteralsTest.java @@ -21,7 +21,8 @@ import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; -import static org.openrewrite.java.Assertions.*; +import static org.openrewrite.java.Assertions.java; +import static org.openrewrite.java.Assertions.srcTestJava; class ReplaceDuplicateStringLiteralsTest implements RewriteTest { @@ -734,18 +735,18 @@ void staticWithObjectArray() { //language=java java( """ - class A { - public void method() { - Object[] args = null; - args = new Object[] {"value"}; - } - } - """, - """ - class A { - public void method() { - Object[] args = null; - args = new Object[] {"value"}; + class A { + public void method() { + Object[] args = null; + args = new Object[] {"value"}; + } + } + class A { + public void method() { + Object[] args = null; + args = new Object[] {"value"}; + } + } } } """