diff --git a/plugins/junit/test/com/intellij/execution/junit/codeInsight/JUnit5MalformedParameterizedTest.java b/plugins/junit/test/com/intellij/execution/junit/codeInsight/JUnit5MalformedParameterizedTest.java index 765b6c689671..6afedd31cc9d 100644 --- a/plugins/junit/test/com/intellij/execution/junit/codeInsight/JUnit5MalformedParameterizedTest.java +++ b/plugins/junit/test/com/intellij/execution/junit/codeInsight/JUnit5MalformedParameterizedTest.java @@ -49,11 +49,13 @@ public class JUnit5MalformedParameterizedTest extends LightInspectionTestCase { "double[] doubles() default {};\n" + "}\n"); addEnvironmentClass("package org.junit.jupiter.params.provider;\n" + - "public interface Arguments {}\n"); + "public @interface CsvSource {String[] value();}"); + addEnvironmentClass("package org.junit.jupiter.params.provider;\n" + + "public interface Arguments {static Arguments of(Object... arguments){}}\n"); } public void testMalformedSources() { doTest(); } - public void testMalformedSourcesArguments() { doTest(); } + public void testMethodSource() { doTest(); } public void testMalformedSourcesImplicitConversion() { doTest(); } public void testMalformedSourcesImplicitParameters() { doTest(); } diff --git a/plugins/junit/testData/codeInsight/malformedParameterized/MalformedSources.java b/plugins/junit/testData/codeInsight/malformedParameterized/MalformedSources.java index 070e97137f09..d65d42b04386 100644 --- a/plugins/junit/testData/codeInsight/malformedParameterized/MalformedSources.java +++ b/plugins/junit/testData/codeInsight/malformedParameterized/MalformedSources.java @@ -2,53 +2,22 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.*; -class ParameterizedTestsDemo { - - @ParameterizedTest - void testWithParamsNoSource(int i) { } - - @ParameterizedTest - @MethodSource(value = {"a", - "b", - "c", - "d"}) - void testWithParams(Object s) { } - - String[] a() { - return new String[] {"a", "b"}; - } - - static String[] b(int i) { - return new String[] {"a", "b"}; - } - - static Object c() { - return new String[] {"a", "b"}; - } - - static Object[] d() { - return new String[] {"a", "b"}; - } - - @ParameterizedTest - @MethodSource(value = {"d"}) - void testWithMultipleParams(Object s, int i) { } - - @ParameterizedTest - @EnumSource(E.class) - void testWithEnumSource(int i) { } - - @ParameterizedTest - @EnumSource(E.class) - void testWithEnumSourceCorrect(E e) { } - - enum E { - A, B; - } - +class ValueSourcesTest { @ParameterizedTest @ValueSource(ints = {1}) - void testWithValues(int i) { } + void testWithIntValues(int i) { } + + @ParameterizedTest + @ValueSource(longs = {1L}) + void testWithLongValues(long l) { } + + @ParameterizedTest + @ValueSource(doubles = {0.5}) + void testWithDoubleValues(double d) { } + + @ParameterizedTest + @ValueSource(strings = {""}) + void testWithStringValues(String s) { } @ParameterizedTest @ValueSource(ints = {1}, @@ -73,3 +42,25 @@ class ParameterizedTestsDemo { void testWithTestAnnotationNoParameterized(int i) { } } + +class ParameterizedTestsDemo { + + @ParameterizedTest + void testWithParamsNoSource(int i) { } + + @ParameterizedTest + @EnumSource(E.class) + void testWithEnumSource(int i) { } + + @ParameterizedTest + @EnumSource(E.class) + void testWithEnumSourceCorrect(E e) { } + + enum E { + A, B; + } + + @ParameterizedTest + @CsvSource({"foo, 1"}) + void testWithCsvSource(String first, int second) {} +} diff --git a/plugins/junit/testData/codeInsight/malformedParameterized/MalformedSourcesArguments.java b/plugins/junit/testData/codeInsight/malformedParameterized/MalformedSourcesArguments.java deleted file mode 100644 index ea00ddf0f284..000000000000 --- a/plugins/junit/testData/codeInsight/malformedParameterized/MalformedSourcesArguments.java +++ /dev/null @@ -1,22 +0,0 @@ - -import java.util.Iterator; -import java.util.stream.Stream; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -class MethodSourceProblem { - @ParameterizedTest - @MethodSource(value = {"stream", "iterator"}) - void test(int x, int y) { - System.out.println(x + ", "+ y); - } - - static Stream stream() { - return null; - } - - static Iterator iterator() { - return null; - } -} \ No newline at end of file diff --git a/plugins/junit/testData/codeInsight/malformedParameterized/MethodSource.java b/plugins/junit/testData/codeInsight/malformedParameterized/MethodSource.java new file mode 100644 index 000000000000..31ecc2c1db4d --- /dev/null +++ b/plugins/junit/testData/codeInsight/malformedParameterized/MethodSource.java @@ -0,0 +1,139 @@ +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.*; + +import java.util.Iterator; +import java.util.stream.Stream; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; +import java.util.stream.LongStream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class MethodSourcePositive { + @ParameterizedTest + @MethodSource("stream") + void simpleStream(int x, int y) { + System.out.println(x + ", " + y); + } + + @ParameterizedTest + @MethodSource("iterable") + void simpleIterable(int x, int y) { + System.out.println(x + ", " + y); + } + + @ParameterizedTest + @MethodSource("iterator") + void simpleIterator(int x, int y) { + System.out.println(x + ", " + y); + } + + @ParameterizedTest + @MethodSource(value = {"stream", "iterator", "iterable"}) + void parametersArray(int x, int y) { + System.out.println(x + ", " + y); + } + + @ParameterizedTest + @MethodSource({"stream", "iterator"}) + void implicitValueArray(int x, int y) { + System.out.println(x + ", " + y); + } + + @ParameterizedTest + @MethodSource(value = "argumentsArrayProvider") + void argumentsArray(int x, String s) { + System.out.println(x + ", " + s); + } + + @ParameterizedTest + @MethodSource(value = "objectsArrayProvider") + void objectsArray(int x, String s) { + System.out.println(x + ", " + s); + } + + @ParameterizedTest + @MethodSource(value = "objects2DArrayProvider") + void objects2DArray(int x, String s) { + System.out.println(x + ", " + s); + } + + @ParameterizedTest + @MethodSource("doubleStreamProvider") + void objectdoubleStreamsArray(double d) { + System.out.println(d); + } + + @ParameterizedTest + @MethodSource("intStreamProvider") + void intStream(int x) { + System.out.println(x); + } + + @ParameterizedTest + @MethodSource("longStreamProvider") + void longStream(long l) { + System.out.println(l); + } + + static Stream stream() { + return null; + } + + static Iterator iterator() { + return null; + } + + static Iterable iterable() { + return null; + } + + static Arguments[] argumentsArrayProvider() { + return new Arguments[]{Arguments.of(1, "one")}; + } + + static Object[] objectsArrayProvider() { + return new Object[]{Arguments.of(1, "one")}; + } + + static Object[][] objects2DArrayProvider() { + return new Object[][]{{1, "s"}}; + } + + static DoubleStream doubleStreamProvider() {return null;} + + static IntStream intStreamProvider() {return null;} + + static LongStream longStreamProvider() {return null;} +} + +class MethodSourceMalformed { + @ParameterizedTest + @MethodSource(value = { "a", + "b", + "c", + "d"}) + void testWithParams(Object s) { } + + String[] a() { + return new String[]{"a", "b"}; + } + + static String[] b(int i) { + return new String[]{"a", "b"}; + } + + static Object c() { + return new String[]{"a", "b"}; + } + + static Object[] d() { + return new String[]{"a", "b"}; + } + + @ParameterizedTest + @MethodSource(value = {"unknown"}) + void unknownMethodSource(String s, int i) { } +} \ No newline at end of file