コード例 #1
0
 @Test
 public void testMemberMethod() throws Exception {
   HintTest.create()
       .input(
           "package example;\n"
               + "public class Test {\n"
               + "    int variable=42;\n"
               + "    static void staticMember() {};\n"
               + "    void getMember(){\n"
               + "         staticMember();\n"
               + "         getMember();\n"
               + "         this.getMember();\n"
               + "         variable = 43;\n"
               + "    };\n"
               + "}")
       .run(AddThisToMember.class)
       .assertWarnings(
           "6:9-6:18:warning:" + Bundle.ERR_AddThisToMember(),
           "7:9-7:17:warning:" + Bundle.ERR_AddThisToMember())
       .findWarning("6:9-6:18:warning:" + Bundle.ERR_AddThisToMember())
       .applyFix()
       .assertCompilable()
       .assertOutput(
           "package example;\n"
               + "public class Test {\n"
               + "    int variable=42;\n"
               + "    static void staticMember() {};\n"
               + "    void getMember(){\n"
               + "         staticMember();\n"
               + "         this.getMember();\n"
               + "         this.getMember();\n"
               + "         variable = 43;\n"
               + "    };\n"
               + "}");
 }
 @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");
 }