I want to implement a paramterized JUnit test for a method, that has three input parameters. I want the test to run through the cartesian product of all possible combinations of these three input parameters. For this, I have a method, that generates the Cartesian product and stores it in an Arraylist. How can I access the single values for my test method? I have read about returning a Stream of Arguments but I want to generate the values for the arguments and not write them explicitly.
@ParameterizedTest
@MethodSource("generateCartesianProduct")
public void myTest(int x, int y, int z) {
Assertions.assertTrue(methodToTest(
x, y, z));
}
private static whatToReturnHere?? generateCartesianProduct() {
int[] x = {1, 2, 3};
int[] y = {4, 5, 6};
int[] z = {7, 8, 9};
ArrayList<Integer> list = new ArrayList<>();
ArrayList<ArrayList> result = new ArrayList<>();
for (int i = 0; i < x.length; i++) {
for (int j = 0; j < y.length; j++) {
for (int k = 0; k < z.length; k++) {
list = new ArrayList<>();
list.add(x[i]);
list.add(y[j]);
list.add(z[k]);
result.add(list);
}
}
}
return result;
}