mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
junit 5: malformed parameterized: check argumentsSources (IDEA-193925)
This commit is contained in:
+3
-1
@@ -37,12 +37,14 @@ public class JUnitCommonClassNames {
|
||||
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 = Collections.unmodifiableList(Arrays.asList(
|
||||
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,
|
||||
ORG_JUNIT_JUPITER_PARAMS_PROVIDER_CSV_FILE_SOURCE,
|
||||
ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ARGUMENTS_SOURCE
|
||||
ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ARGUMENTS_SOURCE,
|
||||
ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ARGUMENTS_SOURCES
|
||||
));
|
||||
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";
|
||||
|
||||
+7
-1
@@ -87,6 +87,12 @@ class JUnit5MalformedParameterizedInspection : AbstractBaseJavaLocalInspectionTo
|
||||
noMultiArgsProvider = false
|
||||
}
|
||||
}
|
||||
JUnitCommonClassNames.ORG_JUNIT_JUPITER_PARAMS_PROVIDER_ARGUMENTS_SOURCES -> {
|
||||
if (source == null) {
|
||||
val attributes = it.findAttributeValue(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME)
|
||||
noMultiArgsProvider = (attributes as? PsiArrayInitializerMemberValue)?.initializers?.isEmpty() ?: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +329,7 @@ class ChangeAnnotationFix(testAnnotation: PsiAnnotation, val targetAnnotation: S
|
||||
override fun getFamilyName(): String = "Replace annotation"
|
||||
|
||||
override fun invoke(project: Project, file: PsiFile, editor: Editor?, startElement: PsiElement, endElement: PsiElement) {
|
||||
val annotation = JavaPsiFacade.getElementFactory(project).createAnnotationFromText("@" + targetAnnotation, startElement)
|
||||
val annotation = JavaPsiFacade.getElementFactory(project).createAnnotationFromText("@$targetAnnotation", startElement)
|
||||
JavaCodeStyleManager.getInstance(project).shortenClassReferences(startElement.replace(annotation))
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -67,6 +67,11 @@ public class JUnit5MalformedParameterizedTest extends LightInspectionTestCase {
|
||||
addEnvironmentClass("package org.junit.jupiter.params.provider;\n" +
|
||||
"public @interface ArgumentsSource {}");
|
||||
|
||||
addEnvironmentClass("package org.junit.jupiter.params.provider;\n" +
|
||||
"public @interface ArgumentsSources {\n" +
|
||||
" ArgumentsSource[] value();\n" +
|
||||
"}\n");
|
||||
|
||||
addEnvironmentClass("package org.junit.jupiter.api;\n" +
|
||||
"public @interface TestInstance {\n" +
|
||||
"enum Lifecycle {PER_CLASS, PER_METHOD;}\n" +
|
||||
|
||||
@@ -84,4 +84,14 @@ class CustomArgProviderTest {
|
||||
@ParameterizedTest
|
||||
@CustomSource
|
||||
void jsonSourceTest(String param) { }
|
||||
}
|
||||
|
||||
class ArgSources {
|
||||
@ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ArgumentsSources({@org.junit.jupiter.params.provider.ArgumentsSource})
|
||||
void args(String param) { }
|
||||
|
||||
<warning descr="No sources are provided, the suite would be empty">@ParameterizedTest</warning>
|
||||
@org.junit.jupiter.params.provider.ArgumentsSources({})
|
||||
void emptyArgs(String param) { }
|
||||
}
|
||||
Reference in New Issue
Block a user