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