1package junitparams.custom.combined;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import org.junit.Test;
7
8import static java.util.Collections.*;
9import static org.assertj.core.api.Assertions.*;
10
11public class CartesianTest {
12
13    @Test
14    public void shouldReturnEmptyWhenNoArgumentsPassed() {
15        // when
16        Object result[] = Cartesian.getCartesianProductOf(null);
17
18        // then
19        assertThat(result).isEmpty();
20    }
21
22    @Test
23    public void shouldReturnInputWhenOneArgumentPassed() {
24        Object[] testArray = new String[]{"AAA", "BBB"};
25        List<Object[]> list = singletonList(testArray);
26
27        // when
28        Object result[] = Cartesian.getCartesianProductOf(list);
29
30        // then
31        assertThat(result).isEqualTo(testArray);
32    }
33
34    @Test
35    public void shouldReturnProductOfTwoArrays() {
36        Object[] testArrayOne = new String[]{"AAA", "BBB"};
37        Object[] testArrayTwo = new Integer[]{1, 2};
38
39        List<Object[]> test = new ArrayList<Object[]>();
40        test.add(testArrayOne);
41        test.add(testArrayTwo);
42
43        Object[] expectedResult = new Object[][]{
44                {"AAA", 1}, {"AAA", 2},
45                {"BBB", 1}, {"BBB", 2},
46        };
47
48        // when
49        Object result[] = Cartesian.getCartesianProductOf(test);
50
51        // then
52        assertThat(result).isEqualTo(expectedResult);
53    }
54
55    @Test
56    public void shouldReturnProductOfThreeArrays() {
57        Object[] testArrayOne = new String[]{"AAA", "BBB"};
58        Object[] testArrayTwo = new Integer[]{1, 2};
59        Object[] testArrayThree = new String[]{"XXX", "YYY"};
60
61        List<Object[]> test = new ArrayList<Object[]>();
62        test.add(testArrayOne);
63        test.add(testArrayTwo);
64        test.add(testArrayThree);
65
66        Object[] expectedResult = new Object[][]{
67                {"AAA", 1, "XXX"}, {"AAA", 1, "YYY"},
68                {"AAA", 2, "XXX"}, {"AAA", 2, "YYY"},
69                {"BBB", 1, "XXX"}, {"BBB", 1, "YYY"},
70                {"BBB", 2, "XXX"}, {"BBB", 2, "YYY"},
71        };
72
73        // when
74        Object result[] = Cartesian.getCartesianProductOf(test);
75
76        // then
77        assertThat(result).isEqualTo(expectedResult);
78    }
79}
80