1
2
3
4
5
6 package mockit;
7
8 import static org.junit.jupiter.api.Assertions.assertNotNull;
9 import static org.junit.jupiter.api.Assertions.assertNull;
10
11 import jakarta.inject.Inject;
12
13 import mockit.integration.junit5.JMockitExtension;
14
15 import org.junit.jupiter.api.Test;
16 import org.junit.jupiter.api.extension.ExtendWith;
17
18
19
20
21 @ExtendWith(JMockitExtension.class)
22 class TestedClassWithFullMixedFieldDITest {
23
24
25
26
27 static class TestedClass {
28
29
30 @Inject
31 Dependency dependency;
32
33
34 StringBuilder text;
35 }
36
37
38
39
40 static class Dependency {
41
42 String value;
43 }
44
45
46
47
48 static class Dependency2 {
49 }
50
51
52
53
54
55
56
57 @Test
58 void verifyThatFieldsFromJRETypesAreNotInitialized(@Tested(fullyInitialized = true) TestedClass tested) {
59 assertNull(tested.text);
60 assertNull(tested.dependency.value);
61 }
62
63
64
65
66 static class TestedClass2 {
67
68
69 @Inject
70 Dependency dependency1;
71
72
73 Dependency2 dependency2;
74 }
75
76
77
78
79
80
81
82 @Test
83 void verifyThatFieldsOfUserTypesAreInitializedEvenOnlySomeAreAnnotated(
84 @Tested(fullyInitialized = true) TestedClass2 tested) {
85 assertNotNull(tested.dependency1);
86 assertNotNull(tested.dependency2);
87 }
88 }