void () { final String in1 = "@SuppressWarnings(\"ALL\")\n" + "public class A {}"; final String what = "@SuppressWarnings(\"ALL\")"; final String expected1a = "public class A {}"; assertEquals(expected1a, replace(in1, what, "")); final String expected1b = "@SuppressWarnings(\"NONE\") @Deprecated\n" + "public class A {}"; assertEquals(expected1b, replace(in1, what, "@SuppressWarnings(\"NONE\") @Deprecated")); final String expected1c = "@SuppressWarnings(\"ALL\") class B {}"; assertEquals("Should replace unmatched annotation parameters", expected1c, replace(in1, "@SuppressWarnings class A {}", "@SuppressWarnings class B {}")); final String expected1d = "@ SuppressWarnings(\"ALL\")\n" + "public class A {}"; assertEquals("Should replace unmatched annotation parameters when matching just annotation", expected1d, replace(in1, "@SuppressWarnings", "@ SuppressWarnings")); String what1 = "@SuppressWarnings(\"'value\")"; String by = "$lower_case$"; final ReplacementVariableDefinition variable = options.addNewVariableDefinition("lower_case"); variable.setScriptCodeConstraint("value.getText().toLowerCase()"); final String expected1e = "@SuppressWarnings(\"all\")\n" + "public class A {}"; assertEquals(expected1e, replace(in1, what1, by)); final String in2 = """ class X { @SuppressWarnings("unused") String s; }"""; final String expected2a = """ class X { @SuppressWarnings({"unused", "other"}) String s; }"""; assertEquals(expected2a, replace(in2, "@SuppressWarnings(\"unused\") String '_s;", "@SuppressWarnings({\"unused\", \"other\"}) String $s$;")); final String expected2b = """ class X { @SuppressWarnings("unused") String s = "undoubtedly"; }"""; assertEquals(expected2b, replace(in2, "@'_Anno('_v) String '_s;", "@$Anno$($v$) String $s$ = \"undoubtedly\";")); final String expected2c = """ class X { @SuppressWarnings(value="unused") String s; }"""; assertEquals(expected2c, replace(in2, "@'_A('_v='_x)", "@$A$($v$=$x$)")); final String expected2d = """ class X { @SuppressWarnings({"unused", "raw"}) String s; }"""; assertEquals(expected2d, replace(in2, "@'_A('_x)", "@$A$({$x$, \"raw\"})")); final String expected2e = """ class X { @SuppressWarnings(value={1,2}, value="unused") String s; }"""; assertEquals(expected2e, replace(in2, "@'_A('_n='_v)", "@$A$($n$={1,2}, $n$=$v$)")); final String in3 = """ class X { @Language(value="RegExp", prefix="xxx") String pattern; }"""; final String expected3 = """ class X { @ A(value="RegExp", prefix="xxx", suffix="") String pattern; }"""; assertEquals(expected3, replace(in3, "@'_A('_v*='_x)", "@ A($v$=$x$, suffix=\"\")")); final String in4 = """ class X { @Anno(one=1, two=1) String s; }"""; final String expected4 = """ class X { @Anno(one=1, two=1, three=1) String s; }"""; assertEquals(expected4, replace(in4, "@'_A('_p*=1)", "@$A$($p$=1, three=1)")); final String expected4b = """ class X { @Anno(one=2, two=1) String s; }"""; assertEquals(expected4b, replace(in4, "@'_A('_p:one =1)", "@$A$($p$=2)")); final String in5 = """ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { ThisShallBeTwoClassesInContextHierarchyConfig.class, SomeTest.SomeTestConfig.class, WhateverConfig.class }) @Transactional public class SomeTest {}"""; final String expected5 = """ @RunWith(SpringJUnit4ClassRunner.class) @ContextHierarchy(classes = { @ContextConfiguration(classes = {ThisShallBeTwoClassesInContextHierarchyConfig.class, SomeTest.SomeTestConfig.class, WhateverConfig.class, Object.class}) }) @Transactional public class SomeTest {}"""; assertEquals(expected5, replace(in5, "@ContextConfiguration(classes = {'_X*})", """ @ContextHierarchy(classes = { @ContextConfiguration(classes = {$X$, Object.class}) })""")); final String in6 = """ class X { @WastingTime @Override public @Constant @Sorrow String value() { return null; } }"""; final String expected6 = """ class X { @WastingTime @Override private @Constant @Sorrow String value() { return null; } }"""; assertEquals(expected6, replace(in6, "'_ReturnType '_method('_ParameterType '_parameter*);", "private $ReturnType$ $method$($ParameterType$ $parameter$);")); final String in7 = """ public class IssueLink { @XmlAttribute(name = "default", namespace = "space") @Deprecated public String typeInward; }"""; final String expected7 = """ public class IssueLink { @XmlAttribute(name="default", namespace = "space") public String typeInward; }"""; assertEquals(expected7, replace(in7, "@XmlAttribute(name=\"default\") @Deprecated '_Type '_field;", "@XmlAttribute(name=\"default\") $Type$ $field$;")); final String expected7b = """ class IssueLink { @XmlAttribute(name = "default", namespace = "space") @Deprecated public String typeInward; }"""; assertEquals(expected7b, replace(in7, "@'_Anno* public class '_X {}", "@$Anno$ class $X$ {}")); }