1 package mockit;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4
5 import org.junit.jupiter.api.Test;
6
7
8
9
10 final class TestedClassWithFieldDIByTypeAndNameTest {
11
12
13
14
15 static class TestedClass {
16
17
18 int someValue;
19
20
21 int anotherValue;
22
23
24
25
26
27
28 final int getSomeValue_base() {
29 return someValue;
30 }
31 }
32
33
34
35
36 static class TestedSubclass extends TestedClass {
37
38
39 @SuppressWarnings("FieldNameHidesFieldInSuperclass")
40 int someValue;
41
42
43 int yetAnotherValue;
44 }
45
46
47 @Tested
48 TestedSubclass tested;
49
50
51
52
53
54
55
56 @Test
57 void injectByFieldTypeAndNameWithTestedClassHavingMultipleFieldsOfSameType(@Injectable("12") int anotherValue) {
58 assertEquals(0, tested.getSomeValue_base());
59 assertEquals(0, tested.someValue);
60 assertEquals(12, tested.anotherValue);
61 assertEquals(0, tested.yetAnotherValue);
62 }
63
64
65
66
67
68
69
70 @Test
71 void injectByFieldTypeAndNameWithTestedClassHavingFieldsOfSameTypeButDifferentNames(@Injectable("45") int val) {
72 assertEquals(0, tested.getSomeValue_base());
73 assertEquals(0, tested.someValue);
74 assertEquals(0, tested.anotherValue);
75 assertEquals(0, tested.yetAnotherValue);
76 }
77
78
79
80
81
82
83
84
85
86
87
88 @Test
89 void injectByFieldTypeAndNameIntoFieldsAtDifferentLevelsOfClassHierarchy(@Injectable("1") int someValue,
90 @Injectable("2") int yetAnotherValue, @Injectable("3") int unused) {
91 assertEquals(0, tested.getSomeValue_base());
92 assertEquals(1, tested.someValue);
93 assertEquals(0, tested.anotherValue);
94 assertEquals(2, tested.yetAnotherValue);
95 }
96 }