#ref() methods not declared 'static' #loc
setup.calls.super.setup.problem.descriptor=#ref() does not call 'super.setUp()' #loc
teardown.calls.super.teardown.problem.descriptor=#ref() does not call 'super.tearDown()' #loc
-setup.is.public.void.no.arg.problem.descriptor=#ref() has incorrect signature
simplifiable.junit.assertion.problem.descriptor=#ref() can be simplified to ''{0}'' #loc
-teardown.is.public.void.no.arg.problem.descriptor=#ref() has incorrect signature #loc
test.method.without.assertion.problem.descriptor=JUnit test method #ref() contains no assertions #loc
test.case.with.no.test.methods.problem.descriptor=JUnit test case #ref has no tests #loc
test.case.in.product.code.problem.descriptor=Test case #ref should probably be placed in a test source tree #loc
@@ -2201,4 +2197,6 @@ expand.to.normal.annotation.name=Single-element annotation
expand.to.normal.annotation.quickfix=Add 'value='
expand.to.normal.annotation.family.quickfix=Expand annotation to normal form
add.array.creation.expression.name=Add array creation expression
-add.array.creation.expression.descriptor=Add ''new {0}''
\ No newline at end of file
+add.array.creation.expression.descriptor=Add ''new {0}''
+malformed.set.up.tear.down.display.name=Malformed 'setUp()' or 'tearDown()'
+malformed.set.up.tear.down.problem.descriptor='#ref()' has incorrect signature #loc
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/SetupIsPublicVoidNoArgInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/MalformedSetUpTearDownInspection.java
similarity index 58%
rename from plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/SetupIsPublicVoidNoArgInspection.java
rename to plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/MalformedSetUpTearDownInspection.java
index 5a70f229ef96..e9701710d578 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/SetupIsPublicVoidNoArgInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/MalformedSetUpTearDownInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
+ * Copyright 2000-2016 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.
@@ -20,65 +20,51 @@ import com.intellij.psi.util.InheritanceUtil;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
+import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
-public class SetupIsPublicVoidNoArgInspection extends BaseInspection {
+/**
+ * @author Bas Leijdekkers
+ */
+public class MalformedSetUpTearDownInspection extends BaseInspection {
- @Override
+ @Nls
@NotNull
- public String getID() {
- return "SetUpWithIncorrectSignature";
- }
-
@Override
- @NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "setup.is.public.void.no.arg.display.name");
+ return InspectionGadgetsBundle.message("malformed.set.up.tear.down.display.name");
}
- @Override
@NotNull
+ @Override
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "setup.is.public.void.no.arg.problem.descriptor");
+ return InspectionGadgetsBundle.message("malformed.set.up.tear.down.problem.descriptor");
}
@Override
public BaseInspectionVisitor buildVisitor() {
- return new SetupIsPublicVoidNoArgVisitor();
+ return new MalformedSetUpTearDownVisitor();
}
- private static class SetupIsPublicVoidNoArgVisitor
- extends BaseInspectionVisitor {
+ private static class MalformedSetUpTearDownVisitor extends BaseInspectionVisitor {
@Override
public void visitMethod(@NotNull PsiMethod method) {
- //note: no call to super;
@NonNls final String methodName = method.getName();
- if (!"setUp".equals(methodName)) {
- return;
- }
- final PsiType returnType = method.getReturnType();
- if (returnType == null) {
+ if (!"setUp".equals(methodName) && !"tearDown".equals(methodName)) {
return;
}
final PsiClass targetClass = method.getContainingClass();
- if (targetClass == null) {
+ if (!InheritanceUtil.isInheritor(targetClass, "junit.framework.TestCase")) {
return;
}
- if (!InheritanceUtil.isInheritor(targetClass,
- "junit.framework.TestCase")) {
- return;
- }
- final PsiParameterList parameterList = method.getParameterList();
- if (parameterList.getParametersCount() != 0 ||
- !returnType.equals(PsiType.VOID) ||
+ if (method.getParameterList().getParametersCount() != 0 ||
+ !PsiType.VOID.equals(method.getReturnType()) ||
!method.hasModifierProperty(PsiModifier.PUBLIC) &&
!method.hasModifierProperty(PsiModifier.PROTECTED)) {
registerMethodError(method);
}
}
}
-}
\ No newline at end of file
+}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/MalformedSetUpTearDownInspectionMerger.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/MalformedSetUpTearDownInspectionMerger.java
new file mode 100644
index 000000000000..57aad6c9efed
--- /dev/null
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/MalformedSetUpTearDownInspectionMerger.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2000-2016 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.intellij.codeInspection.ex.InspectionElementsMerger;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class MalformedSetUpTearDownInspectionMerger extends InspectionElementsMerger {
+
+ @Override
+ public String getMergedToolName() {
+ return "MalformedSetUpTearDown";
+ }
+
+ @Override
+ public String[] getSourceToolNames() {
+ return new String[] { "TearDownWithIncorrectSignature", "SetUpWithIncorrectSignature" };
+ }
+}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/TeardownIsPublicVoidNoArgInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/TeardownIsPublicVoidNoArgInspection.java
deleted file mode 100644
index c5987a49d0ac..000000000000
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/TeardownIsPublicVoidNoArgInspection.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
- *
- * 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.intellij.psi.*;
-import com.intellij.psi.util.InheritanceUtil;
-import com.siyeh.InspectionGadgetsBundle;
-import com.siyeh.ig.BaseInspection;
-import com.siyeh.ig.BaseInspectionVisitor;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-
-public class TeardownIsPublicVoidNoArgInspection extends BaseInspection {
-
- @Override
- @NotNull
- public String getID() {
- return "TearDownWithIncorrectSignature";
- }
-
- @Override
- @NotNull
- public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "teardown.is.public.void.no.arg.display.name");
- }
-
- @Override
- @NotNull
- protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "teardown.is.public.void.no.arg.problem.descriptor");
- }
-
- @Override
- public BaseInspectionVisitor buildVisitor() {
- return new TeardownIsPublicVoidNoArgVisitor();
- }
-
- private static class TeardownIsPublicVoidNoArgVisitor
- extends BaseInspectionVisitor {
-
- @Override
- public void visitMethod(@NotNull PsiMethod method) {
- //note: no call to super;
- @NonNls final String methodName = method.getName();
- if (!"tearDown".equals(methodName)) {
- return;
- }
- final PsiType returnType = method.getReturnType();
- if (returnType == null) {
- return;
- }
- final PsiClass targetClass = method.getContainingClass();
- if (targetClass == null) {
- return;
- }
- if (!InheritanceUtil.isInheritor(targetClass,
- "junit.framework.TestCase")) {
- return;
- }
- final PsiParameterList parameterList = method.getParameterList();
- if (parameterList.getParametersCount() != 0 ||
- !returnType.equals(PsiType.VOID) ||
- !method.hasModifierProperty(PsiModifier.PUBLIC) &&
- !method.hasModifierProperty(PsiModifier.PROTECTED)) {
- registerMethodError(method);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/MalformedSetUpTearDown.html b/plugins/InspectionGadgets/src/inspectionDescriptions/MalformedSetUpTearDown.html
new file mode 100644
index 000000000000..c5e9de1bd63d
--- /dev/null
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/MalformedSetUpTearDown.html
@@ -0,0 +1,11 @@
+
+
+Reports JUnit setUp() or tearDown() methods which are not declared
+public, do not return void, or take arguments.
+Such setUp() or tearDown() methods are easy to create inadvertently,
+and will not be executed by JUnit test runners.
+
++ + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/SetupIsPublicVoidNoArg.html b/plugins/InspectionGadgets/src/inspectionDescriptions/SetupIsPublicVoidNoArg.html deleted file mode 100644 index 5b7b333a6a49..000000000000 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/SetupIsPublicVoidNoArg.html +++ /dev/null @@ -1,12 +0,0 @@ - -
-Reports JUnit classes whose setUp() method -is not declared -public, does not return void, or takes arguments. -Such setUp() methods are easy to create inadvertently, -and will not be executed by JUnit tests runners. - -- - - \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/TeardownIsPublicVoidNoArg.html b/plugins/InspectionGadgets/src/inspectionDescriptions/TeardownIsPublicVoidNoArg.html deleted file mode 100644 index 9070b10bd68d..000000000000 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/TeardownIsPublicVoidNoArg.html +++ /dev/null @@ -1,12 +0,0 @@ - -
-Reports JUnit classes whose tearDown() method -is not declared -public, does not return void, or takes arguments. -Such tearDown() methods are easy to create inadvertently, -and will not be executed by JUnit tests runners. - -- - - \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/MalformedSetUpTearDownInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/MalformedSetUpTearDownInspectionTest.java new file mode 100644 index 000000000000..8a9fb231c227 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/MalformedSetUpTearDownInspectionTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2016 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.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; + +/** + * @author Bas Leijdekkers + */ +public class MalformedSetUpTearDownInspectionTest extends LightInspectionTestCase { + + public void testSimple() { + doTest("import junit.framework.*;" + + "class C extends TestCase {" + + " private void /*'setUp()' has incorrect signature*/setUp/**/(int i) {}" + + "}"); + } + + @Override + protected String[] getEnvironmentClasses() { + return new String[] { + "package junit.framework;" + + "public abstract class TestCase {" + + " protected void setUp() throws Exception {}" + + " protected void tearDown() throws Exception {}" + + "}" + }; + } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new MalformedSetUpTearDownInspection(); + } +} \ No newline at end of file