1
2
3
4
5
6 package mockit;
7
8 import static org.junit.jupiter.api.Assertions.assertEquals;
9
10 import mockit.integration.junit5.ExpectedException;
11 import mockit.integration.junit5.JMockitExtension;
12
13 import org.junit.jupiter.api.Test;
14 import org.junit.jupiter.api.extension.ExtendWith;
15
16
17
18
19 @ExtendWith(JMockitExtension.class)
20 class TestedFieldWithFailedConstructorDITest {
21
22
23
24
25 static class ClassWithOneParameter {
26
27
28 Integer value;
29
30
31
32
33
34
35
36 ClassWithOneParameter(Integer value) {
37 this.value = value;
38 }
39 }
40
41
42 @Tested
43 ClassWithOneParameter tested;
44
45
46 @Injectable
47 Integer foo;
48
49
50
51
52
53
54
55 @Test
56 @ExpectedException(value = IllegalArgumentException.class, expectedMessages = "No injectable value available for parameter \"value\" in constructor ClassWithOneParameter(Integer value)")
57 void attemptToUseTestedObjectWhoseCreationFailedDueToInjectableWithoutAValue(@Injectable String s) {
58
59 assertEquals("", s);
60 }
61 }