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