1
2
3
4
5
6 package mockit;
7
8 import static org.junit.jupiter.api.Assertions.assertEquals;
9 import static org.junit.jupiter.api.Assertions.assertTrue;
10
11 import java.util.Arrays;
12 import java.util.List;
13
14 import mockit.integration.MockedClass;
15
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.junit.runners.Parameterized;
19 import org.junit.runners.Parameterized.Parameters;
20
21 import otherTests.TestedClass;
22
23
24
25
26 @RunWith(Parameterized.class)
27 public final class JUnit4ParametersTest {
28
29
30
31
32
33
34 @Parameters(name = "Input squared: {0} -> {1}")
35 public static List<Integer[]> parameters() {
36 Integer[][] data = { { 1, 1 }, { 2, 4 }, { 3, 9 } };
37 return Arrays.asList(data);
38 }
39
40
41 final int input;
42
43
44 final int expected;
45
46
47 @Tested
48 TestedClass cut;
49
50
51 @Injectable
52 MockedClass dependency;
53
54
55
56
57
58
59
60
61
62 public JUnit4ParametersTest(int input, int expected) {
63 this.input = input;
64 this.expected = expected;
65 }
66
67
68
69
70
71
72
73 @Test
74 public void useParameters(@Mocked final Runnable mock) {
75 new Expectations() {
76 {
77 dependency.doSomething(anyInt);
78 result = true;
79 }
80 };
81
82 mock.run();
83 boolean didSomething = cut.doSomething(input);
84
85 assertTrue(didSomething);
86
87 int result = input * input;
88 assertEquals(expected, result);
89
90 new Verifications() {
91 {
92 mock.run();
93 times = 1;
94 }
95 };
96 }
97 }