[jvm] IDEA-294238 Simplify JUnitMalformedDeclaration after merge

GitOrigin-RevId: 62f7db1d9e7b777d9142a588d3f651af7cbd58b6
This commit is contained in:
Bart van Helvert
2022-06-06 11:20:33 +02:00
committed by intellij-monorepo-bot
parent 13b35e5ecf
commit ee1cd17dae
11 changed files with 507 additions and 638 deletions

View File

@@ -43,7 +43,7 @@
groupBundle="messages.JvmAnalysisBundle" bundle="messages.JvmAnalysisBundle"
groupPathKey="jvm.inspections.group.name" groupKey="jvm.inspections.test.frameworks.group.name"
key="jvm.inspections.junit.malformed.declaration.name"
implementationClass="com.intellij.codeInspection.test.junit.JUnitMalformedMemberInspection"/>
implementationClass="com.intellij.codeInspection.test.junit.JUnitMalformedDeclarationInspection"/>
<inspectionElementsMerger implementation="com.intellij.codeInspection.test.junit.JUnitMalformedMemberInspectionMerger"/>
<localInspection language="UAST" enabledByDefault="true" level="WARNING" shortName="UnstableApiUsage"

View File

@@ -17,7 +17,7 @@ The following problems are reported by this inspection:
not public, not static, whose return type is not void or do not have a valid parameter list.
</li>
<li>
Methods annotated by <code>@Before</code>, <code>@After</code>, <code>@BeforeEach</code> or <code>AfterEach</code> that are
Methods annotated by <code>@Before</code>, <code>@After</code>, <code>@BeforeEach</code> or <code>@AfterEach</code> that are
not public, whose return type is not void or take arguments.
</li>
<li>Injected <code>RepetitionInfo</code> in <code>@BeforeAll</code> or <code>@AfterAll</code> methods.</li>

View File

@@ -101,49 +101,36 @@ jvm.inspections.unconstructable.test.case.not.public.descriptor=Test class <code
jvm.inspections.unconstructable.test.case.junit3.descriptor=Test class <code>#ref</code> is not constructable because it does not have a 'public' no-arg or single 'String' parameter constructor #loc
jvm.inspections.unconstructable.test.case.junit4.descriptor=Test class <code>#ref</code> is not constructable because it should have exactly one 'public' no-arg constructor #loc
jvm.inspections.junit.datapoint.problem.single.descriptor={0}s annotated with ''{1}'' should be {2}
jvm.inspections.junit.datapoint.problem.double.descriptor={0}s annotated with ''{1}'' should be {2} and {3}
jvm.inspections.junit.datapoint.fix.familyName=Fix member signature
jvm.inspections.junit.datapoint.fix.single.name=Make {0} ''{1}'' {2}
jvm.inspections.junit.datapoint.fix.double.name=Make {0} ''{1}'' {2} and {3}
jvm.inspections.junit.rule.signature.problem.single.descriptor={0}s annotated with ''@{1}'' should be {2}
jvm.inspections.junit.rule.signature.problem.double.descriptor={0}s annotated with ''@{1}'' should be {2} and {3}
jvm.inspections.junit.rule.type.problem.descriptor={0} type should be subtype of ''{1}'' or ''{2}''
jvm.inspections.junit.class.rule.type.problem.descriptor={0} type should be subtype of ''{1}''
jvm.inspections.junit5.malformed.nested.class.inspection.description=Only non-static nested classes can serve as '@Nested' test classes.
jvm.inspections.junit5.malformed.extension.registration.message={0} should implement {1}
jvm.inspections.junit5.malformed.extension.class.level.message={0} should be registered at the class level, otherwise beforeAll/afterAll methods won''t be executed
jvm.inspections.junit5.malformed.repetition.description.injected.for.test=RepetitionInfo won't be injected for @Test methods
jvm.inspections.junit5.malformed.repetition.description.injected.for.each=RepetitionInfo is injected for @BeforeEach/@AfterEach only, but not for {0}
jvm.inspections.junit5.malformed.repetition.description.injected.for.repeatedtest=RepetitionInfo is injected for @RepeatedTest only
jvm.inspections.junit5.malformed.repetition.description.positive.number=The number of repetitions must be greater than zero
jvm.inspections.junit5.malformed.repetition.description.suspicious.combination=Suspicious combination @Test and @RepeatedTest
jvm.inspections.junit5.malformed.parameterized.inspection.description.method.source.unresolved=Cannot resolve target method source: ''{0}''
jvm.inspections.junit5.malformed.parameterized.inspection.description.wrapped.in.arguments=Multiple parameters have to be wrapped in 'Arguments'
jvm.inspections.junit5.malformed.parameterized.inspection.description.method.source.return.type=Method source ''{0}'' must have one of the following return types: ''Stream<?>'', ''Iterator<?>'', ''Iterable<?>'' or ''Object[]''
jvm.inspections.junit5.malformed.parameterized.inspection.description.method.source.no.params=Method source ''{0}'' should have no parameters
jvm.inspections.junit5.malformed.parameterized.inspection.description.method.source.static=Method source ''{0}'' must be static
jvm.inspections.junit5.malformed.parameterized.inspection.description.method.source.assignable=No implicit conversion found to convert ''{0}'' to ''{1}''
jvm.inspections.junit5.malformed.parameterized.inspection.description.duplicated.enum=Duplicate 'enum' constant name
jvm.inspections.junit5.malformed.parameterized.inspection.description.unresolved.enum=Can't resolve 'enum' constant reference.
jvm.inspections.junit5.malformed.parameterized.inspection.description.no.value.source.is.defined=No value source is defined
jvm.inspections.junit5.malformed.parameterized.inspection.description.exactly.one.type.of.input.must.be.provided=Exactly one type of input must be provided
jvm.inspections.junit5.malformed.parameterized.inspection.description.file.source=Cannot resolve file source: ''{0}''
jvm.inspections.junit5.malformed.parameterized.inspection.description.nullsource.cannot.provide.argument.no.params=''@{0}'' cannot provide an argument to method because method doesn''t have parameters
jvm.inspections.junit5.malformed.parameterized.inspection.description.nullsource.cannot.provide.argument.too.many.params=''@{0}'' cannot provide an argument to method because method provides too many parameters
jvm.inspections.junit5.malformed.parameterized.inspection.description.emptysource.cannot.provide.argument=''@{0}'' cannot provide an argument to method because method has an unsupported parameter of ''{1}'' type
jvm.inspections.junit5.malformed.parameterized.fix.text=Change to ''{0}''
jvm.inspections.junit5.malformed.parameterized.inspection.description.suspicious.combination.test.and.parameterizedtest=Suspicious combination '@Test' and '@ParameterizedTest'
jvm.inspections.junit5.malformed.parameterized.inspection.description.suspicious.combination=Suspicious combination '@Test' and parameterized source
jvm.inspections.junit5.malformed.parameterized.inspection.description.multiple.parameters.are.not.supported.by.this.source=Multiple parameters are not supported by this source
jvm.inspections.junit5.malformed.parameterized.inspection.description.no.sources.are.provided=No sources are provided, the suite would be empty
jvm.inspections.junit5.malformed.parameterized.fix.family.name=Replace annotation
jvm.inspections.before.after.descriptor=<code>#ref()</code> has incorrect signature for a ''@{0}'' method #loc
jvm.inspections.malformed.set.up.tear.down.problem.descriptor='#ref()' has incorrect signature #loc
jvm.inspections.junit.malformed.declaration.name=JUnit malformed declaration
jvm.inspections.test.method.is.public.void.no.arg.problem.no.param=Test method <code>#ref()</code> should probably not have parameters #loc
jvm.inspections.test.method.is.public.void.no.arg.problem.public.void=Test method <code>#ref()</code> is not declared 'public void' #loc
jvm.inspections.test.method.is.public.void.no.arg.problem.static=Test method <code>#ref()</code> should not be 'static' #loc
jvm.inspections.junit.malformed.option.ignore.test.parameter.if.annotated.by=Ignore test parameter if it is annotated by:
jvm.inspections.junit.malformed.method.signature.descriptor=Method <code>#ref</code> is malformed
jvm.inspections.junit.malformed.annotated.field.signature.descriptor=Field <code>#ref</code> annotated with ''@{0}'' is malformed
jvm.inspections.junit.malformed.annotated.method.signature.descriptor=Method <code>#ref</code> annotated with ''@{0}'' is malformed
jvm.inspections.junit.malformed.test.combination.descriptor=Suspicious combination of {0} and ''@{1}''
jvm.inspections.junit.malformed.repetition.number.descriptor=The number of repetitions must be greater than zero
jvm.inspections.junit.malformed.nested.class.descriptor=Only non-static nested classes can serve as '@Nested' test classes.
jvm.inspections.junit.malformed.extension.registration.descriptor=''{0}'' should implement ''{1}''
jvm.inspections.junit.malformed.extension.class.level.descriptor={0} should be registered at the class level
jvm.inspections.junit.malformed.param.method.source.unresolved.descriptor=Cannot resolve target method source: ''{0}''
jvm.inspections.junit.malformed.param.wrapped.in.arguments.descriptor=Multiple parameters have to be wrapped in 'Arguments'
jvm.inspections.junit.malformed.param.method.source.return.type.descriptor=Method source ''{0}'' must have one of the following return types: ''Stream<?>'', ''Iterator<?>'', ''Iterable<?>'' or ''Object[]''
jvm.inspections.junit.malformed.param.method.source.no.params.descriptor=Method source ''{0}'' should have no parameters
jvm.inspections.junit.malformed.param.method.source.static.descriptor=Method source ''{0}'' must be static
jvm.inspections.junit.malformed.param.method.source.assignable.descriptor=No implicit conversion found to convert ''{0}'' to ''{1}''
jvm.inspections.junit.malformed.param.duplicated.enum.descriptor=Duplicate 'enum' constant name
jvm.inspections.junit.malformed.param.unresolved.enum.descriptor=Can't resolve 'enum' constant reference.
jvm.inspections.junit.malformed.param.no.value.source.is.defined.descriptor=No value source is defined
jvm.inspections.junit.malformed.param.exactly.one.type.of.input.must.be.provided.descriptor=Exactly one type of input must be provided
jvm.inspections.junit.malformed.param.file.source.descriptor=Cannot resolve file source: ''{0}''
jvm.inspections.junit.malformed.param.null.source.cannot.provide.argument.no.params.descriptor=''@{0}'' cannot provide an argument to method because method doesn''t have parameters
jvm.inspections.junit.malformed.param.null.source.cannot.provide.argument.too.many.params.descriptor=''@{0}'' cannot provide an argument to method because method provides too many parameters
jvm.inspections.junit.malformed.param.empty.source.cannot.provide.argument.descriptor=''@{0}'' cannot provide an argument to method because method has an unsupported parameter of ''{1}'' type
jvm.inspections.junit.malformed.param.multiple.parameters.are.not.supported.by.this.source.descriptor=Multiple parameters are not supported by this source
jvm.inspections.junit.malformed.param.no.sources.are.provided.descriptor=No sources are provided, the suite would be empty
jvm.inspections.junit.fix.method.signature=Fix method signature
jvm.inspections.junit.fix.method.signature.descriptor=Fix ''{0}'' method signature
jvm.inspections.junit.fix.field.signature=Fix field signature
jvm.inspections.junit.fix.field.signature.descriptor=Fix ''{0}'' field signature
jvm.inspection.test.failed.line.display.name=Failed line in test
@@ -165,9 +152,6 @@ jvm.inspections.assertequals.between.inconvertible.types.problem.descriptor=<cod
jvm.inspections.assertnotsame.between.inconvertible.types.problem.descriptor=Redundant assertion: incompatible types are compared ''{0}'' and ''{1}''
jvm.inspections.assertnotequals.between.inconvertible.types.problem.descriptor=Possibly redundant assertion: incompatible types are compared ''{0}'' and ''{1}''
jvm.fix.make.no.arg.void.name=Fix method signature
jvm.fix.make.no.arg.void.descriptor=Fix ''{0}'' method signature
can.t.build.uast.tree.for.file=Can't build UAST tree for file
title.uast=UAST
current.version=Current version

