View Javadoc
1   package mockit;
2   
3   import static org.junit.jupiter.api.Assertions.assertEquals;
4   
5   import org.junit.jupiter.api.Test;
6   
7   /**
8    * The Class TestedClassWithFieldDIByTypeAndNameTest.
9    */
10  final class TestedClassWithFieldDIByTypeAndNameTest {
11  
12      /**
13       * The Class TestedClass.
14       */
15      static class TestedClass {
16  
17          /** The some value. */
18          int someValue;
19  
20          /** The another value. */
21          int anotherValue;
22  
23          /**
24           * Gets the some value base.
25           *
26           * @return the some value base
27           */
28          final int getSomeValue_base() {
29              return someValue;
30          }
31      }
32  
33      /**
34       * The Class TestedSubclass.
35       */
36      static class TestedSubclass extends TestedClass {
37  
38          /** The some value. */
39          @SuppressWarnings("FieldNameHidesFieldInSuperclass")
40          int someValue;
41  
42          /** The yet another value. */
43          int yetAnotherValue;
44      }
45  
46      /** The tested. */
47      @Tested
48      TestedSubclass tested;
49  
50      /**
51       * Inject by field type and name with tested class having multiple fields of same type.
52       *
53       * @param anotherValue
54       *            the another value
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       * Inject by field type and name with tested class having fields of same type but different names.
66       *
67       * @param val
68       *            the val
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       * Inject by field type and name into fields at different levels of class hierarchy.
80       *
81       * @param someValue
82       *            the some value
83       * @param yetAnotherValue
84       *            the yet another value
85       * @param unused
86       *            the unused
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  }