[java] (IDEA-292972) fix of Malformed parameterized tests inspection with parameterized collections

GitOrigin-RevId: 331515798801d4ec644654b7531e4b919bbeebd9
This commit is contained in:
Olga Klisho
2022-04-30 00:23:35 +00:00
committed by intellij-monorepo-bot
parent 5e4a7f329a
commit 24f3296304
6 changed files with 51 additions and 4 deletions
@@ -17,6 +17,7 @@ import com.intellij.openapi.util.NlsSafe
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.*
import com.intellij.psi.codeStyle.JavaCodeStyleManager
import com.intellij.psi.impl.source.PsiClassReferenceType
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference
import com.intellij.psi.impl.source.tree.java.PsiNameValuePairImpl
import com.intellij.psi.search.searches.ClassInheritorsSearch
@@ -233,7 +234,10 @@ private class NullOrEmptySourceChecker(val holder: ProblemsHolder) {
val size = method.uastParameters.size
val shortName = psiAnnotation.qualifiedName ?: return
if (size == 1) {
val type = method.uastParameters[0].type
var type = method.uastParameters[0].type
if (type is PsiClassReferenceType) {
type = type.rawType()
}
if (type is PsiArrayType ||
type.equalsToText(CommonClassNames.JAVA_LANG_STRING) ||
type.equalsToText(CommonClassNames.JAVA_UTIL_LIST) ||
@@ -0,0 +1,20 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.params.provider.EmptySource;
import org.junit.jupiter.params.ParameterizedTest;
class MalformedParameterizedCollection {
@ParameterizedTest
@EmptySource
void testFooSet(Set<String> input) {}
@ParameterizedTest
@EmptySource
void testFooList(List<String> input) {}
@ParameterizedTest
@EmptySource
void testFooMap(Map<String, String> input) {}
}
@@ -30,6 +30,7 @@ public class JavaJUnit5MalformedParameterizedTest extends LightJavaInspectionTes
public void testMalformedSourcesImplicitConversion() { doTest(); }
public void testMalformedSourcesImplicitParameters() { doTest(); }
public void testMalformedSourcesTestInstancePerClass() { doTest(); }
public void testMalformedParameterizedCollection() { doTest(); }
@Override
protected String getBasePath() {
@@ -41,4 +42,4 @@ public class JavaJUnit5MalformedParameterizedTest extends LightJavaInspectionTes
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_8;
}
}
}
@@ -0,0 +1,16 @@
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.EmptySource
object MalformedParameterizedCollectionKt {
@ParameterizedTest
@EmptySource
fun testFooSet(input: Set<String?>?) {}
@ParameterizedTest
@EmptySource
fun testFooList(input: List<String?>?) {}
@ParameterizedTest
@EmptySource
fun testFooMap(input: Map<String?, String?>?) {}
}
@@ -54,6 +54,10 @@ class KotlinJUnit5MalformedParameterizedTest : JavaCodeInsightFixtureTestCase()
myFixture.testHighlighting("CantResolveTarget.kt")
}
fun `test MalformedParameterizedCollectionKt`() {
myFixture.testHighlighting("MalformedParameterizedCollectionKt.kt")
}
fun `test CantResolveTarget highlighting`() {
myFixture.testHighlighting("CantResolveTarget.kt")
}
@@ -93,4 +97,4 @@ class KotlinJUnit5MalformedParameterizedTest : JavaCodeInsightFixtureTestCase()
fun `test EnumResolve quickFixes`() {
myFixture.testHighlighting("EnumResolve.kt")
}
}
}
@@ -7,6 +7,8 @@ public class JUnit5TestFrameworkSetupUtil {
public static JavaCodeInsightTestFixture setupJUnit5Library(JavaCodeInsightTestFixture fixture) {
fixture.addClass( "package org.junit.jupiter.params.provider;\n" +
"public @interface MethodSource {String[] value() default \"\";}");
fixture.addClass( "package org.junit.jupiter.params.provider;\n" +
"public @interface EmptySource {}");
fixture.addClass( "package org.junit.jupiter.params;\n" +
"@org.junit.platform.commons.annotation.Testable\n" +
"public @interface ParameterizedTest {String name() default \"\";}");
@@ -83,4 +85,4 @@ public class JUnit5TestFrameworkSetupUtil {
fixture.addClass("package org.junit.jupiter.api; public @interface Nested{}");
return fixture;
}
}
}