summaryrefslogtreecommitdiff
path: root/plugins/InspectionGadgets/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/InspectionGadgets/src/com')
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit3MethodNamingConventionInspection.java30
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit4AnnotatedMethodInJUnit3TestCaseInspection.java31
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit4MethodNamingConventionInspection.java30
3 files changed, 86 insertions, 5 deletions
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit3MethodNamingConventionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit3MethodNamingConventionInspection.java
new file mode 100644
index 000000000000..29dcf0bf1a01
--- /dev/null
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit3MethodNamingConventionInspection.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.siyeh.ig.junit;
+
+import com.siyeh.ig.InspectionGadgetsFix;
+import com.siyeh.ig.fixes.RenameFix;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class JUnit3MethodNamingConventionInspection extends JUnit3MethodNamingConventionInspectionBase {
+
+ @Override
+ protected InspectionGadgetsFix buildFix(Object... infos) {
+ return new RenameFix();
+ }
+}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit4AnnotatedMethodInJUnit3TestCaseInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit4AnnotatedMethodInJUnit3TestCaseInspection.java
index 252411527cc1..89ad944a0f78 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit4AnnotatedMethodInJUnit3TestCaseInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit4AnnotatedMethodInJUnit3TestCaseInspection.java
@@ -18,6 +18,7 @@ package com.siyeh.ig.junit;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.siyeh.InspectionGadgetsBundle;
@@ -41,7 +42,16 @@ public class JUnit4AnnotatedMethodInJUnit3TestCaseInspection extends JUnit4Annot
fixes.add(new RemoveIgnoreAndRename(method));
}
if (TestUtils.isJUnit4TestMethod(method)) {
- fixes.add(new RemoveTestAnnotationFix());
+ String methodName = method.getName();
+ String newMethodName;
+ if (methodName.startsWith("test")) {
+ newMethodName = null;
+ }
+ else {
+ boolean lowCaseStyle = methodName.contains("_");
+ newMethodName = "test" + (lowCaseStyle ? "_" + methodName : StringUtil.capitalize(methodName));
+ }
+ fixes.add(new RemoveTestAnnotationFix(newMethodName));
}
final PsiClass aClass = (PsiClass)infos[0];
final String className = aClass.getName();
@@ -233,22 +243,33 @@ public class JUnit4AnnotatedMethodInJUnit3TestCaseInspection extends JUnit4Annot
}
}
- private static class RemoveTestAnnotationFix extends InspectionGadgetsFix {
+ private static class RemoveTestAnnotationFix extends RenameFix {
+ private final String myNewName;
+
+ public RemoveTestAnnotationFix(String newName) {
+ super(newName);
+ myNewName = newName;
+ }
+
@Override
@NotNull
public String getFamilyName() {
- return getName();
+ return InspectionGadgetsBundle.message("remove.junit4.test.annotation.quickfix");
}
@Override
@NotNull
public String getName() {
- return InspectionGadgetsBundle.message("remove.junit4.test.annotation.quickfix");
+ return myNewName == null ? getFamilyName()
+ : InspectionGadgetsBundle.message("remove.junit4.test.annotation.and.rename.quickfix", myNewName);
}
@Override
- protected void doFix(Project project, ProblemDescriptor descriptor) {
+ public void doFix(Project project, ProblemDescriptor descriptor) {
deleteAnnotation(descriptor, "org.junit.Test");
+ if (myNewName != null) {
+ super.doFix(project, descriptor);
+ }
}
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit4MethodNamingConventionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit4MethodNamingConventionInspection.java
new file mode 100644
index 000000000000..22c8937d48d9
--- /dev/null
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/JUnit4MethodNamingConventionInspection.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.siyeh.ig.junit;
+
+import com.siyeh.ig.InspectionGadgetsFix;
+import com.siyeh.ig.fixes.RenameFix;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class JUnit4MethodNamingConventionInspection extends JUnit4MethodNamingConventionInspectionBase {
+
+ @Override
+ protected InspectionGadgetsFix buildFix(Object... infos) {
+ return new RenameFix();
+ }
+}