View File

@@ -31,7 +31,7 @@ final class JUnitReferenceContributor extends PsiReferenceContributor {
}
private static PsiElementPattern.Capture<PsiLanguageInjectionHost> getEnumSourceNamesPattern() {
return getElementPattern(JUnitCommonClassNames.ORG_JUNIT_JUPITER_PARAMS_ENUM_SOURCE, "names")
return getElementPattern(JUnitCommonClassNames.ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ENUM_SOURCE, "names")
.withAncestor(4, PlatformPatterns.psiElement(PsiAnnotation.class).and(new PsiJavaElementPattern<>(
new InitialPatternCondition<>(PsiAnnotation.class) {
@Override

View File

@@ -1,9 +1,9 @@
package com.intellij.codeInspection.tests.java.test.junit
import com.intellij.codeInspection.tests.ULanguage
import com.intellij.codeInspection.tests.test.junit.JUnitMalformedMemberTestBase
import com.intellij.codeInspection.tests.test.junit.JUnitMalformedDeclarationTestBase
class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
class JavaJUnitMalformedDeclarationTest : JUnitMalformedDeclarationTestBase() {
/* Malformed extensions */
fun `test malformed extension no highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
@@ -18,7 +18,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.JAVA, """
class A {
@org.junit.jupiter.api.extension.RegisterExtension
Rule5 <warning descr="A.Rule5 should implement org.junit.jupiter.api.extension.Extension">myRule5</warning> = new Rule5();
Rule5 <warning descr="'A.Rule5' should implement 'org.junit.jupiter.api.extension.Extension'">myRule5</warning> = new Rule5();
class Rule5 { }
}
""".trimIndent())
@@ -259,9 +259,9 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
fun `test malformed parameterized value source multiple parameters highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
class ValueSourcesTest {
@org.junit.jupiter.params.<warning descr="Multiple parameters are not supported by this source">ParameterizedTest</warning>
@org.junit.jupiter.params.ParameterizedTest
@org.junit.jupiter.params.provider.ValueSource(strings = "foo")
void testWithMultipleParams(String argument, int i) { }
void <warning descr="Multiple parameters are not supported by this source">testWithMultipleParams</warning>(String argument, int i) { }
}
""".trimIndent())
}
@@ -270,8 +270,8 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
class ValueSourcesTest {
@org.junit.jupiter.params.ParameterizedTest
@org.junit.jupiter.params.provider.ValueSource(ints = {1})
@org.junit.jupiter.api.<warning descr="Suspicious combination '@Test' and '@ParameterizedTest'">Test</warning>
void testWithTestAnnotation(int i) { }
@org.junit.jupiter.api.Test
void <warning descr="Suspicious combination of '@Test' and '@ParameterizedTest'">testWithTestAnnotation</warning>(int i) { }
}
""".trimIndent())
}
@@ -279,17 +279,17 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.JAVA, """
class ValueSourcesTest {
@org.junit.jupiter.params.provider.ValueSource(ints = {1})
@org.junit.jupiter.api.<warning descr="Suspicious combination '@Test' and parameterized source">Test</warning>
void testWithTestAnnotationNoParameterized(int i) { }
@org.junit.jupiter.api.Test
void <warning descr="Suspicious combination of '@ValueSource' and '@Test'">testWithTestAnnotationNoParameterized</warning>(int i) { }
}
""".trimIndent())
}
fun `test malformed parameterized no argument source provided highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
class ValueSourcesTest {
@org.junit.jupiter.params.<warning descr="No sources are provided, the suite would be empty">ParameterizedTest</warning>
@org.junit.jupiter.params.ParameterizedTest
@org.junit.jupiter.params.provider.ArgumentsSources({})
void emptyArgs(String param) { }
void <warning descr="No sources are provided, the suite would be empty">emptyArgs</warning>(String param) { }
}
""".trimIndent())
}
@@ -478,9 +478,9 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
fun `test malformed repeated test combination of @Test and @RepeatedTest highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
class WithRepeatedAndTests {
<warning descr="Suspicious combination @Test and @RepeatedTest">@org.junit.jupiter.api.Test</warning>
@org.junit.jupiter.api.Test
@org.junit.jupiter.api.RepeatedTest(1)
void repeatedTestAndTest() { }
void <warning descr="Suspicious combination of '@Test' and '@RepeatedTest'">repeatedTestAndTest</warning>() { }
}
""".trimIndent())
}
@@ -488,10 +488,10 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.JAVA, """
class WithRepeatedInfoAndTest {
@org.junit.jupiter.api.BeforeEach
void beforeEach(org.junit.jupiter.api.RepetitionInfo <warning descr="RepetitionInfo won't be injected for @Test methods">repetitionInfo</warning>) { }
void beforeEach(org.junit.jupiter.api.RepetitionInfo repetitionInfo) { }
@org.junit.jupiter.api.Test
void nonRepeated(org.junit.jupiter.api.RepetitionInfo <warning descr="RepetitionInfo is injected for @RepeatedTest only">repetitionInfo</warning>) { }
void <warning descr="Method 'nonRepeated' annotated with '@Test' is malformed">nonRepeated</warning>(org.junit.jupiter.api.RepetitionInfo repetitionInfo) { }
}
""".trimIndent())
}
@@ -499,18 +499,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.JAVA, """
class WithBeforeEach {
@org.junit.jupiter.api.BeforeAll
void <warning descr="'beforeAllWithRepetitionInfo()' has incorrect signature for a '@org.junit.jupiter.api.BeforeAll' method">beforeAllWithRepetitionInfo</warning>(org.junit.jupiter.api.RepetitionInfo <warning descr="RepetitionInfo is injected for @BeforeEach/@AfterEach only, but not for BeforeAll">repetitionInfo</warning>) { }
}
""".trimIndent())
}
fun `test malformed repeated test with injected RepetitionInfo for @ParameterizedTest method highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
class WithParameterized {
@org.junit.jupiter.params.ParameterizedTest
@org.junit.jupiter.params.provider.MethodSource(value = "a")
void testAccidentalRepetitionInfo(Object s, org.junit.jupiter.api.RepetitionInfo <warning descr="RepetitionInfo is injected for @RepeatedTest only">repetitionInfo</warning>) { }
static Object[] a() { return new Object[] { org.junit.jupiter.params.provider.Arguments.of(1, "one") }; }
void <warning descr="Method 'beforeAllWithRepetitionInfo' annotated with '@BeforeAll' is malformed">beforeAllWithRepetitionInfo</warning>(org.junit.jupiter.api.RepetitionInfo repetitionInfo) { }
}
""".trimIndent())
}
@@ -531,7 +520,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.JAVA, """
class MainTest {
@org.junit.Before
String <warning descr="'before()' has incorrect signature for a '@org.junit.Before' method">before</warning>(int i) { return ""; }
String <warning descr="Method 'before' annotated with '@Before' is malformed">before</warning>(int i) { return ""; }
}
""".trimIndent())
}
@@ -539,7 +528,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.JAVA, """
class MainTest {
@org.junit.jupiter.api.BeforeEach
String <warning descr="'beforeEach()' has incorrect signature for a '@org.junit.jupiter.api.BeforeEach' method">beforeEach</warning>(int i) { return ""; }
String <warning descr="Method 'beforeEach' annotated with '@BeforeEach' is malformed">beforeEach</warning>(int i) { return ""; }
}
""".trimIndent())
}
@@ -608,11 +597,11 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.JAVA, """
class MainTest {
@org.junit.jupiter.api.BeforeAll
String <warning descr="'beforeAll()' has incorrect signature for a '@org.junit.jupiter.api.BeforeAll' method">beforeAll</warning>(int i) { return ""; }
String <warning descr="Method 'beforeAll' annotated with '@BeforeAll' is malformed">beforeAll</warning>(int i) { return ""; }
}
""".trimIndent())
}
fun `test malformed before class quickfix`() {
fun `test malformed before all quickfix`() {
myFixture.testQuickFix(ULanguage.JAVA, """
class MainTest {
@org.junit.jupiter.api.BeforeAll
@@ -621,7 +610,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
""".trimIndent(), """
class MainTest {
@org.junit.jupiter.api.BeforeAll
public static void beforeAll() { return ""; }
static void beforeAll() { return ""; }
}
""".trimIndent(), "Fix 'beforeAll' method signature")
}
@@ -637,35 +626,35 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
fun `test malformed dataPoint non-static highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
class Test {
@org.junit.experimental.theories.DataPoint public Object <warning descr="Fields annotated with 'org.junit.experimental.theories.DataPoint' should be static">f1</warning>;
@org.junit.experimental.theories.DataPoint public Object <warning descr="Field 'f1' annotated with '@DataPoint' is malformed">f1</warning>;
}
""".trimIndent())
}
fun `test malformed dataPoint non-public highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
class Test {
@org.junit.experimental.theories.DataPoint static Object <warning descr="Fields annotated with 'org.junit.experimental.theories.DataPoint' should be public">f1</warning>;
@org.junit.experimental.theories.DataPoint static Object <warning descr="Field 'f1' annotated with '@DataPoint' is malformed">f1</warning>;
}
""".trimIndent())
}
fun `test malformed dataPoint field highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
class Test {
@org.junit.experimental.theories.DataPoint Object <warning descr="Fields annotated with 'org.junit.experimental.theories.DataPoint' should be public and static">f1</warning>;
@org.junit.experimental.theories.DataPoint Object <warning descr="Field 'f1' annotated with '@DataPoint' is malformed">f1</warning>;
}
""".trimIndent())
}
fun `test malformed datapoint method highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
class Test {
@org.junit.experimental.theories.DataPoint Object <warning descr="Methods annotated with 'org.junit.experimental.theories.DataPoint' should be public and static">f1</warning>() { return null; }
@org.junit.experimental.theories.DataPoint Object <warning descr="Method 'f1' annotated with '@DataPoint' is malformed">f1</warning>() { return null; }
}
""".trimIndent())
}
fun `test malformed datapoints method highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
class Test {
@org.junit.experimental.theories.DataPoints Object <warning descr="Methods annotated with 'org.junit.experimental.theories.DataPoints' should be public and static">f1</warning>() { return null; }
@org.junit.experimental.theories.DataPoints Object <warning descr="Method 'f1' annotated with '@DataPoints' is malformed">f1</warning>() { return null; }
}
""".trimIndent())
}
@@ -679,7 +668,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
@org.junit.experimental.theories.DataPoint
public static Object f1() { return null; }
}
""".trimIndent(), "Make method 'f1' public and static")
""".trimIndent(), "Fix 'f1' method signature")
}
/* Malformed setup/teardown */
@@ -694,7 +683,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
fun `test malformed setup highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
class C extends junit.framework.TestCase {
private void <warning descr="'setUp()' has incorrect signature">setUp</warning>(int i) { }
private void <warning descr="Method 'setUp' is malformed">setUp</warning>(int i) { }
}
""".trimIndent())
}
@@ -724,10 +713,10 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
class RuleTest {
@org.junit.Rule
private SomeTestRule <warning descr="Fields annotated with '@org.junit.Rule' should be 'public'">x</warning>;
private SomeTestRule <warning descr="Field 'x' annotated with '@Rule' is malformed">x</warning>;
@org.junit.Rule
public static SomeTestRule <warning descr="Fields annotated with '@org.junit.Rule' should be non-static">y</warning>;
public static SomeTestRule <warning descr="Field 'y' annotated with '@Rule' is malformed">y</warning>;
}
""".trimIndent())
}
@@ -735,7 +724,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.JAVA, """
class RuleTest {
@org.junit.Rule
public int <warning descr="Field type should be subtype of 'org.junit.rules.TestRule' or 'org.junit.rules.MethodRule'">x</warning>;
public int <warning descr="Field 'x' annotated with '@Rule' is malformed">x</warning>;
}
""".trimIndent())
}
@@ -752,7 +741,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
class RuleTest {
@org.junit.Rule
public static SomeTestRule <warning descr="Methods annotated with '@org.junit.Rule' should be non-static">y</warning>() {
public static SomeTestRule <warning descr="Method 'y' annotated with '@Rule' is malformed">y</warning>() {
return new SomeTestRule();
};
}
@@ -771,16 +760,16 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
class ClassRuleTest {
@org.junit.ClassRule
static SomeTestRule <warning descr="Fields annotated with '@org.junit.ClassRule' should be 'public'">x</warning> = new SomeTestRule();
static SomeTestRule <warning descr="Field 'x' annotated with '@ClassRule' is malformed">x</warning> = new SomeTestRule();
@org.junit.ClassRule
public SomeTestRule <warning descr="Fields annotated with '@org.junit.ClassRule' should be 'static'">y</warning> = new SomeTestRule();
public SomeTestRule <warning descr="Field 'y' annotated with '@ClassRule' is malformed">y</warning> = new SomeTestRule();
@org.junit.ClassRule
private SomeTestRule <warning descr="Fields annotated with '@org.junit.ClassRule' should be 'public' and 'static'">z</warning> = new SomeTestRule();
private SomeTestRule <warning descr="Field 'z' annotated with '@ClassRule' is malformed">z</warning> = new SomeTestRule();
@org.junit.ClassRule
public static int <warning descr="Field type should be subtype of 'org.junit.rules.TestRule'">t</warning> = 0;
public static int <warning descr="Field 't' annotated with '@ClassRule' is malformed">t</warning> = 0;
}
""".trimIndent())
}
@@ -795,7 +784,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
@org.junit.Rule
public int x;
}
""".trimIndent(), "Make 'x' public")
""".trimIndent(), "Fix 'x' field signature")
}
fun `test malformed rule make field non-static quickfix`() {
myFixture.testQuickFix(ULanguage.JAVA, """
@@ -808,7 +797,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
@org.junit.Rule
public int y() { return 0; }
}
""".trimIndent(), "Make 'y' not static")
""".trimIndent(), "Fix 'y' method signature")
}
fun `test malformed class rule make field public quickfix`() {
myFixture.testQuickFix(ULanguage.JAVA, """
@@ -839,7 +828,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
@org.junit.ClassRule
public static SomeTestRule x = new SomeTestRule();
}
""".trimIndent(), "Make 'x' public")
""".trimIndent(), "Fix 'x' field signature")
}
fun `test malformed class rule make field static quickfix`() {
myFixture.testQuickFix(ULanguage.JAVA, """
@@ -870,7 +859,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
@org.junit.ClassRule
public static SomeTestRule y = new SomeTestRule();
}
""".trimIndent(), "Make 'y' static")
""".trimIndent(), "Fix 'y' field signature")
}
fun `test malformed class rule make field public and static quickfix`() {
myFixture.testQuickFix(ULanguage.JAVA, """
@@ -901,17 +890,17 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
@org.junit.ClassRule
public static SomeTestRule z = new SomeTestRule();
}
""".trimIndent(), "Make 'z' public", "Make 'z' static")
""".trimIndent(), "Fix 'z' field signature")
}
/* Malformed test */
fun `test malformed test for JUnit 3 highlighting`() {
myFixture.testHighlighting(ULanguage.JAVA, """
class JUnit3TestMethodIsPublicVoidNoArg extends junit.framework.TestCase {
void <warning descr="Test method 'testOne()' is not declared 'public void'">testOne</warning>() { }
public int <warning descr="Test method 'testTwo()' is not declared 'public void'">testTwo</warning>() { return 2; }
public static void <warning descr="Test method 'testThree()' should not be 'static'">testThree</warning>() { }
public void <warning descr="Test method 'testFour()' should probably not have parameters">testFour</warning>(int i) { }
void <warning descr="Method 'testOne' is malformed">testOne</warning>() { }
public int <warning descr="Method 'testTwo' is malformed">testTwo</warning>() { return 2; }
public static void <warning descr="Method 'testThree' is malformed">testThree</warning>() { }
public void <warning descr="Method 'testFour' is malformed">testFour</warning>(int i) { }
public void testFive() { }
void testSix(int i) { } //ignore when method doesn't look like test anymore
}
@@ -924,10 +913,10 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
""".trimIndent())
myFixture.testHighlighting(ULanguage.JAVA, """
class JUnit4TestMethodIsPublicVoidNoArg {
@org.junit.Test void <warning descr="Test method 'testOne()' is not declared 'public void'">testOne</warning>() {}
@org.junit.Test public int <warning descr="Test method 'testTwo()' is not declared 'public void'">testTwo</warning>() { return 2; }
@org.junit.Test public static void <warning descr="Test method 'testThree()' should not be 'static'">testThree</warning>() {}
@org.junit.Test public void <warning descr="Test method 'testFour()' should probably not have parameters">testFour</warning>(int i) {}
@org.junit.Test void <warning descr="Method 'testOne' annotated with '@Test' is malformed">testOne</warning>() {}
@org.junit.Test public int <warning descr="Method 'testTwo' annotated with '@Test' is malformed">testTwo</warning>() { return 2; }
@org.junit.Test public static void <warning descr="Method 'testThree' annotated with '@Test' is malformed">testThree</warning>() {}
@org.junit.Test public void <warning descr="Method 'testFour' annotated with '@Test' is malformed">testFour</warning>(int i) {}
@org.junit.Test public void testFive() {}
@org.junit.Test public void testMock(@mockit.Mocked String s) {}
}
@@ -937,7 +926,7 @@ class JavaJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.JAVA, """
@org.junit.runner.RunWith(org.junit.runner.Runner.class)
class JUnit4RunWith {
@org.junit.Test public int testMe(int i) { return -1; }
@org.junit.Test public int <warning descr="Method 'testMe' annotated with '@Test' is malformed">testMe</warning>(int i) { return -1; }
}
""".trimIndent())
}

View File

@@ -1,7 +1,7 @@
package com.intellij.codeInspection.tests.kotlin.test.junit
import com.intellij.codeInspection.tests.ULanguage
import com.intellij.codeInspection.tests.test.junit.JUnitMalformedMemberTestBase
import com.intellij.codeInspection.tests.test.junit.JUnitMalformedDeclarationTestBase
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ContentEntry
import com.intellij.openapi.roots.ModifiableRootModel
@@ -10,7 +10,7 @@ import com.intellij.testFramework.PsiTestUtil
import com.intellij.util.PathUtil
import java.io.File
class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
class KotlinJUnitMalformedDeclarationTest : JUnitMalformedDeclarationTestBase() {
override fun getProjectDescriptor(): LightProjectDescriptor = object : JUnitProjectDescriptor(sdkLevel) {
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
super.configureModule(module, model, contentEntry)
@@ -20,7 +20,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
}
/* Malformed extensions */
fun `test Malformed extension no highlighting`() {
fun `test malformed extension no highlighting`() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class A {
@org.junit.jupiter.api.extension.RegisterExtension
@@ -29,18 +29,18 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
}
""".trimIndent())
}
fun `test Malformed extension highlighting`() {
fun `test malformed extension highlighting`() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class A {
@org.junit.jupiter.api.extension.RegisterExtension
val <warning descr="A.Rule5 should implement org.junit.jupiter.api.extension.Extension">myRule5</warning> = Rule5()
val <warning descr="'A.Rule5' should implement 'org.junit.jupiter.api.extension.Extension'">myRule5</warning> = Rule5()
class Rule5 { }
}
""".trimIndent())
}
/* Malformed nested class */
fun `test Malformed nested no highlighting`() {
fun `test malformed nested no highlighting`() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class A {
@org.junit.jupiter.api.Nested
@@ -48,7 +48,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
}
""".trimIndent())
}
fun `test Malformed nested class highlighting`() {
fun `test malformed nested class highlighting`() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class A {
@org.junit.jupiter.api.Nested
@@ -284,9 +284,9 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
fun `test malformed parameterized value source multiple parameters`() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class ValueSourcesTest {
@org.junit.jupiter.params.<warning descr="Multiple parameters are not supported by this source">ParameterizedTest</warning>
@org.junit.jupiter.params.ParameterizedTest
@org.junit.jupiter.params.provider.ValueSource(strings = ["foo"])
fun testWithMultipleParams(argument: String, i: Int) { }
fun <warning descr="Multiple parameters are not supported by this source">testWithMultipleParams</warning>(argument: String, i: Int) { }
}
""".trimIndent())
}
@@ -295,8 +295,8 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
class ValueSourcesTest {
@org.junit.jupiter.params.ParameterizedTest
@org.junit.jupiter.params.provider.ValueSource(ints = [1])
@org.junit.jupiter.api.<warning descr="Suspicious combination '@Test' and '@ParameterizedTest'">Test</warning>
fun testWithTestAnnotation(i: Int) { }
@org.junit.jupiter.api.Test
fun <warning descr="Suspicious combination of '@Test' and '@ParameterizedTest'">testWithTestAnnotation</warning>(i: Int) { }
}
""".trimIndent())
}
@@ -304,17 +304,17 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class ValueSourcesTest {
@org.junit.jupiter.params.provider.ValueSource(ints = [1])
@org.junit.jupiter.api.<warning descr="Suspicious combination '@Test' and parameterized source">Test</warning>
fun testWithTestAnnotationNoParameterized(i: Int) { }
@org.junit.jupiter.api.Test
fun <warning descr="Suspicious combination of '@ValueSource' and '@Test'">testWithTestAnnotationNoParameterized</warning>(i: Int) { }
}
""".trimIndent())
}
fun `test malformed parameterized no argument source provided`() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class ValueSourcesTest {
@org.junit.jupiter.params.<warning descr="No sources are provided, the suite would be empty">ParameterizedTest</warning>
@org.junit.jupiter.params.ParameterizedTest
@org.junit.jupiter.params.provider.ArgumentsSources()
fun emptyArgs(param: String) { }
fun <warning descr="No sources are provided, the suite would be empty">emptyArgs</warning>(param: String) { }
}
""".trimIndent())
}
@@ -514,9 +514,9 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
fun `test malformed repeated test combination of @Test and @RepeatedTest`() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class WithRepeatedAndTests {
<warning descr="Suspicious combination @Test and @RepeatedTest">@org.junit.jupiter.api.Test</warning>
@org.junit.jupiter.api.Test
@org.junit.jupiter.api.RepeatedTest(1)
fun repeatedTestAndTest() { }
fun <warning descr="Suspicious combination of '@Test' and '@RepeatedTest'">repeatedTestAndTest</warning>() { }
}
""".trimIndent())
}
@@ -524,10 +524,10 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class WithRepeatedInfoAndTest {
@org.junit.jupiter.api.BeforeEach
fun beforeEach(<warning descr="RepetitionInfo won't be injected for @Test methods">repetitionInfo</warning>: org.junit.jupiter.api.RepetitionInfo) { }
fun beforeEach(repetitionInfo: org.junit.jupiter.api.RepetitionInfo) { }
@org.junit.jupiter.api.Test
fun nonRepeated(<warning descr="RepetitionInfo is injected for @RepeatedTest only">repetitionInfo</warning>: org.junit.jupiter.api.RepetitionInfo) { }
fun <warning descr="Method 'nonRepeated' annotated with '@Test' is malformed">nonRepeated</warning>(repetitionInfo: org.junit.jupiter.api.RepetitionInfo) { }
}
""".trimIndent() )
}
@@ -537,21 +537,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
companion object {
@JvmStatic
@org.junit.jupiter.api.BeforeAll
fun <warning descr="'beforeAllWithRepetitionInfo()' has incorrect signature for a '@org.junit.jupiter.api.BeforeAll' method">beforeAllWithRepetitionInfo</warning>(<warning descr="RepetitionInfo is injected for @BeforeEach/@AfterEach only, but not for BeforeAll">repetitionInfo</warning>: org.junit.jupiter.api.RepetitionInfo) { }
}
}
""".trimIndent())
}
fun `test malformed repeated test with injected RepetitionInfo for @ParameterizedTest method`() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class WithParameterized {
@org.junit.jupiter.params.ParameterizedTest
@org.junit.jupiter.params.provider.MethodSource("a")
fun testAccidentalRepetitionInfo(s: Any, <warning descr="RepetitionInfo is injected for @RepeatedTest only">repetitionInfo</warning>: org.junit.jupiter.api.RepetitionInfo) { }
companion object {
@JvmStatic
fun a(): Array<Any> = arrayOf("1", "2")
fun <warning descr="Method 'beforeAllWithRepetitionInfo' annotated with '@BeforeAll' is malformed">beforeAllWithRepetitionInfo</warning>(repetitionInfo: org.junit.jupiter.api.RepetitionInfo) { }
}
}
""".trimIndent())
@@ -573,7 +559,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class MainTest {
@org.junit.Before
fun <warning descr="'before()' has incorrect signature for a '@org.junit.Before' method">before</warning>(i: Int): String { return "${'$'}i" }
fun <warning descr="Method 'before' annotated with '@Before' is malformed">before</warning>(i: Int): String { return "${'$'}i" }
}
""".trimIndent())
}
@@ -581,7 +567,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class MainTest {
@org.junit.jupiter.api.BeforeEach
fun <warning descr="'beforeEach()' has incorrect signature for a '@org.junit.jupiter.api.BeforeEach' method">beforeEach</warning>(i: Int): String { return "" }
fun <warning descr="Method 'beforeEach' annotated with '@BeforeEach' is malformed">beforeEach</warning>(i: Int): String { return "" }
}
""".trimIndent())
}
@@ -671,7 +657,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class MainTest {
@org.junit.BeforeClass
fun <warning descr="'beforeClass()' has incorrect signature for a '@org.junit.BeforeClass' method">beforeClass</warning>() { }
fun <warning descr="Method 'beforeClass' annotated with '@BeforeClass' is malformed">beforeClass</warning>() { }
}
""".trimIndent())
}
@@ -681,7 +667,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
companion object {
@JvmStatic
@org.junit.BeforeClass
private fun <warning descr="'beforeClass()' has incorrect signature for a '@org.junit.BeforeClass' method">beforeClass</warning>() { }
private fun <warning descr="Method 'beforeClass' annotated with '@BeforeClass' is malformed">beforeClass</warning>() { }
}
}
""".trimIndent())
@@ -692,7 +678,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
companion object {
@JvmStatic
@org.junit.BeforeClass
fun <warning descr="'beforeClass()' has incorrect signature for a '@org.junit.BeforeClass' method">beforeClass</warning>(i: Int) { System.out.println(i) }
fun <warning descr="Method 'beforeClass' annotated with '@BeforeClass' is malformed">beforeClass</warning>(i: Int) { System.out.println(i) }
}
}
""".trimIndent())
@@ -703,7 +689,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
companion object {
@JvmStatic
@org.junit.BeforeClass
fun <warning descr="'beforeClass()' has incorrect signature for a '@org.junit.BeforeClass' method">beforeClass</warning>(): String { return "" }
fun <warning descr="Method 'beforeClass' annotated with '@BeforeClass' is malformed">beforeClass</warning>(): String { return "" }
}
}
""".trimIndent())
@@ -712,7 +698,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class MainTest {
@org.junit.jupiter.api.BeforeAll
fun <warning descr="'beforeAll()' has incorrect signature for a '@org.junit.jupiter.api.BeforeAll' method">beforeAll</warning>() { }
fun <warning descr="Method 'beforeAll' annotated with '@BeforeAll' is malformed">beforeAll</warning>() { }
}
""".trimIndent())
}
@@ -722,7 +708,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
companion object {
@JvmStatic
@org.junit.jupiter.api.BeforeAll
private fun <warning descr="'beforeAll()' has incorrect signature for a '@org.junit.jupiter.api.BeforeAll' method">beforeAll</warning>() { }
private fun <warning descr="Method 'beforeAll' annotated with '@BeforeAll' is malformed">beforeAll</warning>() { }
}
}
""".trimIndent())
@@ -733,7 +719,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
companion object {
@JvmStatic
@org.junit.jupiter.api.BeforeAll
fun <warning descr="'beforeAll()' has incorrect signature for a '@org.junit.jupiter.api.BeforeAll' method">beforeAll</warning>(i: Int) { System.out.println(i) }
fun <warning descr="Method 'beforeAll' annotated with '@BeforeAll' is malformed">beforeAll</warning>(i: Int) { System.out.println(i) }
}
}
""".trimIndent())
@@ -744,7 +730,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
companion object {
@JvmStatic
@org.junit.jupiter.api.BeforeAll
fun <warning descr="'beforeAll()' has incorrect signature for a '@org.junit.jupiter.api.BeforeAll' method">beforeAll</warning>(): String { return "" }
fun <warning descr="Method 'beforeAll' annotated with '@BeforeAll' is malformed">beforeAll</warning>(): String { return "" }
}
}
""".trimIndent())
@@ -789,7 +775,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
class Test {
@JvmField
@org.junit.experimental.theories.DataPoint
val <warning descr="Fields annotated with 'org.junit.experimental.theories.DataPoint' should be static">f1</warning>: Any? = null
val <warning descr="Field 'f1' annotated with '@DataPoint' is malformed">f1</warning>: Any? = null
}
""".trimIndent())
}
@@ -799,7 +785,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
companion object {
@JvmStatic
@org.junit.experimental.theories.DataPoint
private val <warning descr="Fields annotated with 'org.junit.experimental.theories.DataPoint' should be public">f1</warning>: Any? = null
private val <warning descr="Field 'f1' annotated with '@DataPoint' is malformed">f1</warning>: Any? = null
}
}
""".trimIndent())
@@ -808,7 +794,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class Test {
@org.junit.experimental.theories.DataPoint
private val <warning descr="Fields annotated with 'org.junit.experimental.theories.DataPoint' should be public and static">f1</warning>: Any? = null
private val <warning descr="Field 'f1' annotated with '@DataPoint' is malformed">f1</warning>: Any? = null
}
""".trimIndent())
}
@@ -816,7 +802,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class Test {
@org.junit.experimental.theories.DataPoint
private fun <warning descr="Methods annotated with 'org.junit.experimental.theories.DataPoint' should be public and static">f1</warning>(): Any? = null
private fun <warning descr="Method 'f1' annotated with '@DataPoint' is malformed">f1</warning>(): Any? = null
}
""".trimIndent())
}
@@ -824,7 +810,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class Test {
@org.junit.experimental.theories.DataPoints
private fun <warning descr="Methods annotated with 'org.junit.experimental.theories.DataPoints' should be public and static">f1</warning>(): Any? = null
private fun <warning descr="Method 'f1' annotated with '@DataPoints' is malformed">f1</warning>(): Any? = null
}
""".trimIndent())
}
@@ -844,13 +830,13 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
val f1: Any? = null
}
}
""".trimIndent(), "Make field 'f1' public")
""".trimIndent(), "Fix 'f1' field signature")
}
fun `test malformed datapoint make field public and static quickfix`() {
myFixture.testQuickFix(ULanguage.KOTLIN, """
class Test {
@org.junit.experimental.theories.DataPoint
val f<caret>1: Any? = null
@org.junit.experimental.theories.DataPoint
val f<caret>1: Any? = null
}
""".trimIndent(), """
class Test {
@@ -860,13 +846,13 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
val f1: Any? = null
}
}
""".trimIndent(), "Make field 'f1' public and static")
""".trimIndent(), "Fix 'f1' field signature")
}
fun `test malformed datapoint make method public and static quickfix`() {
myFixture.testQuickFix(ULanguage.KOTLIN, """
class Test {
@org.junit.experimental.theories.DataPoint
private fun f<caret>1(): Any? = null
@org.junit.experimental.theories.DataPoint
private fun f<caret>1(): Any? = null
}
""".trimIndent(), """
class Test {
@@ -876,7 +862,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
fun f1(): Any? = null
}
}
""".trimIndent(), "Make method 'f1' public and static")
""".trimIndent(), "Fix 'f1' method signature")
}
/* Malformed setup/teardown */
@@ -890,7 +876,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
fun `test malformed setup highlighting`() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class C : junit.framework.TestCase() {
private fun <warning descr="'setUp()' has incorrect signature">setUp</warning>(i: Int) { System.out.println(i) }
private fun <warning descr="Method 'setUp' is malformed">setUp</warning>(i: Int) { System.out.println(i) }
}
""".trimIndent())
}
@@ -915,7 +901,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
class PrivateRule {
@org.junit.Rule
var <warning descr="Fields annotated with '@org.junit.Rule' should be 'public'">x</warning> = SomeTestRule()
var <warning descr="Field 'x' annotated with '@Rule' is malformed">x</warning> = SomeTestRule()
}
""".trimIndent())
}
@@ -931,7 +917,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
object ObjRule {
@org.junit.Rule
private var <warning descr="Fields annotated with '@org.junit.Rule' should be 'public' and non-static">x</warning> = SomeTestRule()
private var <warning descr="Field 'x' annotated with '@Rule' is malformed">x</warning> = SomeTestRule()
}
class ClazzRule {
@@ -939,7 +925,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
fun x() = OtherRule
@org.junit.Rule
fun <warning descr="Method return type should be subtype of 'org.junit.rules.TestRule' or 'org.junit.rules.MethodRule'">y</warning>() = 0
fun <warning descr="Method 'y' annotated with '@Rule' is malformed">y</warning>() = 0
@org.junit.Rule
public fun z() = object : org.junit.rules.TestRule {
@@ -947,7 +933,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
}
@org.junit.Rule
public fun <warning descr="Method return type should be subtype of 'org.junit.rules.TestRule' or 'org.junit.rules.MethodRule'">a</warning>() = object { }
public fun <warning descr="Method 'a' annotated with '@Rule' is malformed">a</warning>() = object { }
}
""".trimIndent())
}
@@ -959,7 +945,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
class PrivateRule {
@org.junit.Rule
private fun <warning descr="Methods annotated with '@org.junit.Rule' should be 'public'">x</warning>() = SomeTestRule()
private fun <warning descr="Method 'x' annotated with '@Rule' is malformed">x</warning>() = SomeTestRule()
}
""".trimIndent())
}
@@ -967,7 +953,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class PrivateRule {
@org.junit.Rule
fun <warning descr="Method return type should be subtype of 'org.junit.rules.TestRule' or 'org.junit.rules.MethodRule'">x</warning>() = 0
fun <warning descr="Method 'x' annotated with '@Rule' is malformed">x</warning>() = 0
}
""".trimIndent())
}
@@ -979,10 +965,10 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
object PrivateClassRule {
@org.junit.ClassRule
private var <warning descr="Fields annotated with '@org.junit.ClassRule' should be 'public'">x</warning> = SomeTestRule()
private var <warning descr="Field 'x' annotated with '@ClassRule' is malformed">x</warning> = SomeTestRule()
@org.junit.ClassRule
private var <warning descr="Field type should be subtype of 'org.junit.rules.TestRule'"><warning descr="Fields annotated with '@org.junit.ClassRule' should be 'public'">y</warning></warning> = 0
private var <warning descr="Field 'y' annotated with '@ClassRule' is malformed">y</warning> = 0
}
""".trimIndent())
}
@@ -998,29 +984,29 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
@org.junit.Rule
var x = 0
}
""".trimIndent(), "Make field 'x' public")
""".trimIndent(), "Fix 'x' field signature")
}
fun `test malformed class rule make field public quickfix`() {
myFixture.testQuickFix(ULanguage.KOTLIN, """
class SomeTestRule : org.junit.rules.TestRule {
override fun apply(base: org.junit.runners.model.Statement, description: org.junit.runner.Description): org.junit.runners.model.Statement = base
override fun apply(base: org.junit.runners.model.Statement, description: org.junit.runner.Description): org.junit.runners.model.Statement = base
}
object PrivateClassRule {
@org.junit.ClassRule
private var x<caret> = SomeTestRule()
@org.junit.ClassRule
private var x<caret> = SomeTestRule()
}
""".trimIndent(), """
class SomeTestRule : org.junit.rules.TestRule {
override fun apply(base: org.junit.runners.model.Statement, description: org.junit.runner.Description): org.junit.runners.model.Statement = base
override fun apply(base: org.junit.runners.model.Statement, description: org.junit.runner.Description): org.junit.runners.model.Statement = base
}
object PrivateClassRule {
@kotlin.jvm.JvmField
@org.junit.ClassRule
var x = SomeTestRule()
@kotlin.jvm.JvmField
@org.junit.ClassRule
var x = SomeTestRule()
}
""".trimIndent(), "Make field 'x' public")
""".trimIndent(), "Fix 'x' field signature")
}
/* Malformed test */
@@ -1028,13 +1014,13 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
public class JUnit3TestMethodIsPublicVoidNoArg : junit.framework.TestCase() {
fun testOne() { }
public fun <warning descr="Test method 'testTwo()' is not declared 'public void'">testTwo</warning>(): Int { return 2 }
public fun <warning descr="Test method 'testFour()' should probably not have parameters">testFour</warning>(i: Int) { println(i) }
public fun <warning descr="Method 'testTwo' is malformed">testTwo</warning>(): Int { return 2 }
public fun <warning descr="Method 'testFour' is malformed">testFour</warning>(i: Int) { println(i) }
public fun testFive() { }
private fun testSix(i: Int) { println(i) } //ignore when method doesn't look like test anymore
companion object {
@JvmStatic
public fun <warning descr="Test method 'testThree()' should not be 'static'">testThree</warning>() { }
public fun <warning descr="Method 'testThree' is malformed">testThree</warning>() { }
}
}
""".trimIndent())
@@ -1047,13 +1033,13 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
public class JUnit4TestMethodIsPublicVoidNoArg {
@org.junit.Test fun testOne() { }
@org.junit.Test public fun <warning descr="Test method 'testTwo()' is not declared 'public void'">testTwo</warning>(): Int { return 2 }
@org.junit.Test public fun <warning descr="Test method 'testFour()' should probably not have parameters">testFour</warning>(i: Int) { }
@org.junit.Test public fun <warning descr="Method 'testTwo' annotated with '@Test' is malformed">testTwo</warning>(): Int { return 2 }
@org.junit.Test public fun <warning descr="Method 'testFour' annotated with '@Test' is malformed">testFour</warning>(i: Int) { }
@org.junit.Test public fun testFive() { }
@org.junit.Test public fun testMock(@mockit.Mocked s: String) { }
companion object {
@JvmStatic
@org.junit.Test public fun <warning descr="Test method 'testThree()' should not be 'static'">testThree</warning>() { }
@org.junit.Test public fun <warning descr="Method 'testThree' annotated with '@Test' is malformed">testThree</warning>() { }
}
}
""".trimIndent())
@@ -1062,7 +1048,7 @@ class KotlinJUnitMalformedMemberTest : JUnitMalformedMemberTestBase() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
@org.junit.runner.RunWith(org.junit.runner.Runner::class)
class JUnit4RunWith {
@org.junit.Test public fun testMe(i: Int): Int { return -1 }
@org.junit.Test public fun <warning descr="Method 'testMe' annotated with '@Test' is malformed">testMe</warning>(i: Int): Int { return -1 }
}
""".trimIndent())
}

View File

@@ -1,6 +1,6 @@
package com.intellij.codeInspection.tests.test.junit
import com.intellij.codeInspection.test.junit.JUnitMalformedMemberInspection
import com.intellij.codeInspection.test.junit.JUnitMalformedDeclarationInspection
import com.intellij.codeInspection.tests.UastInspectionTestBase
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ContentEntry
@@ -8,8 +8,8 @@ import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.pom.java.LanguageLevel
import com.intellij.testFramework.LightProjectDescriptor
abstract class JUnitMalformedMemberTestBase : UastInspectionTestBase() {
override val inspection = JUnitMalformedMemberInspection()
abstract class JUnitMalformedDeclarationTestBase : UastInspectionTestBase() {
override val inspection = JUnitMalformedDeclarationInspection()
protected open class JUnitProjectDescriptor(languageLevel: LanguageLevel) : ProjectDescriptor(languageLevel) {
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {

View File

@@ -1756,7 +1756,6 @@ ignore.getters.returning.resource=Ignore getters that returns resource
log.method.name=Logging Method Name
log.condition.text=Log Condition Text
ignore.if.annotated.by=Ignore if annotated by:
ignore.parameter.if.annotated.by=Ignore parameter if it is annotated by:
ignore.classes.annotated.by=Ignore classes annotated by:
ignored.class.hierarchies.border.title=Ignore subclasses of:
choose.class.hierarchy.to.ignore.title=Choose Class Hierarchy to Ignore

View File

@@ -29,25 +29,25 @@ public final class JUnitCommonClassNames {
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_METHOD_SOURCE = "org.junit.jupiter.params.provider.MethodSource";
public static final String ORG_JUNIT_JUPITER_CONDITION_PROVIDER_ENABLED_IF = "org.junit.jupiter.api.condition.EnabledIf";
public static final String ORG_JUNIT_JUPITER_CONDITION_PROVIDER_DISABLED_IF = "org.junit.jupiter.api.condition.DisabledIf";
public static final String ORG_JUNIT_JUPITER_PARAMS_VALUES_SOURCE = "org.junit.jupiter.params.provider.ValueSource";
public static final String ORG_JUNIT_JUPITER_PARAMS_ENUM_SOURCE = "org.junit.jupiter.params.provider.EnumSource";
public static final String ORG_JUNIT_JUPITER_PARAMS_ENUM_SOURCE_SHORT = "EnumSource";
public static final String ORG_JUNIT_JUPITER_PARAMS_NULL_SOURCE = "org.junit.jupiter.params.provider.NullSource";
public static final String ORG_JUNIT_JUPITER_PARAMS_EMPTY_SOURCE = "org.junit.jupiter.params.provider.EmptySource";
public static final String ORG_JUNIT_JUPITER_PARAMS_NULL_AND_EMPTY_SOURCE = "org.junit.jupiter.params.provider.NullAndEmptySource";
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_NULL_SOURCE = "org.junit.jupiter.params.provider.NullSource";
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_EMPTY_SOURCE = "org.junit.jupiter.params.provider.EmptySource";
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_VALUE_SOURCE = "org.junit.jupiter.params.provider.ValueSource";
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ENUM_SOURCE = "org.junit.jupiter.params.provider.EnumSource";
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_NULL_AND_EMPTY_SOURCE = "org.junit.jupiter.params.provider.NullAndEmptySource";
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_NULL_ENUM = "org.junit.jupiter.params.provider.NullEnum";
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_CSV_SOURCE = "org.junit.jupiter.params.provider.CsvSource";
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_CSV_FILE_SOURCE = "org.junit.jupiter.params.provider.CsvFileSource";
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ARGUMENTS_SOURCE = "org.junit.jupiter.params.provider.ArgumentsSource";
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ARGUMENTS_SOURCES = "org.junit.jupiter.params.provider.ArgumentsSources";
public static final Collection<String> SOURCE_ANNOTATIONS = ContainerUtil
.immutableList(ORG_JUNIT_JUPITER_PARAMS_PROVIDER_METHOD_SOURCE, ORG_JUNIT_JUPITER_PARAMS_VALUES_SOURCE,
ORG_JUNIT_JUPITER_PARAMS_ENUM_SOURCE, ORG_JUNIT_JUPITER_PARAMS_PROVIDER_CSV_SOURCE,
.immutableList(ORG_JUNIT_JUPITER_PARAMS_PROVIDER_METHOD_SOURCE, ORG_JUNIT_JUPITER_PARAMS_PROVIDER_VALUE_SOURCE,
ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ENUM_SOURCE, ORG_JUNIT_JUPITER_PARAMS_PROVIDER_CSV_SOURCE,
ORG_JUNIT_JUPITER_PARAMS_PROVIDER_CSV_FILE_SOURCE, ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ARGUMENTS_SOURCE,
ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ARGUMENTS_SOURCES,
ORG_JUNIT_JUPITER_PARAMS_NULL_SOURCE,
ORG_JUNIT_JUPITER_PARAMS_EMPTY_SOURCE,
ORG_JUNIT_JUPITER_PARAMS_NULL_AND_EMPTY_SOURCE);
ORG_JUNIT_JUPITER_PARAMS_PROVIDER_NULL_SOURCE,
ORG_JUNIT_JUPITER_PARAMS_PROVIDER_EMPTY_SOURCE,
ORG_JUNIT_JUPITER_PARAMS_PROVIDER_NULL_AND_EMPTY_SOURCE);
public static final String ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ARGUMENTS = "org.junit.jupiter.params.provider.Arguments";
public static final String ORG_JUNIT_JUPITER_PARAMS_CONVERTER_CONVERT_WITH = "org.junit.jupiter.params.converter.ConvertWith";
public static final String ORG_JUNIT_JUPITER_API_TEST = "org.junit.jupiter.api.Test";

View File

@@ -120,7 +120,7 @@ public class JUnitImplicitUsageProvider implements ImplicitUsageProvider {
PsiAnnotation annotation = PsiTreeUtil.getParentOfType(referenceElement, PsiAnnotation.class, true, PsiStatement.class, PsiMember.class);
if (annotation != null) {
String annotationName = annotation.getQualifiedName();
if (JUnitCommonClassNames.ORG_JUNIT_JUPITER_PARAMS_ENUM_SOURCE.equals(annotationName) && annotation.getAttributes().size() == 1) {
if (JUnitCommonClassNames.ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ENUM_SOURCE.equals(annotationName) && annotation.getAttributes().size() == 1) {
return true;
}
}