@Test public void testSingleLiteral() throws Exception { HintTest.create() .setCaretMarker('|') .input( "package test;\n" + "public class Test {\n" + " public static void main(String[] args) {\n" + " String foo=\"A|\";\n" + " }\n" + "}\n") .run(ReplacePlusHint.class) .assertNotContainsWarnings(Bundle.DN_ReplacePlus()); }
@Test public void testFixWorkingLiteralPrefix() throws Exception { HintTest.create() .setCaretMarker('|') .input( "package test;\n" + "public class Test {\n" + " public static void main(String[] args) {\n" + " String foo=\"A\"|+4;\n" + " }\n" + "}\n") .run(ReplacePlusHint.class) .findWarning("3:22-3:22:hint:" + Bundle.DN_ReplacePlus()) .applyFix(Bundle.LBL_ReplaceWithStringBuilderFix()) .assertCompilable() .assertOutput( "package test;\n" + "public class Test {\n" + " public static void main(String[] args) {\n" + " String foo=new StringBuilder().append(\"A\").append(4).toString();\n" + " }\n" + "}\n"); }
@Test public void testFixWorkingMixedB() throws Exception { HintTest.create() .setCaretMarker('|') .input( "package test;\n" + "public class Test {\n" + " public static void main(String[] args) {\n" + " String foo=\"Output contains \"| + 4 + \" entries\" + \" and more at \" + new java.util.Date();\n" + " }\n" + "}\n") .run(ReplacePlusHint.class) .findWarning("3:37-3:37:hint:" + Bundle.DN_ReplacePlus()) .applyFix(Bundle.LBL_ReplaceWithStringBuilderFix()) .assertCompilable() .assertOutput( "package test;\n" + "import java.util.Date;\n" + "public class Test {\n" + " public static void main(String[] args) {\n" + " String foo=new StringBuilder().append(\"Output contains \").append(4).append(\" entries and more at \").append(new Date()).toString();\n" + " }\n" + "}\n"); }