mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: merged MalformedSetUpTearDownInspection
This commit is contained in:
@@ -357,6 +357,18 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
"</profile>");
|
||||
}
|
||||
|
||||
public void testMergedMalformedSetUpTearDownInspections() throws Exception {
|
||||
checkMergedNoChanges("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"" + PROFILE + "\" />\n" +
|
||||
" <inspection_tool class=\"SetupIsPublicVoidNoArg\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\" />\n" +
|
||||
" <inspection_tool class=\"TeardownIsPublicVoidNoArg\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\" />\n" +
|
||||
"</profile>");
|
||||
checkMergedNoChanges("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"" + PROFILE + "\" />\n" +
|
||||
" <inspection_tool class=\"MalformedSetUpTearDown\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\" />\n" +
|
||||
"</profile>");
|
||||
}
|
||||
|
||||
public void testMergedThrowableNotThrownInspections() throws Exception {
|
||||
checkMergedNoChanges("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"" + PROFILE + "\" />\n" +
|
||||
|
||||
+5
-8
@@ -4,6 +4,7 @@
|
||||
|
||||
<inspectionElementsMerger implementation="com.siyeh.ig.bugs.ThrowableNeverThrownInspectionMerger"/>
|
||||
<inspectionElementsMerger implementation="com.siyeh.ig.naming.MisspelledMethodNameInspectionMerger"/>
|
||||
<inspectionElementsMerger implementation="com.siyeh.ig.junit.MalformedSetUpTearDownInspectionMerger"/>
|
||||
|
||||
<!--group.names.abstraction.issues-->
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="BooleanParameter" bundle="com.siyeh.InspectionGadgetsBundle" key="boolean.parameter.display.name"
|
||||
@@ -1466,6 +1467,10 @@
|
||||
key="junit.test.class.naming.convention.display.name" groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.junit.JUnitTestClassNamingConventionInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="MalformedSetUpTearDown" bundle="com.siyeh.InspectionGadgetsBundle"
|
||||
key="malformed.set.up.tear.down.display.name" groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.junit.MalformedSetUpTearDownInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" suppressId="MisorderedAssertEqualsArguments" alternativeId="MisorderedAssertEqualsArguments" shortName="MisorderedAssertEqualsParameters"
|
||||
bundle="com.siyeh.InspectionGadgetsBundle" key="misordered.assert.equals.arguments.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
@@ -1481,10 +1486,6 @@
|
||||
<localInspection groupPath="Java" language="JAVA" suppressId="SetUpDoesntCallSuperSetUp" shortName="SetupCallsSuperSetup" bundle="com.siyeh.InspectionGadgetsBundle"
|
||||
key="setup.calls.super.setup.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.junit.issues"
|
||||
enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.junit.SetupCallsSuperSetupInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" suppressId="SetUpWithIncorrectSignature" shortName="SetupIsPublicVoidNoArg" bundle="com.siyeh.InspectionGadgetsBundle"
|
||||
key="setup.is.public.void.no.arg.display.name" groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.junit.SetupIsPublicVoidNoArgInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="SimplifiableJUnitAssertion" bundle="com.siyeh.InspectionGadgetsBundle"
|
||||
key="simplifiable.junit.assertion.display.name" groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
@@ -1507,10 +1508,6 @@
|
||||
bundle="com.siyeh.InspectionGadgetsBundle" key="teardown.calls.super.teardown.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.junit.TeardownCallsSuperTeardownInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" suppressId="TearDownWithIncorrectSignature" shortName="TeardownIsPublicVoidNoArg"
|
||||
bundle="com.siyeh.InspectionGadgetsBundle" key="teardown.is.public.void.no.arg.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.junit.TeardownIsPublicVoidNoArgInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" suppressId="JUnitTestMethodInProductSource" shortName="TestMethodInProductCode"
|
||||
bundle="com.siyeh.InspectionGadgetsBundle" key="test.method.in.product.code.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
|
||||
|
||||
+3
-5
@@ -764,7 +764,6 @@ class.name.same.as.ancestor.name.display.name=Class name same as ancestor name
|
||||
error.rethrown.display.name='java.lang.Error' not rethrown
|
||||
serializable.has.serialization.methods.display.name=Serializable class without 'readObject()' and 'writeObject()'
|
||||
serializable.has.serialization.methods.ignore.option=Ignore classes that do not define instance fields
|
||||
setup.is.public.void.no.arg.display.name='setUp()' with incorrect signature
|
||||
missing.override.annotation.display.name=Missing @Override annotation
|
||||
wait.while.holding.two.locks.display.name='wait()' while holding two locks
|
||||
empty.class.display.name=Empty class
|
||||
@@ -777,7 +776,6 @@ unnecessary.super.constructor.display.name=Unnecessary call to 'super()'
|
||||
unnecessarily.qualified.static.usage.display.name=Unnecessarily qualified static access
|
||||
bad.exception.caught.display.name=Prohibited exception caught
|
||||
custom.security.manager.display.name=Custom SecurityManager
|
||||
teardown.is.public.void.no.arg.display.name='tearDown()' with incorrect signature
|
||||
string.concatenation.in.loops.display.name=String concatenation in loop
|
||||
boolean.constructor.display.name=Boolean constructor call
|
||||
continue.statement.display.name='continue' statement
|
||||
@@ -1078,9 +1076,7 @@ misordered.assert.equals.arguments.problem.descriptor=Arguments to <code>#ref()<
|
||||
static.suite.problem.descriptor=JUnit <code>#ref()</code> methods not declared 'static' #loc
|
||||
setup.calls.super.setup.problem.descriptor=<code>#ref()</code> does not call 'super.setUp()' #loc
|
||||
teardown.calls.super.teardown.problem.descriptor=<code>#ref()</code> does not call 'super.tearDown()' #loc
|
||||
setup.is.public.void.no.arg.problem.descriptor=<code>#ref()</code> has incorrect signature
|
||||
simplifiable.junit.assertion.problem.descriptor=<code>#ref()</code> can be simplified to ''{0}'' #loc
|
||||
teardown.is.public.void.no.arg.problem.descriptor=<code>#ref()</code> has incorrect signature #loc
|
||||
test.method.without.assertion.problem.descriptor=JUnit test method <code>#ref()</code> contains no assertions #loc
|
||||
test.case.with.no.test.methods.problem.descriptor=JUnit test case <code>#ref</code> has no tests #loc
|
||||
test.case.in.product.code.problem.descriptor=Test case <code>#ref</code> 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}''
|
||||
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
|
||||
+17
-31
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -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" };
|
||||
}
|
||||
}
|
||||
-84
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports JUnit <b>setUp()</b> or <b>tearDown()</b> methods which are not declared
|
||||
<b>public</b>, do not return <b>void</b>, or take arguments.
|
||||
Such <b>setUp()</b> or <b>tearDown()</b> methods are easy to create inadvertently,
|
||||
and will not be executed by JUnit test runners.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,12 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports JUnit classes whose <b>setUp()</b> method
|
||||
is not declared
|
||||
<b>public</b>, does not return <b>void</b>, or takes arguments.
|
||||
Such <b>setUp()</b> methods are easy to create inadvertently,
|
||||
and will not be executed by JUnit tests runners.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,12 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports JUnit classes whose <b>tearDown()</b> method
|
||||
is not declared
|
||||
<b>public</b>, does not return <b>void</b>, or takes arguments.
|
||||
Such <b>tearDown()</b> methods are easy to create inadvertently,
|
||||
and will not be executed by JUnit tests runners.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
+50
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user