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