1 package mockit;
2
3 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4 import static org.junit.jupiter.api.Assertions.assertEquals;
5 import static org.junit.jupiter.api.Assertions.assertFalse;
6 import static org.junit.jupiter.api.Assertions.assertNotNull;
7 import static org.junit.jupiter.api.Assertions.assertTrue;
8
9 import org.junit.jupiter.api.Test;
10
11
12
13
14 @SuppressWarnings({ "UnusedParameters", "ClassWithTooManyFields" })
15 final class TestedClassWithConstructorDI0Test {
16
17
18
19
20 public static final class TestedClassWithConstructorHavingPrimitiveParameter {
21
22
23
24
25
26
27
28 public TestedClassWithConstructorHavingPrimitiveParameter(int i) {
29 assertEquals(123, i);
30 }
31 }
32
33
34
35
36 public static final class TestedClassWithConstructorHavingStringParameter {
37
38
39
40
41
42
43
44 public TestedClassWithConstructorHavingStringParameter(String s) {
45 }
46 }
47
48
49
50
51 public static final class TestedClassWithConstructorHavingArrayParameter {
52
53
54
55
56
57
58
59 public TestedClassWithConstructorHavingArrayParameter(String[] arr) {
60 assertArrayEquals(new String[] { "abc", "Xyz" }, arr);
61 }
62 }
63
64
65
66
67 public static final class TestedClassWithConstructorHavingLongParameters {
68
69
70
71
72
73
74
75
76
77 @SuppressWarnings("unused")
78 public TestedClassWithConstructorHavingLongParameters(long l1, long l2) {
79 assertEquals(1, l1);
80 assertEquals(2, l2);
81 }
82
83
84
85
86
87
88
89
90
91
92
93 @SuppressWarnings("unused")
94 TestedClassWithConstructorHavingLongParameters(int i, long l1, long l2) {
95 throw new RuntimeException("Must not occur");
96 }
97 }
98
99
100
101
102 public static final class TestedClassWithConstructorHavingDoubleParameters {
103
104
105
106
107
108
109
110
111
112 TestedClassWithConstructorHavingDoubleParameters(double d1, double d2) {
113 assertEquals(1.0, d1, 0);
114 assertEquals(2.0, d2, 0);
115 }
116 }
117
118
119
120
121 public static final class TestedClassWithConstructorHavingVarargsParameter {
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 public TestedClassWithConstructorHavingVarargsParameter(byte b, char c, String s, byte b2, boolean... flags) {
138 assertEquals(56, b);
139 assertEquals(57, b2);
140 assertEquals('X', c);
141 assertEquals("test", s);
142 assertEquals(3, flags.length);
143 assertTrue(flags[0]);
144 assertFalse(flags[1]);
145 assertTrue(flags[2]);
146 }
147 }
148
149
150
151
152 public static final class TestedClassWithConstructorHavingDoubleSizeParameterFollowedByRegularParameters {
153
154
155
156
157
158
159
160
161
162
163
164 public TestedClassWithConstructorHavingDoubleSizeParameterFollowedByRegularParameters(long l1, char c,
165 String s) {
166 assertEquals(1, l1);
167 assertEquals('X', c);
168 assertEquals("test", s);
169 }
170 }
171
172
173 @Tested
174 TestedClassWithConstructorHavingPrimitiveParameter tested0;
175
176
177 @Tested
178 TestedClassWithConstructorHavingStringParameter tested1;
179
180
181 @Tested
182 TestedClassWithConstructorHavingArrayParameter tested2;
183
184
185 @Tested
186 TestedClassWithConstructorHavingLongParameters tested3;
187
188
189 @Tested
190 TestedClassWithConstructorHavingDoubleParameters tested4;
191
192
193 @Tested
194 TestedClassWithConstructorHavingVarargsParameter tested5;
195
196
197 @Tested
198 TestedClassWithConstructorHavingDoubleSizeParameterFollowedByRegularParameters tested6;
199
200
201 @Injectable
202 int i = 123;
203
204
205 @Injectable
206 int unused;
207
208
209 @Injectable
210 long l1 = 1;
211
212
213 @Injectable
214 final long l2 = 2;
215
216
217 @Injectable
218 String[] arr = { "abc", "Xyz" };
219
220
221 @Injectable
222 byte b = 56;
223
224
225 @Injectable
226 byte b2 = 57;
227
228
229 @Injectable
230 char c = 'X';
231
232
233 @Injectable
234 String s = "test";
235
236
237 @Injectable
238 double d1 = 1.0;
239
240
241 @Injectable
242 double d2 = 2.0;
243
244
245
246 @Injectable
247 boolean firstFlag = true;
248
249
250 @Injectable("false")
251 boolean secondFlag;
252
253
254 @Injectable
255 boolean thirdFlag = true;
256
257
258
259
260 @Test
261 void verifyInstantiationOfTestedObjectsThroughConstructorsWithNonMockedParameters() {
262 assertNotNull(tested0);
263 assertNotNull(tested1);
264 assertNotNull(tested2);
265 assertNotNull(tested3);
266 assertNotNull(tested4);
267 assertNotNull(tested5);
268 assertNotNull(tested6);
269 }
270 }