More tests for MalformedParameterized inspection

This commit is contained in:
Timur Yuldashev
2017-07-13 21:08:35 +03:00
parent e5f918f48d
commit 008f6bdc3e
4 changed files with 179 additions and 69 deletions
@@ -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(); }
@@ -2,53 +2,22 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.*;
class ParameterizedTestsDemo {
<warning descr="No sources are provided, the suite would be empty">@ParameterizedTest</warning>
void testWithParamsNoSource(int i) { }
@ParameterizedTest
@MethodSource(value = {<warning descr="Method source 'a' must be static">"a"</warning>,
<warning descr="Method source 'b' should have no parameters">"b"</warning>,
<warning descr="Method source 'c' must have one of the following return type: Stream<?>, Iterator<?>, Iterable<?> or Object[]">"c"</warning>,
"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(<warning descr="No implicit conversion found to convert object of type E to int">E.class</warning>)
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
<warning descr="Exactly one type of input must be provided">@ValueSource(ints = {1},
@@ -73,3 +42,25 @@ class ParameterizedTestsDemo {
void testWithTestAnnotationNoParameterized(int i) { }
}
class ParameterizedTestsDemo {
<warning descr="No sources are provided, the suite would be empty">@ParameterizedTest</warning>
void testWithParamsNoSource(int i) { }
@ParameterizedTest
@EnumSource(<warning descr="No implicit conversion found to convert object of type E to int">E.class</warning>)
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) {}
}
@@ -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<Arguments> stream() {
return null;
}
static Iterator<Arguments> iterator() {
return null;
}
}
@@ -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<Arguments> stream() {
return null;
}
static Iterator<Arguments> iterator() {
return null;
}
static Iterable<Arguments> 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 = { <warning descr="Method source 'a' must be static">"a"</warning>,
<warning descr="Method source 'b' should have no parameters">"b"</warning>,
<warning descr="Method source 'c' must have one of the following return type: Stream<?>, Iterator<?>, Iterable<?> or Object[]">"c"</warning>,
"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 = {<warning descr="Cannot resolve target method source: 'unknown'">"unknown"</warning>})
void unknownMethodSource(String s, int i) { }
}