[junit] Move Java JUnit inspections into JUnit plugin

#IDEA-341929 Fixed

GitOrigin-RevId: 7dd42203f64380382b3d39c77a409fe652b09941
This commit is contained in:
Bart van Helvert
2023-12-28 23:17:28 +00:00
committed by intellij-monorepo-bot
parent 2f289ccda6
commit 271d362d14
56 changed files with 582 additions and 682 deletions
+1
View File
@@ -819,6 +819,7 @@
<module fileurl="file://$PROJECT_DIR$/java/jsp-base-openapi/intellij.jsp.base.iml" filepath="$PROJECT_DIR$/java/jsp-base-openapi/intellij.jsp.base.iml" />
<module fileurl="file://$PROJECT_DIR$/java/jsp-spi/intellij.jsp.spi.iml" filepath="$PROJECT_DIR$/java/jsp-spi/intellij.jsp.spi.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/junit/intellij.junit.iml" filepath="$PROJECT_DIR$/plugins/junit/intellij.junit.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/junit/groovy-tests/intellij.junit.groovy.tests.iml" filepath="$PROJECT_DIR$/plugins/junit/groovy-tests/intellij.junit.groovy.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/junit/java-tests/intellij.junit.java.tests.iml" filepath="$PROJECT_DIR$/plugins/junit/java-tests/intellij.junit.java.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/junit/kotlin-tests/intellij.junit.kotlin.tests.iml" filepath="$PROJECT_DIR$/plugins/junit/kotlin-tests/intellij.junit.kotlin.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/junit_rt/intellij.junit.rt.iml" filepath="$PROJECT_DIR$/plugins/junit_rt/intellij.junit.rt.iml" />
@@ -1695,8 +1695,6 @@ unnecessary.inherit.doc.class.invalid.problem.descriptor=<code>#ref</code> is no
unnecessary.inherit.doc.module.invalid.problem.descriptor=<code>#ref</code> is not valid on module declarations #loc
unnecessary.inherit.doc.constructor.no.super.problem.descriptor=No super method found to inherit Javadoc from #loc
unnecessary.inherit.doc.quickfix=Remove unnecessary {@inheritDoc}
multiple.exceptions.declared.on.test.method.display.name=Multiple exceptions declared on test method
multiple.exceptions.declared.on.test.method.problem.descriptor=<code>#ref</code> could be replaced with 'throws Exception' #loc
unnecessary.javadoc.link.display.name=Unnecessary Javadoc link
unnecessary.javadoc.link.super.method.problem.descriptor=<code>#ref</code> pointing to super method is unnecessary #loc
unnecessary.javadoc.link.this.method.problem.descriptor=<code>#ref</code> pointing to this method is unnecessary #loc
@@ -1729,8 +1727,6 @@ choose.class=Choose Class
query.label=Query names start with:
update.label=Update names start with:
assert.keyword.is.considered.an.assertion='assert' keyword is considered an assertion
expected.exception.never.thrown.display.name=Expected exception never thrown in test method body
expected.exception.never.thrown.problem.descriptor=Expected <code>#ref</code> never thrown in body of ''{0}()'' #loc
choose.logger.class=Choose Logger Class
logger.class.name=Logger class names:
ignore.exceptions.declared.on.library.override.option=Ignore exceptions declared on methods overriding a &library method
@@ -1868,9 +1864,6 @@ use.of.concrete.class.option.report.cast=Report type used in cast expression
class.only.used.in.one.package.display.name=Class only used from one other package
class.only.used.in.one.package.problem.descriptor=Class <code>#ref</code> has only dependencies on and/or dependents in package ''{0}'' #loc
unnecessary.return.option=Ignore in then branch of 'if' statement with 'else' branch
usage.of.obsolete.assert.display.name=Usage of obsolete 'junit.framework.Assert' method
use.of.obsolete.assert.problem.descriptor=Call to <code>#ref()</code> from ''{0}'' should be replaced with call to method from ''org.junit.Assert'' #loc
use.of.obsolete.assert.quickfix=Replace with 'org.junit.Assert' method call
unclear.binary.expression.display.name=Multiple operators with different precedence
unclear.binary.expression.problem.descriptor=Expression could use clarifying parentheses #loc
unclear.binary.expression.quickfix=Add clarifying parentheses
@@ -1914,8 +1907,6 @@ public.constructor.display.name='public' constructor can be replaced with factor
public.default.constructor.problem.descriptor=Class <code>#ref</code> has 'public' default constructor
public.constructor.problem.descriptor=Public constructor <code>#ref()</code> #loc
public.constructor.quickfix=Replace constructor with factory method
junit3.style.test.method.in.junit4.class.display.name=Old style JUnit test method in JUnit 4 class
junit3.style.test.method.in.junit4.class.problem.descriptor=Old style JUnit test method <code>#ref()</code> in JUnit 4 class #loc
none=none
private=private
package.local.private=package-private \\& private
@@ -2452,12 +2443,6 @@ inspection.comparator.combinators.description=Can be replaced with 'Comparator'
inspection.comparator.combinators.description2=Can be replaced with ''{0}''
inspection.unnecessary.string.escape.report.char.literals.option=Report char literals
inspection.method.call.in.loop.ignore.known.methods.option=Ignore known methods with side-effects
fix.data.provider.signature.fix.name=Change method signature to ''{0}''
fix.data.provider.create.method.fix.name=Create data provider method '@Parameters public static Iterable<Object> parameters()'
fix.data.provider.signature.family.name=Fix data provider method signature
fix.data.provider.signature.missing.method.problem=Parameterized test class <code>#ref</code> lacks data provider method annotated with '@Parameters'
fix.data.provider.signature.incorrect.problem=Data provider method <code>#ref()</code> has an incorrect signature
fix.data.provider.multiple.methods.problem=Multiple @Parameters data provider methods present in class <code>#ref</code>
throws.runtime.exception.fix.family.name=Remove from 'throws' clause
move.exception.to.javadoc.fix.family.name=Move to Javadoc '@throws'
create.package.info.java.family.name=Create 'package-info.java'
@@ -2471,7 +2456,6 @@ inspection.collection.must.have.initial.capacity.initializers.option=Don't repor
utility.class.without.private.constructor.cant.generate.constructor.message=Utility class has instantiations, private constructor will not be created
inspection.suspicious.package.private.access.problem={0} overrides a package-private method from {1} which is declared in a different module ''{2}''
inspection.condition.covered.by.further.condition.descr=Condition ''{0}'' covered by subsequent {1, choice, 1#condition ''''{2}''''|2#conditions}
inspection.parameterized.parameters.static.collection.display.name=Parameterized test class without data provider method
create.missing.switch.branch=Create missing switch branch ''{0}''
create.missing.switch.branches=Create missing branches: {0}
redundant.as.list.for.iteration.problem=Unnecessary 'Arrays.asList()' call
@@ -1370,40 +1370,21 @@
bundle="messages.InspectionGadgetsBundle" key="asserts.without.messages.display.name"
groupBundle="messages.InspectionsBundle" groupKey="group.names.test.frameworks.issues" enabledByDefault="false" level="WARNING"
implementationClass="com.siyeh.ig.testFrameworks.AssertWithoutMessageInspection"/>
<localInspection groupPath="Java" language="JAVA" shortName="ExpectedExceptionNeverThrown" bundle="messages.InspectionGadgetsBundle"
key="expected.exception.never.thrown.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
implementationClass="com.siyeh.ig.junit.ExpectedExceptionNeverThrownInspection"/>
<localInspection groupPath="Java" language="JAVA" shortName="ParameterizedParametersStaticCollection"
groupBundle="messages.InspectionsBundle" groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
implementationClass="com.siyeh.ig.junit.ParameterizedParametersStaticCollectionInspection"
key="inspection.parameterized.parameters.static.collection.display.name" bundle="messages.InspectionGadgetsBundle"/>
<localInspection groupPath="Java" language="JAVA" shortName="ConstantAssertArgument" bundle="messages.InspectionGadgetsBundle"
key="constant.junit.assert.argument.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.test.frameworks.issues" enabledByDefault="false" level="WARNING"
implementationClass="com.siyeh.ig.testFrameworks.ConstantAssertArgumentInspection"/>
<inspectionElementsMerger implementation="com.siyeh.ig.testFrameworks.ConstantAssertArgumentMerger"/>
<localInspection groupPath="Java" language="JAVA" shortName="JUnit3StyleTestMethodInJUnit4Class" bundle="messages.InspectionGadgetsBundle"
key="junit3.style.test.method.in.junit4.class.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.junit.issues" enabledByDefault="true" level="WARNING"
implementationClass="com.siyeh.ig.junit.JUnit3StyleTestMethodInJUnit4ClassInspection"/>
<localInspection groupPath="Java" language="JAVA" shortName="MisorderedAssertEqualsArguments"
bundle="messages.InspectionGadgetsBundle" key="misordered.assert.equals.arguments.display.name"
groupBundle="messages.InspectionsBundle" groupKey="group.names.test.frameworks.issues" enabledByDefault="false" level="WARNING"
implementationClass="com.siyeh.ig.testFrameworks.MisorderedAssertEqualsArgumentsInspection"/>
<inspectionElementsMerger implementation="com.siyeh.ig.testFrameworks.MisorderedAssertEqualsArgumentsMerger"/>
<localInspection groupPath="Java" language="JAVA" shortName="MultipleExceptionsDeclaredOnTestMethod" bundle="messages.InspectionGadgetsBundle"
key="multiple.exceptions.declared.on.test.method.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
implementationClass="com.siyeh.ig.junit.MultipleExceptionsDeclaredOnTestMethodInspection" cleanupTool="true"/>
<localInspection groupPath="Java" language="JAVA" shortName="SimplifiableAssertion" bundle="messages.InspectionGadgetsBundle"
key="simplifiable.junit.assertion.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.test.frameworks.issues" enabledByDefault="true" level="WARNING"
implementationClass="com.siyeh.ig.testFrameworks.SimplifiableAssertionInspection" cleanupTool="true"/>
<inspectionElementsMerger implementation="com.siyeh.ig.testFrameworks.SimplifiableAssertionMerger"/>
<localInspection groupPath="Java" language="JAVA" shortName="UseOfObsoleteAssert" bundle="messages.InspectionGadgetsBundle" key="usage.of.obsolete.assert.display.name"
groupBundle="messages.InspectionsBundle" groupKey="group.names.junit.issues" enabledByDefault="false" level="WARNING"
implementationClass="com.siyeh.ig.junit.UseOfObsoleteAssertInspection" cleanupTool="true"/>
<!--group.names.logging.issues-->
<localInspection groupPath="Java" language="JAVA" shortName="ClassWithMultipleLoggers" bundle="messages.InspectionGadgetsBundle" key="multiple.loggers.display.name"
@@ -1557,9 +1538,7 @@
groupBundle="messages.InspectionsBundle" groupKey="group.names.naming.conventions.class" enabledByDefault="true"
level="WARNING" implementationClass="com.siyeh.ig.naming.NewClassNamingConventionInspection"/>
<inspectionElementsMerger implementation="com.siyeh.ig.naming.ClassNamingConventionMerger"/>
<naming.convention.class implementation="com.siyeh.ig.junit.AbstractTestClassNamingConvention" id="JUnitAbstractTestClassNamingConvention" order="first"/>
<naming.convention.class implementation="com.siyeh.ig.junit.TestSuiteNamingConvention" id="TestSuiteNamingConvention" order="after JUnitAbstractTestClassNamingConvention"/>
<naming.convention.class implementation="com.siyeh.ig.junit.TestClassNamingConvention" id="JUnitTestClassNamingConvention" order="after TestSuiteNamingConvention"/>
<naming.convention.class implementation="com.siyeh.ig.naming.TypeParameterNamingConvention" id="TypeParameterNamingConvention" order="after JUnitTestClassNamingConvention"/>
<naming.convention.class implementation="com.siyeh.ig.naming.AnnotationNamingConvention" id="AnnotationNamingConvention" order="after TypeParameterNamingConvention"/>
<naming.convention.class implementation="com.siyeh.ig.naming.EnumeratedClassNamingConvention" id="EnumeratedClassNamingConvention" order="after AnnotationNamingConvention"/>
@@ -1575,8 +1554,6 @@
<naming.convention.method implementation="com.siyeh.ig.naming.InstanceMethodNamingConvention" id="InstanceMethodNamingConvention" order="last"/>
<naming.convention.method implementation="com.siyeh.ig.naming.StaticMethodNamingConvention" id="StaticMethodNamingConvention" order="before InstanceMethodNamingConvention"/>
<naming.convention.method implementation="com.siyeh.ig.naming.NativeMethodNamingConvention" id="NativeMethodNamingConvention" order="before StaticMethodNamingConvention"/>
<naming.convention.method implementation="com.siyeh.ig.junit.JUnit4MethodNamingConvention" id="JUnit4MethodNamingConvention" order="before NativeMethodNamingConvention"/>
<naming.convention.method implementation="com.siyeh.ig.junit.JUnit3MethodNamingConvention" id="JUnit3MethodNamingConvention" order="before JUnit4MethodNamingConvention"/>
<localInspection groupPathKey="group.path.naming.conventions" language="JAVA" shortName="BooleanMethodNameMustStartWithQuestion" bundle="messages.InspectionGadgetsBundle"
key="boolean.method.name.must.start.with.question.display.name" groupBundle="messages.InspectionsBundle"
@@ -1,9 +0,0 @@
import org.junit.Before;
public class BeforeAnnotationUsed {
@Before
public void before() {}
public void <warning descr="Old style JUnit test method 'testOldStyle()' in JUnit 4 class">testOldStyle</warning>() {}
}
@@ -1,10 +0,0 @@
import org.junit.Test;
public class JUnit3StyleTestMethodInJUnit4Class {
@Test
public void junit4Test() {
}
public void <warning descr="Old style JUnit test method 'testJUnit3()' in JUnit 4 class">testJUnit3</warning>() {}
}
@@ -1,18 +0,0 @@
import org.junit.*;
public class OtherAnnotation {
@Test
public void testFoo() {}
public void <warning descr="Old style JUnit test method 'testSmth()' in JUnit 4 class">testSmth</warning>() {}
@Ignore
public void testIgnored() {}
@After
public void testAfter() {}
@Before
public void testBefore() {}
}
@@ -1,22 +0,0 @@
/*
* 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.
*/
import org.junit.jupiter.api.Test;
public class SimpleJUnit5 {
@Test
public void testIt() {
}
}
@@ -1,7 +0,0 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class CorrectSignature {
@org.junit.runners.Parameterized.Parameters
public static Object[] parameters() {
return null;
}
}
@@ -1,7 +0,0 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class CorrectSignature2 {
@org.junit.runners.Parameterized.Parameters
public static Iterable<Object[]> parameters() {
return null;
}
}
@@ -1,9 +0,0 @@
import org.junit.runners.Parameterized;
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class Createmethod {
@Parameterized.Parameters
public static Iterable<Object[]> parameters() {
return null;
}
}
@@ -1,2 +0,0 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class <warning descr="Parameterized test class 'Createmethod' lacks data provider method annotated with '@Parameters'"><caret>Createmethod</warning> {}
@@ -1,12 +0,0 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class <warning descr="Multiple @Parameters data provider methods present in class 'MultipleMethods'">MultipleMethods</warning> {
@org.junit.runners.Parameterized.Parameters
public static Object[] parameters() {
return null;
}
@org.junit.runners.Parameterized.Parameters
public static Object[] parameters2() {
return null;
}
}
@@ -1,7 +0,0 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class Wrongsignature {
@org.junit.runners.Parameterized.Parameters
public static java.util.Collection regExValues() {
return null;
}
}
@@ -1,7 +0,0 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class Wrongsignature {
@org.junit.runners.Parameterized.Parameters
java.util.Collection <warning descr="Data provider method 'regExValues()' has an incorrect signature"><caret>regExValues</warning>() {
return null;
}
}
@@ -1,7 +0,0 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class Wrongsignature1 {
@org.junit.runners.Parameterized.Parameters
static Integer <warning descr="Data provider method 'regExValues()' has an incorrect signature">regExValues</warning>() {
return null;
}
}
@@ -1,7 +0,0 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class Wrongsignature2 {
@org.junit.runners.Parameterized.Parameters
public static Integer <warning descr="Data provider method 'regExValues()' has an incorrect signature">regExValues</warning>() {
return null;
}
}
@@ -1,7 +0,0 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class Wrongsignature3 {
@org.junit.runners.Parameterized.Parameters
public static Integer[] <warning descr="Data provider method 'regExValues()' has an incorrect signature">regExValues</warning>() {
return null;
}
}
@@ -1,10 +0,0 @@
public class JUnit3MethodNamingConvention extends junit.framework.TestCase {
public void <warning descr="JUnit 3 test method name 'testA' is too short (5 < 8)">testA</warning>() {}
public void <warning descr="JUnit 3 test method name 'testAbcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' is too long (82 > 64)">testAbcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz</warning>() {}
public void <warning descr="JUnit 3 test method name 'testGiveMeMore$$$' doesn't match regex 'test[A-Za-z_\d]*'">testGiveMeMore$$$</warning>() {}
public void test_me_properly() {}
}
@@ -1,16 +0,0 @@
import org.junit.Test;
public class JUnit4MethodNamingConvention {
@Test
public void <warning descr="JUnit 4+ test method name 'a' is too short (1 < 4)">a</warning>() {}
@Test
public void <warning descr="JUnit 4+ test method name 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' is too long (78 > 64)">abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz</warning>() {}
@Test
public void <warning descr="JUnit 4+ test method name 'more$$$' doesn't match regex '[a-z][A-Za-z_\d]*'">more$$$</warning>() {}
@Test
public void assure_foo_is_never_null() {}
}
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiModifier;
import com.intellij.psi.search.scope.packageSet.NamedScope;
import com.intellij.testFramework.InspectionsKt;
import com.intellij.testFramework.LightIdeaTestCase;
import com.siyeh.ig.junit.TestClassNamingConvention;
import com.intellij.execution.junit.codeInspection.naming.TestClassNamingConvention;
import com.siyeh.ig.naming.ClassNamingConvention;
import com.siyeh.ig.naming.FieldNamingConventionInspection;
import com.siyeh.ig.naming.NewClassNamingConventionInspection;
@@ -1,80 +0,0 @@
/*
* Copyright 2000-2011 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.fixes.junit;
import com.intellij.testFramework.PsiTestUtil;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.IGQuickFixesTestCase;
import com.siyeh.ig.junit.UseOfObsoleteAssertInspection;
public class UseOfObsoleteAssertInspectionTest extends IGQuickFixesTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
myFixture.addClass("package junit.framework; public class Assert { public static void fail(){}" +
"public static void assertEquals(double d1, double d2, double d3) {}" +
"public static void assertEquals(Object o1, Object o2) {}" +
"}");
myFixture.addClass("package junit.framework; public class TestCase extends Assert {}");
myFixture.addClass("package org.junit; public class Assert { " +
"public static void fail(){}" +
"@Deprecated public static void assertEquals(double d1, double d2) {}" +
" public static void assertEquals(double d1, double d2, double d3) {}}");
myFixture.enableInspections(new UseOfObsoleteAssertInspection());
}
public void testExtendsTestCase() {
doFixTest();
}
public void testStaticAccess() {
doFixTest();
}
public void testSingleStaticAccess() {
doFixTest();
}
public void testOnDemandStaticImport() {
doFixTest();
}
public void testStaticImport() {
doFixTest();
}
public void testSingleStaticImport() {
PsiTestUtil.disablePsiTextConsistencyChecks(getTestRootDisposable());
doFixTest();
}
public void testAddingDeltaToAvoidFailure() {
PsiTestUtil.disablePsiTextConsistencyChecks(getTestRootDisposable());
doFixTest();
}
private void doFixTest() {
doTest(getTestName(true), InspectionGadgetsBundle.message("use.of.obsolete.assert.quickfix"));
}
@Override
protected String getRelativePath() {
return "junit/useOfObsoleteAssert";
}
}
@@ -1,53 +0,0 @@
package com.siyeh.ig.junit;
import com.intellij.codeInspection.LocalInspectionTool;
import com.siyeh.ig.LightJavaInspectionTestCase;
/**
* @author Bas Leijdekkers
*/
public class ExpectedExceptionNeverThrownInspectionTest extends LightJavaInspectionTestCase {
@Override
protected LocalInspectionTool getInspection() {
return new ExpectedExceptionNeverThrownInspection();
}
@Override
protected String[] getEnvironmentClasses() {
return new String[] {"package org.junit; " +
"public @interface Test {\n" +
" java.lang.Class<? extends java.lang.Throwable> expected() default org.junit.Test.None.class;" +
"}"};
}
public void testSimple() {
doTest("class X {" +
" @org.junit.Test(expected=/*Expected 'java.io.IOException' never thrown in body of 'test()'*/java.io.IOException/**/.class)" +
" public void test() {}" +
"}");
}
public void testInheritance() {
doTest("class X {" +
" @org.junit.Test(expected=java.io.EOFException.class)" +
" public void test() throws Exception {" +
" foo();" +
" }" +
" void foo() throws java.io.IOException {}" +
"}");
}
public void testError() {
doTest("class X {" +
" @org.junit.Test(expected = Error.class)" +
" public void test() {}" +
"}");
}
public void testRuntimeException() {
doTest("class X {" +
" @org.junit.Test(expected = IllegalArgumentException.class)" +
" public void test() {}" +
"}");
}
}
@@ -1,48 +0,0 @@
/*
* 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.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.naming.AbstractMethodNamingConventionInspectionTest;
import com.siyeh.ig.naming.NewMethodNamingConventionInspection;
import org.jetbrains.annotations.Nullable;
/**
* @author Bas Leijdekkers
*/
public class JUnit3MethodNamingConventionInspectionTest extends AbstractMethodNamingConventionInspectionTest {
public void testJUnit3MethodNamingConvention() { doTest(); }
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
NewMethodNamingConventionInspection inspection = new NewMethodNamingConventionInspection();
inspection.setEnabled(true, new JUnit3MethodNamingConvention().getShortName());
return inspection;
}
@Override
protected String[] getEnvironmentClasses() {
return new String[] {
"package junit.framework;" +
"public abstract class TestCase {" +
" protected void setUp() throws Exception {}" +
" protected void tearDown() throws Exception {}" +
"}"
};
}
}
@@ -1,58 +0,0 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.siyeh.ig.junit;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.LightJavaInspectionTestCase;
import org.jetbrains.annotations.Nullable;
/**
* @author Bas Leijdekkers
*/
public class JUnit3StyleTestMethodInJUnit4ClassInspectionTest extends LightJavaInspectionTestCase {
public void testJUnit3StyleTestMethodInJUnit4Class() { doTest(); }
public void testBeforeAnnotationUsed() { doTest(); }
public void testSimpleJUnit5() { doTest(); }
public void testOtherAnnotation() { doTest(); }
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
return new JUnit3StyleTestMethodInJUnit4ClassInspection();
}
@Override
protected String[] getEnvironmentClasses() {
return new String[] {
"package org.junit;" +
"import java.lang.annotation.*;" +
"@Retention(RetentionPolicy.RUNTIME)" +
"@Target({ElementType.METHOD})" +
"public @interface Before {}",
"package org.junit;" +
"import java.lang.annotation.*;" +
"@Retention(RetentionPolicy.RUNTIME)" +
"@Target({ElementType.METHOD})" +
"public @interface After {}",
"package org.junit;" +
"import java.lang.annotation.*;" +
"@Retention(RetentionPolicy.RUNTIME)" +
"@Target({ElementType.METHOD})" +
"public @interface Ignore {}",
"package org.junit;" +
"import java.lang.annotation.*;" +
"@Retention(RetentionPolicy.RUNTIME)" +
"@Target({ElementType.METHOD})" +
"public @interface Test {}",
"package org.junit.jupiter.api;" +
"import org.junit.platform.commons.annotation.Testable;" +
"import java.lang.annotation.*;" +
"@Retention(RetentionPolicy.RUNTIME)" +
"@Target({ElementType.METHOD})" +
"@Testable " +
"public @interface Test {}",
"package org.junit.platform.commons.annotation;" +
"public @interface Testable {}"
};
}
}
@@ -1,51 +0,0 @@
/*
* 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.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.naming.AbstractMethodNamingConventionInspectionTest;
import com.siyeh.ig.naming.NewMethodNamingConventionInspection;
import org.jetbrains.annotations.Nullable;
/**
* @author Bas Leijdekkers
*/
public class JUnit4MethodNamingConventionInspectionTest extends AbstractMethodNamingConventionInspectionTest {
public void testJUnit4MethodNamingConvention() { doTest(); }
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
NewMethodNamingConventionInspection inspection = new NewMethodNamingConventionInspection();
inspection.setEnabled(true, new JUnit4MethodNamingConvention().getShortName());
return inspection;
}
@Override
protected String[] getEnvironmentClasses() {
return new String[] {
"package org.junit;" +
"import java.lang.annotation.ElementType;" +
"import java.lang.annotation.Retention;" +
"import java.lang.annotation.RetentionPolicy;" +
"import java.lang.annotation.Target;" +
"@Retention(RetentionPolicy.RUNTIME)" +
"@Target({ElementType.METHOD})" +
"public @interface Test {}"
};
}
}
@@ -1,69 +0,0 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.siyeh.ig.junit;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.LightJavaInspectionTestCase;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
public class ParameterizedParametersStaticCollectionInspectionTest extends LightJavaCodeInsightFixtureTestCase {
@Override
protected String getBasePath() {
return LightJavaInspectionTestCase.INSPECTION_GADGETS_TEST_DATA_PATH + "com/siyeh/igtest/junit/parameterized";
}
@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.addClass("""
package org.junit.runner;
public @interface RunWith {
Class value();
}
""");
myFixture.addClass("""
package org.junit.runners;
public class Parameterized { public @interface Parameters {
String name() default "{index}";
}}\s""");
}
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_8;
}
private void doTest() {
myFixture.enableInspections(new ParameterizedParametersStaticCollectionInspection());
myFixture.testHighlighting(getTestName(false) + ".java");
}
private void checkQuickFix(@NotNull @Nls String intentionName) {
final IntentionAction intention = myFixture.getAvailableIntention(intentionName);
assertNotNull(intention);
myFixture.launchAction(intention);
myFixture.checkResultByFile(getTestName(false) + ".after.java");
}
public void testCreatemethod() {
doTest();
checkQuickFix(InspectionGadgetsBundle.message("fix.data.provider.create.method.fix.name"));
}
public void testWrongsignature() {
doTest();
checkQuickFix(InspectionGadgetsBundle.message("fix.data.provider.signature.fix.name", "public static Collection regExValues()"));
}
public void testWrongsignature1() { doTest(); }
public void testWrongsignature2() { doTest(); }
public void testWrongsignature3() { doTest(); }
public void testCorrectSignature() { doTest(); }
public void testCorrectSignature2() { doTest(); }
public void testMultipleMethods() { doTest(); }
}
@@ -1,52 +0,0 @@
/*
* 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.LightJavaInspectionTestCase;
/**
* @author Bas Leijdekkers
*/
public class UseOfObsoleteAssertInspectionTest extends LightJavaInspectionTestCase {
public void testObsoleteAssert() { doTest(); }
@Override
protected String[] getEnvironmentClasses() {
return new String[] {
"package junit.framework;" +
"public class Assert {" +
" static public void assertEquals(String message, int expected, int actual) {}" +
"}",
"package junit.framework;" +
"public class TestCase extends Assert {" +
" public static void assertEquals(String message, int expected, int actual) {" +
" Assert.assertEquals(message, expected, actual);" +
" }" +
"}",
"package org.junit;" +
"public class Assert {}"
};
}
@Override
protected InspectionProfileEntry getInspection() {
return new UseOfObsoleteAssertInspection();
}
}
@@ -3,8 +3,8 @@ package com.siyeh.ig.naming;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.LightJavaInspectionTestCase;
import com.siyeh.ig.junit.TestClassNamingConvention;
import com.siyeh.ig.junit.TestSuiteNamingConvention;
import com.intellij.execution.junit.codeInspection.naming.TestClassNamingConvention;
import com.intellij.execution.junit.codeInspection.naming.TestSuiteNamingConvention;
/**
* @author Bas Leijdekkers
@@ -1,3 +1,3 @@
package com.intellij.jvm.analysis.testFramework
enum class JvmLanguage(val ext: String) { JAVA(".java"), KOTLIN(".kt") }
enum class JvmLanguage(val ext: String) { JAVA(".java"), KOTLIN(".kt"), GROOVY(".groovy") }
@@ -1,11 +1,8 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.groovy.lang.highlighting
import com.siyeh.ig.junit.AbstractTestClassNamingConvention
import com.siyeh.ig.junit.TestClassNamingConvention
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection
import org.jetbrains.plugins.groovy.codeInspection.bugs.GroovyConstructorNamedArgumentsInspection
import org.jetbrains.plugins.groovy.codeInspection.naming.NewGroovyClassNamingConventionInspection
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection
import org.jetbrains.plugins.groovy.codeInspection.unusedDef.UnusedDefInspection
import org.jetbrains.plugins.groovy.transformations.TransformationUtilKt
@@ -290,14 +287,6 @@ class Bar {{
void testExtendingOwnInner() { doTest() }
void testJUnitConvention() {
myFixture.addClass("package junit.framework; public class TestCase {}")
def inspection = new NewGroovyClassNamingConventionInspection()
inspection.setEnabled(true, TestClassNamingConvention.TEST_CLASS_NAMING_CONVENTION_SHORT_NAME)
inspection.setEnabled(true, AbstractTestClassNamingConvention.ABSTRACT_TEST_CLASS_NAMING_CONVENTION_SHORT_NAME)
doTest(inspection)
}
void testDuplicateMethods() {
myFixture.configureByText('a.groovy', '''\
class A {
@@ -1,11 +0,0 @@
import junit.framework.TestCase
class SpecialGoodTest extends TestCase {
class MyVeryInner extends SpecialGoodTest {}
}
class <warning descr="Test class name 'SpecialBad' doesn't match regex '[A-Z][A-Za-z\d]*Test(s|Case)?|Test[A-Z][A-Za-z\d]*|IT(.*)|(.*)IT(Case)?'">SpecialBad</warning> extends TestCase { }
class TestInTheBeginning extends TestCase { }
class WithTests extends TestCase { }
class WithTestCase extends TestCase { }
abstract class <warning descr="Abstract test class name 'SpecialAbstract' doesn't match regex '[A-Z][A-Za-z\d]*TestCase'">SpecialAbstract</warning> extends TestCase { }
abstract class SpecialAbstractTestCase extends TestCase { }
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="intellij.groovy" scope="TEST" />
<orderEntry type="module" module-name="intellij.junit.testFramework" scope="TEST" />
</component>
</module>
@@ -0,0 +1,47 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.junit.codeInspection.naming
import com.intellij.junit.testFramework.addJUnit3Library
import com.intellij.jvm.analysis.testFramework.JvmInspectionTestBase
import com.intellij.jvm.analysis.testFramework.JvmLanguage
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ContentEntry
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.pom.java.LanguageLevel
import com.intellij.testFramework.LightProjectDescriptor
import org.jetbrains.plugins.groovy.codeInspection.naming.NewGroovyClassNamingConventionInspection
class GroovyJUnit3NamingConventionInspectionTest : JvmInspectionTestBase() {
override val inspection by lazy {
NewGroovyClassNamingConventionInspection().apply {
setEnabled(true, TestClassNamingConvention.TEST_CLASS_NAMING_CONVENTION_SHORT_NAME)
setEnabled(true, AbstractTestClassNamingConvention.ABSTRACT_TEST_CLASS_NAMING_CONVENTION_SHORT_NAME)
}
}
private class JUnitProjectDescriptor(languageLevel: LanguageLevel) : ProjectDescriptor(languageLevel) {
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
super.configureModule(module, model, contentEntry)
model.addJUnit3Library()
}
}
override fun getProjectDescriptor(): LightProjectDescriptor = JUnitProjectDescriptor(LanguageLevel.HIGHEST)
fun testTestCaseConvention() {
myFixture.testHighlighting(JvmLanguage.GROOVY, """
import junit.framework.TestCase
class SpecialGoodTest extends TestCase {
class MyVeryInner extends SpecialGoodTest {}
}
class <warning descr="Test class name 'SpecialBad' doesn't match regex '[A-Z][A-Za-z\d]*Test(s|Case)?|Test[A-Z][A-Za-z\d]*|IT(.*)|(.*)IT(Case)?'">SpecialBad</warning> extends TestCase { }
class TestInTheBeginning extends TestCase { }
class WithTests extends TestCase { }
class WithTestCase extends TestCase { }
abstract class <warning descr="Abstract test class name 'SpecialAbstract' doesn't match regex '[A-Z][A-Za-z\d]*TestCase'">SpecialAbstract</warning> extends TestCase { }
abstract class SpecialAbstractTestCase extends TestCase { }
""".trimIndent())
}
}
@@ -0,0 +1,64 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.junit.codeInspection
import com.intellij.junit.testFramework.addJUnit4Library
import com.intellij.jvm.analysis.testFramework.JvmInspectionTestBase
import com.intellij.jvm.analysis.testFramework.JvmLanguage
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ContentEntry
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.pom.java.LanguageLevel
import com.intellij.testFramework.LightProjectDescriptor
class JavaExpectedExceptionNeverThrownInspectionTest : JvmInspectionTestBase() {
override val inspection = ExpectedExceptionNeverThrownInspection()
private class JUnitProjectDescriptor(languageLevel: LanguageLevel) : ProjectDescriptor(languageLevel) {
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
super.configureModule(module, model, contentEntry)
model.addJUnit4Library()
}
}
override fun getProjectDescriptor(): LightProjectDescriptor = JUnitProjectDescriptor(LanguageLevel.HIGHEST)
fun testSimple() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
class X {
@org.junit.Test(expected=<warning descr="Expected 'java.io.IOException' never thrown in body of 'test()'">java.io.IOException</warning>.class)
public void test() { }
}
""".trimIndent())
}
fun testInheritance() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
class X {
@org.junit.Test(expected=java.io.EOFException.class)
public void test() throws Exception {
foo();
}
void foo() throws java.io.IOException { }
}
""".trimIndent())
}
fun testError() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
class X {
@org.junit.Test(expected = Error.class)
public void test() { }
}
""".trimIndent())
}
fun testRuntimeException() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
class X {
@org.junit.Test(expected = IllegalArgumentException.class)
public void test() {}
}
""".trimIndent())
}
}
@@ -0,0 +1,85 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.junit.codeInspection
import com.intellij.junit.testFramework.addJUnit4Library
import com.intellij.junit.testFramework.addJUnit5Library
import com.intellij.jvm.analysis.testFramework.JvmInspectionTestBase
import com.intellij.jvm.analysis.testFramework.JvmLanguage
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ContentEntry
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.pom.java.LanguageLevel
import com.intellij.testFramework.LightProjectDescriptor
class JavaJUnit3StyleTestMethodInJUnit4ClassInspectionTest : JvmInspectionTestBase() {
override val inspection = JUnit3StyleTestMethodInJUnit4ClassInspection()
private class JUnitProjectDescriptor(languageLevel: LanguageLevel) : ProjectDescriptor(languageLevel) {
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
super.configureModule(module, model, contentEntry)
model.addJUnit4Library()
model.addJUnit5Library()
}
}
override fun getProjectDescriptor(): LightProjectDescriptor = JUnitProjectDescriptor(LanguageLevel.HIGHEST)
fun testJUnit3StyleTestMethodInJUnit4Class() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
import org.junit.Test;
public class JUnit3StyleTestMethodInJUnit4Class {
@Test
public void junit4Test() { }
public void <warning descr="Old style JUnit test method 'testJUnit3()' in JUnit 4 class">testJUnit3</warning>() { }
}
""".trimIndent())
}
fun testBeforeAnnotationUsed() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
import org.junit.Before;
public class BeforeAnnotationUsed {
@Before
public void before() { }
public void <warning descr="Old style JUnit test method 'testOldStyle()' in JUnit 4 class">testOldStyle</warning>() { }
}
""".trimIndent())
}
fun testSimpleJUnit5() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
import org.junit.jupiter.api.Test;
public class SimpleJUnit5 {
@Test
public void testIt() { }
}
""".trimIndent())
}
fun testOtherAnnotation() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
import org.junit.*;
public class OtherAnnotation {
@Test
public void testFoo() { }
public void <warning descr="Old style JUnit test method 'testSmth()' in JUnit 4 class">testSmth</warning>() { }
@Ignore
public void testIgnored() { }
@After
public void testAfter() { }
@Before
public void testBefore() { }
}
""".trimIndent())
}
}
@@ -0,0 +1,160 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.junit.codeInspection
import com.intellij.execution.JUnitBundle
import com.intellij.junit.testFramework.addJUnit4Library
import com.intellij.junit.testFramework.addJUnit5Library
import com.intellij.jvm.analysis.testFramework.JvmInspectionTestBase
import com.intellij.jvm.analysis.testFramework.JvmLanguage
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ContentEntry
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.pom.java.LanguageLevel
import com.intellij.testFramework.LightProjectDescriptor
class JavaParameterizedParametersStaticCollectionInspectionTest : JvmInspectionTestBase() {
override val inspection = ParameterizedParametersStaticCollectionInspection()
private class JUnitProjectDescriptor(languageLevel: LanguageLevel) : ProjectDescriptor(languageLevel) {
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
super.configureModule(module, model, contentEntry)
model.addJUnit4Library()
model.addJUnit5Library()
}
}
override fun getProjectDescriptor(): LightProjectDescriptor = JUnitProjectDescriptor(LanguageLevel.HIGHEST)
fun testCreateMethod() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class <warning descr="Parameterized test class 'CreateMethod' lacks data provider method annotated with '@Parameters'"><caret>CreateMethod</warning> { }
""".trimIndent())
}
fun testCreateMethodFix() {
myFixture.testQuickFix(JvmLanguage.JAVA, """
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class Create<caret>Method { }
""".trimIndent(), """
import org.junit.runners.Parameterized;
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class CreateMethod {
@Parameterized.Parameters
public static Iterable<Object[]> parameters() {
return null;
}
}
""".trimIndent(), JUnitBundle.message("fix.data.provider.create.method.fix.name"))
}
fun testWrongSignature() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class WrongSignature {
@org.junit.runners.Parameterized.Parameters
java.util.Collection <warning descr="Data provider method 'regExValues()' has an incorrect signature"><caret>regExValues</warning>() {
return null;
}
}
""".trimIndent())
}
fun testWrongSignatureFix() {
myFixture.testQuickFix(JvmLanguage.JAVA, """
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class WrongSignature {
@org.junit.runners.Parameterized.Parameters
java.util.Collection regEx<caret>Values() {
return null;
}
}
""".trimIndent(), """
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class WrongSignature {
@org.junit.runners.Parameterized.Parameters
public static java.util.Collection regExValues() {
return null;
}
}
""".trimIndent(), JUnitBundle.message("fix.data.provider.signature.fix.name", "public static Collection regExValues()"))
}
fun testWrongSignature1() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class WrongSignature1 {
@org.junit.runners.Parameterized.Parameters
static Integer <warning descr="Data provider method 'regExValues()' has an incorrect signature">regExValues</warning>() {
return null;
}
}
""".trimIndent())
}
fun testWrongSignature2() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class WrongSignature2 {
@org.junit.runners.Parameterized.Parameters
public static Integer <warning descr="Data provider method 'regExValues()' has an incorrect signature">regExValues</warning>() {
return null;
}
}
""".trimIndent())
}
fun testWrongSignature3() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class WrongSignature3 {
@org.junit.runners.Parameterized.Parameters
public static Integer[] <warning descr="Data provider method 'regExValues()' has an incorrect signature">regExValues</warning>() {
return null;
}
}
""".trimIndent())
}
fun testCorrectSignature() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class CorrectSignature {
@org.junit.runners.Parameterized.Parameters
public static Object[] parameters() {
return null;
}
}
""".trimIndent())
}
fun testCorrectSignature2() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class CorrectSignature2 {
@org.junit.runners.Parameterized.Parameters
public static Iterable<Object[]> parameters() {
return null;
}
}
""".trimIndent())
}
fun testMultipleMethods() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class <warning descr="Multiple @Parameters data provider methods present in class 'MultipleMethods'">MultipleMethods</warning> {
@org.junit.runners.Parameterized.Parameters
public static Object[] parameters() {
return null;
}
@org.junit.runners.Parameterized.Parameters
public static Object[] parameters2() {
return null;
}
}
""".trimIndent())
}
}
@@ -0,0 +1,35 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.junit.codeInspection
import com.intellij.junit.testFramework.addJUnit3Library
import com.intellij.jvm.analysis.testFramework.JvmInspectionTestBase
import com.intellij.jvm.analysis.testFramework.JvmLanguage
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ContentEntry
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.pom.java.LanguageLevel
import com.intellij.testFramework.LightProjectDescriptor
class JavaUseOfObsoleteAssertInspectionTest : JvmInspectionTestBase() {
override val inspection = UseOfObsoleteAssertInspection()
private class JUnitProjectDescriptor(languageLevel: LanguageLevel) : ProjectDescriptor(languageLevel) {
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
super.configureModule(module, model, contentEntry)
model.addJUnit3Library()
}
}
override fun getProjectDescriptor(): LightProjectDescriptor = JUnitProjectDescriptor(LanguageLevel.HIGHEST)
fun testObsoleteAssert() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
public class ObsoleteAssert {
public void testMe(int s) {
junit.framework.Assert.<warning descr="Call to 'assertEquals()' from 'junit.framework.Assert' should be replaced with call to method from 'org.junit.Assert'">assertEquals</warning>("asdfasd", -1, s);
junit.framework.TestCase.<warning descr="Call to 'assertEquals()' from 'junit.framework.TestCase' should be replaced with call to method from 'org.junit.Assert'">assertEquals</warning>("asdfasd", -1, s);
}
}
""".trimIndent())
}
}
@@ -0,0 +1,40 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.junit.codeInspection.naming
import com.intellij.junit.testFramework.addJUnit3Library
import com.intellij.jvm.analysis.testFramework.JvmInspectionTestBase
import com.intellij.jvm.analysis.testFramework.JvmLanguage
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ContentEntry
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.pom.java.LanguageLevel
import com.intellij.testFramework.LightProjectDescriptor
import com.siyeh.ig.naming.NewMethodNamingConventionInspection
class JavaJUnit3MethodNamingConventionInspectionTest : JvmInspectionTestBase() {
override val inspection by lazy {
NewMethodNamingConventionInspection().apply {
setEnabled(true, JUnit3MethodNamingConvention().shortName)
}
}
private class JUnitProjectDescriptor(languageLevel: LanguageLevel) : ProjectDescriptor(languageLevel) {
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
super.configureModule(module, model, contentEntry)
model.addJUnit3Library()
}
}
override fun getProjectDescriptor(): LightProjectDescriptor = JUnitProjectDescriptor(LanguageLevel.HIGHEST)
fun testJUnit3MethodNamingConvention() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
public class JUnit3MethodNamingConvention extends junit.framework.TestCase {
public void <warning descr="JUnit 3 test method name 'testA' is too short (5 < 8)">testA</warning>() {}
public void <warning descr="JUnit 3 test method name 'testAbcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' is too long (82 > 64)">testAbcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz</warning>() {}
public void <warning descr="JUnit 3 test method name 'testGiveMeMore${'$'}${'$'}${'$'}' doesn't match regex 'test[A-Za-z_\d]*'">testGiveMeMore${'$'}${'$'}${'$'}</warning>() {}
public void test_me_properly() {}
}
""".trimIndent())
}
}
@@ -0,0 +1,49 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.junit.codeInspection.naming
import com.intellij.junit.testFramework.addJUnit4Library
import com.intellij.jvm.analysis.testFramework.JvmInspectionTestBase
import com.intellij.jvm.analysis.testFramework.JvmLanguage
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ContentEntry
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.pom.java.LanguageLevel
import com.intellij.testFramework.LightProjectDescriptor
import com.siyeh.ig.naming.NewMethodNamingConventionInspection
class JavaJUnit4MethodNamingConventionInspectionTest : JvmInspectionTestBase() {
override val inspection by lazy {
NewMethodNamingConventionInspection().apply {
setEnabled(true, JUnit4MethodNamingConvention().shortName)
}
}
private class JUnitProjectDescriptor(languageLevel: LanguageLevel) : ProjectDescriptor(languageLevel) {
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
super.configureModule(module, model, contentEntry)
model.addJUnit4Library()
}
}
override fun getProjectDescriptor(): LightProjectDescriptor = JUnitProjectDescriptor(LanguageLevel.HIGHEST)
fun testJUnit4MethodNamingConvention() {
myFixture.testHighlighting(JvmLanguage.JAVA, """
import org.junit.Test;
public class JUnit4MethodNamingConvention {
@Test
public void <warning descr="JUnit 4+ test method name 'a' is too short (1 < 4)">a</warning>() {}
@Test
public void <warning descr="JUnit 4+ test method name 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' is too long (78 > 64)">abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz</warning>() {}
@Test
public void <warning descr="JUnit 4+ test method name 'more${'$'}${'$'}${'$'}' doesn't match regex '[a-z][A-Za-z_\d]*'">more${'$'}${'$'}${'$'}</warning>() {}
@Test
public void assure_foo_is_never_null() {}
}
""".trimIndent())
}
}
@@ -119,6 +119,33 @@
groupKey="junit.inspections.group.name" key="jvm.inspections.junit.malformed.declaration.name"
implementationClass="com.intellij.execution.junit.codeInspection.JUnitMalformedDeclarationInspection"/>
<inspectionElementsMerger implementation="com.intellij.execution.junit.codeInspection.JUnitMalformedDeclarationInspectionMerger"/>
<localInspection language="JAVA" enabledByDefault="false" level="WARNING" shortName="ParameterizedParametersStaticCollection"
groupBundle="messages.JUnitBundle" bundle="messages.JUnitBundle"
groupKey="junit.inspections.group.name" key="inspection.parameterized.parameters.static.collection.display.name"
implementationClass="com.intellij.execution.junit.codeInspection.ParameterizedParametersStaticCollectionInspection"/>
<localInspection language="JAVA" enabledByDefault="false" level="WARNING" shortName="ExpectedExceptionNeverThrown"
groupBundle="messages.JUnitBundle" bundle="messages.JUnitBundle"
groupKey="junit.inspections.group.name" key="expected.exception.never.thrown.display.name"
implementationClass="com.intellij.execution.junit.codeInspection.ExpectedExceptionNeverThrownInspection"/>
<localInspection language="JAVA" enabledByDefault="true" level="WARNING" shortName="JUnit3StyleTestMethodInJUnit4Class"
groupBundle="messages.JUnitBundle" bundle="messages.JUnitBundle"
groupKey="junit.inspections.group.name" key="junit3.style.test.method.in.junit4.class.display.name"
implementationClass="com.intellij.execution.junit.codeInspection.JUnit3StyleTestMethodInJUnit4ClassInspection"/>
<localInspection language="JAVA" enabledByDefault="false" cleanupTool="true" level="WARNING"
shortName="MultipleExceptionsDeclaredOnTestMethod"
groupBundle="messages.JUnitBundle" bundle="messages.JUnitBundle"
groupKey="junit.inspections.group.name" key="multiple.exceptions.declared.on.test.method.display.name"
implementationClass="com.intellij.execution.junit.codeInspection.MultipleExceptionsDeclaredOnTestMethodInspection" />
<localInspection language="JAVA" enabledByDefault="false" cleanupTool="true" shortName="UseOfObsoleteAssert"
groupBundle="messages.JUnitBundle" bundle="messages.JUnitBundle"
groupKey="junit.inspections.group.name" key="usage.of.obsolete.assert.display.name"
implementationClass="com.intellij.execution.junit.codeInspection.UseOfObsoleteAssertInspection" />
<naming.convention.class implementation="com.intellij.execution.junit.codeInspection.naming.AbstractTestClassNamingConvention" id="JUnitAbstractTestClassNamingConvention" order="first"/>
<naming.convention.class implementation="com.intellij.execution.junit.codeInspection.naming.TestSuiteNamingConvention" id="TestSuiteNamingConvention" order="after JUnitAbstractTestClassNamingConvention"/>
<naming.convention.class implementation="com.intellij.execution.junit.codeInspection.naming.TestClassNamingConvention" id="JUnitTestClassNamingConvention" order="after TestSuiteNamingConvention"/>
<naming.convention.method implementation="com.intellij.execution.junit.codeInspection.naming.JUnit3MethodNamingConvention" id="JUnit3MethodNamingConvention" order="first"/>
<naming.convention.method implementation="com.intellij.execution.junit.codeInspection.naming.JUnit4MethodNamingConvention" id="JUnit4MethodNamingConvention" order="after JUnit3MethodNamingConvention"/>
</extensions>
<extensionPoints>
@@ -206,4 +206,25 @@ jvm.inspections.junit.ignored.test.method.problem.descriptor=Test method ''{0}()
jvm.inspections.migrate.assertion.name=JUnit assertion can be 'assertThat()' call
jvm.inspections.migrate.assert.to.matcher.option=Statically import matcher's methods
jvm.inspections.migrate.assert.to.matcher.description=Assert expression <code>#ref</code> can be replaced with ''{0}'' call #loc
jvm.inspections.migrate.assert.to.matcher.description=Assert expression <code>#ref</code> can be replaced with ''{0}'' call #loc
inspection.parameterized.parameters.static.collection.display.name=Parameterized test class without data provider method
fix.data.provider.signature.fix.name=Change method signature to ''{0}''
fix.data.provider.create.method.fix.name=Create data provider method '@Parameters public static Iterable<Object> parameters()'
fix.data.provider.signature.family.name=Fix data provider method signature
fix.data.provider.signature.missing.method.problem=Parameterized test class <code>#ref</code> lacks data provider method annotated with '@Parameters'
fix.data.provider.signature.incorrect.problem=Data provider method <code>#ref()</code> has an incorrect signature
fix.data.provider.multiple.methods.problem=Multiple @Parameters data provider methods present in class <code>#ref</code>
expected.exception.never.thrown.display.name=Expected exception never thrown in test method body
expected.exception.never.thrown.problem.descriptor=Expected <code>#ref</code> never thrown in body of ''{0}()'' #loc
junit3.style.test.method.in.junit4.class.display.name=Old style JUnit test method in JUnit 4 class
junit3.style.test.method.in.junit4.class.problem.descriptor=Old style JUnit test method <code>#ref()</code> in JUnit 4 class #loc
multiple.exceptions.declared.on.test.method.display.name=Multiple exceptions declared on test method
multiple.exceptions.declared.on.test.method.problem.descriptor=<code>#ref</code> could be replaced with 'throws Exception' #loc
usage.of.obsolete.assert.display.name=Usage of obsolete 'junit.framework.Assert' method
use.of.obsolete.assert.problem.descriptor=Call to <code>#ref()</code> from ''{0}'' should be replaced with call to method from ''org.junit.Assert'' #loc
use.of.obsolete.assert.quickfix=Replace with 'org.junit.Assert' method call
@@ -1,12 +1,12 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.siyeh.ig.junit;
package com.intellij.execution.junit.codeInspection;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.ExceptionUtil;
import com.intellij.execution.JUnitBundle;
import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiUtil;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import org.jetbrains.annotations.NotNull;
@@ -19,7 +19,7 @@ public final class ExpectedExceptionNeverThrownInspection extends BaseInspection
@Override
protected String buildErrorString(Object... infos) {
final PsiMethod method = (PsiMethod)infos[0];
return InspectionGadgetsBundle.message("expected.exception.never.thrown.problem.descriptor", method.getName());
return JUnitBundle.message("expected.exception.never.thrown.problem.descriptor", method.getName());
}
@Override
@@ -1,13 +1,13 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.siyeh.ig.junit;
package com.intellij.execution.junit.codeInspection;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.TestFrameworks;
import com.intellij.codeInsight.intention.AddAnnotationPsiFix;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.execution.JUnitBundle;
import com.intellij.psi.*;
import com.intellij.testIntegration.TestFramework;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.psiutils.TestUtils;
@@ -23,7 +23,7 @@ public final class JUnit3StyleTestMethodInJUnit4ClassInspection extends BaseInsp
@NotNull
@Override
protected String buildErrorString(Object... infos) {
return InspectionGadgetsBundle.message("junit3.style.test.method.in.junit4.class.problem.descriptor");
return JUnitBundle.message("junit3.style.test.method.in.junit4.class.problem.descriptor");
}
@Nullable
@@ -1,9 +1,10 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.siyeh.ig.junit;
package com.intellij.execution.junit.codeInspection;
import com.intellij.codeInspection.CleanupLocalInspectionTool;
import com.intellij.codeInspection.CommonQuickFixBundle;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.execution.JUnitBundle;
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
import com.intellij.modcommand.ModPsiUpdater;
import com.intellij.openapi.project.Project;
@@ -11,7 +12,6 @@ import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.MethodReferencesSearch;
import com.intellij.util.Query;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.psiutils.TestUtils;
@@ -22,7 +22,7 @@ public final class MultipleExceptionsDeclaredOnTestMethodInspection extends Base
@NotNull
@Override
protected String buildErrorString(Object... infos) {
return InspectionGadgetsBundle.message(
return JUnitBundle.message(
"multiple.exceptions.declared.on.test.method.problem.descriptor");
}
@@ -1,10 +1,11 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.siyeh.ig.junit;
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.junit.codeInspection;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.daemon.impl.quickfix.CreateMethodQuickFix;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.execution.JUnitBundle;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
@@ -15,7 +16,6 @@ import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.refactoring.JavaRefactoringFactory;
import com.intellij.refactoring.changeSignature.ParameterInfoImpl;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
@@ -43,7 +43,7 @@ public final class ParameterizedParametersStaticCollectionInspection extends Bas
@Override
public @NotNull String getFamilyName() {
return InspectionGadgetsBundle.message("fix.data.provider.create.method.fix.name");
return JUnitBundle.message("fix.data.provider.create.method.fix.name");
}
@Override
@@ -82,13 +82,13 @@ public final class ParameterizedParametersStaticCollectionInspection extends Bas
@Override
@NotNull
public String getName() {
return InspectionGadgetsBundle.message("fix.data.provider.signature.fix.name", infos[0]);
return JUnitBundle.message("fix.data.provider.signature.fix.name", infos[0]);
}
@NotNull
@Override
public String getFamilyName() {
return InspectionGadgetsBundle.message("fix.data.provider.signature.family.name");
return JUnitBundle.message("fix.data.provider.signature.family.name");
}
};
}
@@ -97,11 +97,11 @@ public final class ParameterizedParametersStaticCollectionInspection extends Bas
@NotNull
protected String buildErrorString(Object... infos) {
if (infos.length == 0) {
return InspectionGadgetsBundle.message("fix.data.provider.multiple.methods.problem");
return JUnitBundle.message("fix.data.provider.multiple.methods.problem");
}
return infos.length > 1
? InspectionGadgetsBundle.message("fix.data.provider.signature.incorrect.problem")
: InspectionGadgetsBundle.message("fix.data.provider.signature.missing.method.problem");
? JUnitBundle.message("fix.data.provider.signature.incorrect.problem")
: JUnitBundle.message("fix.data.provider.signature.missing.method.problem");
}
@Override
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.siyeh.ig.junit;
package com.intellij.execution.junit.codeInspection;
import com.intellij.codeInspection.CleanupLocalInspectionTool;
import com.intellij.execution.JUnitBundle;
import com.intellij.modcommand.ModPsiUpdater;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
@@ -27,9 +28,9 @@ import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.junit.JUnitCommonClassNames;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -39,7 +40,7 @@ public final class UseOfObsoleteAssertInspection extends BaseInspection implemen
@NotNull
protected String buildErrorString(Object... infos) {
String name = (String)infos[0];
return InspectionGadgetsBundle.message("use.of.obsolete.assert.problem.descriptor", name);
return JUnitBundle.message("use.of.obsolete.assert.problem.descriptor", name);
}
@Override
@@ -234,7 +235,7 @@ public final class UseOfObsoleteAssertInspection extends BaseInspection implemen
@NotNull
@Override
public String getFamilyName() {
return InspectionGadgetsBundle.message("use.of.obsolete.assert.quickfix");
return JUnitBundle.message("use.of.obsolete.assert.quickfix");
}
}
}
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.siyeh.ig.junit;
package com.intellij.execution.junit.codeInspection.naming;
import com.intellij.codeInsight.TestFrameworks;
import com.intellij.codeInspection.naming.NamingConvention;
@@ -1,19 +1,5 @@
/*
* 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;
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.junit.codeInspection.naming;
import com.intellij.codeInspection.naming.NamingConvention;
import com.intellij.codeInspection.naming.NamingConventionBean;
@@ -1,5 +1,5 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.siyeh.ig.junit;
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.junit.codeInspection.naming;
import com.intellij.codeInspection.naming.NamingConvention;
import com.intellij.codeInspection.naming.NamingConventionBean;
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.siyeh.ig.junit;
package com.intellij.execution.junit.codeInspection.naming;
import com.intellij.codeInsight.TestFrameworks;
import com.intellij.codeInspection.naming.NamingConvention;
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.siyeh.ig.junit;
package com.intellij.execution.junit.codeInspection.naming;
import com.intellij.codeInsight.TestFrameworks;
import com.intellij.codeInspection.naming.NamingConvention;
@@ -9,24 +9,24 @@ import com.intellij.util.PathUtil
import junit.framework.TestCase
import java.io.File
internal fun ModifiableRootModel.addJUnit3Library() {
fun ModifiableRootModel.addJUnit3Library() {
val jar = File(PathUtil.getJarPathForClass(TestCase::class.java))
PsiTestUtil.addLibrary(this, "junit3", jar.parent, jar.name)
}
internal fun ModifiableRootModel.addJUnit4Library() {
fun ModifiableRootModel.addJUnit4Library() {
val jar = File(PathUtil.getJarPathForClass(org.junit.Test::class.java))
PsiTestUtil.addLibrary(this, "junit4", jar.parent, jar.name)
}
internal fun ModifiableRootModel.addHamcrestLibrary() {
fun ModifiableRootModel.addHamcrestLibrary() {
val jar = File(PathUtil.getJarPathForClass(org.hamcrest.MatcherAssert::class.java))
PsiTestUtil.addLibrary(this, "hamcrest-core", jar.parent, jar.name)
val libraryJar = File(IntelliJProjectConfiguration.getProjectLibraryClassesRootPaths("hamcrest").first())
PsiTestUtil.addLibrary(this, "hamcrest-library", libraryJar.parent, libraryJar.name)
}
internal fun ModifiableRootModel.addJUnit5Library(version: String = "5.9.1") {
fun ModifiableRootModel.addJUnit5Library(version: String = "5.9.1") {
MavenDependencyUtil.addFromMaven(this, "org.junit.jupiter:junit-jupiter-api:$version")
MavenDependencyUtil.addFromMaven(this, "org.junit.jupiter:junit-jupiter-params:$version")
}