View Javadoc
1   package mockit;
2   
3   import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4   import static org.junit.jupiter.api.Assertions.assertEquals;
5   import static org.junit.jupiter.api.Assertions.assertFalse;
6   import static org.junit.jupiter.api.Assertions.assertNotNull;
7   import static org.junit.jupiter.api.Assertions.assertTrue;
8   
9   import org.junit.jupiter.api.Test;
10  
11  /**
12   * The Class TestedClassWithConstructorDI0Test.
13   */
14  @SuppressWarnings({ "UnusedParameters", "ClassWithTooManyFields" })
15  final class TestedClassWithConstructorDI0Test {
16  
17      /**
18       * The Class TestedClassWithConstructorHavingPrimitiveParameter.
19       */
20      public static final class TestedClassWithConstructorHavingPrimitiveParameter {
21  
22          /**
23           * Instantiates a new tested class with constructor having primitive parameter.
24           *
25           * @param i
26           *            the i
27           */
28          public TestedClassWithConstructorHavingPrimitiveParameter(int i) {
29              assertEquals(123, i);
30          }
31      }
32  
33      /**
34       * The Class TestedClassWithConstructorHavingStringParameter.
35       */
36      public static final class TestedClassWithConstructorHavingStringParameter {
37  
38          /**
39           * Instantiates a new tested class with constructor having string parameter.
40           *
41           * @param s
42           *            the s
43           */
44          public TestedClassWithConstructorHavingStringParameter(String s) {
45          }
46      }
47  
48      /**
49       * The Class TestedClassWithConstructorHavingArrayParameter.
50       */
51      public static final class TestedClassWithConstructorHavingArrayParameter {
52  
53          /**
54           * Instantiates a new tested class with constructor having array parameter.
55           *
56           * @param arr
57           *            the arr
58           */
59          public TestedClassWithConstructorHavingArrayParameter(String[] arr) {
60              assertArrayEquals(new String[] { "abc", "Xyz" }, arr);
61          }
62      }
63  
64      /**
65       * The Class TestedClassWithConstructorHavingLongParameters.
66       */
67      public static final class TestedClassWithConstructorHavingLongParameters {
68  
69          /**
70           * Instantiates a new tested class with constructor having long parameters.
71           *
72           * @param l1
73           *            the l 1
74           * @param l2
75           *            the l 2
76           */
77          @SuppressWarnings("unused")
78          public TestedClassWithConstructorHavingLongParameters(long l1, long l2) {
79              assertEquals(1, l1);
80              assertEquals(2, l2);
81          }
82  
83          /**
84           * Instantiates a new tested class with constructor having long parameters.
85           *
86           * @param i
87           *            the i
88           * @param l1
89           *            the l 1
90           * @param l2
91           *            the l 2
92           */
93          @SuppressWarnings("unused")
94          TestedClassWithConstructorHavingLongParameters(int i, long l1, long l2) {
95              throw new RuntimeException("Must not occur");
96          }
97      }
98  
99      /**
100      * The Class TestedClassWithConstructorHavingDoubleParameters.
101      */
102     public static final class TestedClassWithConstructorHavingDoubleParameters {
103 
104         /**
105          * Instantiates a new tested class with constructor having double parameters.
106          *
107          * @param d1
108          *            the d 1
109          * @param d2
110          *            the d 2
111          */
112         TestedClassWithConstructorHavingDoubleParameters(double d1, double d2) {
113             assertEquals(1.0, d1, 0);
114             assertEquals(2.0, d2, 0);
115         }
116     }
117 
118     /**
119      * The Class TestedClassWithConstructorHavingVarargsParameter.
120      */
121     public static final class TestedClassWithConstructorHavingVarargsParameter {
122 
123         /**
124          * Instantiates a new tested class with constructor having varargs parameter.
125          *
126          * @param b
127          *            the b
128          * @param c
129          *            the c
130          * @param s
131          *            the s
132          * @param b2
133          *            the b 2
134          * @param flags
135          *            the flags
136          */
137         public TestedClassWithConstructorHavingVarargsParameter(byte b, char c, String s, byte b2, boolean... flags) {
138             assertEquals(56, b);
139             assertEquals(57, b2);
140             assertEquals('X', c);
141             assertEquals("test", s);
142             assertEquals(3, flags.length);
143             assertTrue(flags[0]);
144             assertFalse(flags[1]);
145             assertTrue(flags[2]);
146         }
147     }
148 
149     /**
150      * The Class TestedClassWithConstructorHavingDoubleSizeParameterFollowedByRegularParameters.
151      */
152     public static final class TestedClassWithConstructorHavingDoubleSizeParameterFollowedByRegularParameters {
153 
154         /**
155          * Instantiates a new tested class with constructor having double size parameter followed by regular parameters.
156          *
157          * @param l1
158          *            the l 1
159          * @param c
160          *            the c
161          * @param s
162          *            the s
163          */
164         public TestedClassWithConstructorHavingDoubleSizeParameterFollowedByRegularParameters(long l1, char c,
165                 String s) {
166             assertEquals(1, l1);
167             assertEquals('X', c);
168             assertEquals("test", s);
169         }
170     }
171 
172     /** The tested 0. */
173     @Tested
174     TestedClassWithConstructorHavingPrimitiveParameter tested0;
175 
176     /** The tested 1. */
177     @Tested
178     TestedClassWithConstructorHavingStringParameter tested1;
179 
180     /** The tested 2. */
181     @Tested
182     TestedClassWithConstructorHavingArrayParameter tested2;
183 
184     /** The tested 3. */
185     @Tested
186     TestedClassWithConstructorHavingLongParameters tested3;
187 
188     /** The tested 4. */
189     @Tested
190     TestedClassWithConstructorHavingDoubleParameters tested4;
191 
192     /** The tested 5. */
193     @Tested
194     TestedClassWithConstructorHavingVarargsParameter tested5;
195 
196     /** The tested 6. */
197     @Tested
198     TestedClassWithConstructorHavingDoubleSizeParameterFollowedByRegularParameters tested6;
199 
200     /** The i. */
201     @Injectable
202     int i = 123;
203 
204     /** The unused. */
205     @Injectable
206     int unused;
207 
208     /** The l 1. */
209     @Injectable
210     long l1 = 1;
211 
212     /** The l 2. */
213     @Injectable
214     final long l2 = 2;
215 
216     /** The arr. */
217     @Injectable
218     String[] arr = { "abc", "Xyz" };
219 
220     /** The b. */
221     @Injectable
222     byte b = 56;
223 
224     /** The b 2. */
225     @Injectable
226     byte b2 = 57;
227 
228     /** The c. */
229     @Injectable
230     char c = 'X';
231 
232     /** The s. */
233     @Injectable
234     String s = "test";
235 
236     /** The d 1. */
237     @Injectable
238     double d1 = 1.0;
239 
240     /** The d 2. */
241     @Injectable
242     double d2 = 2.0;
243 
244     /** The first flag. */
245     // For varargs parameter:
246     @Injectable
247     boolean firstFlag = true;
248 
249     /** The second flag. */
250     @Injectable("false")
251     boolean secondFlag;
252 
253     /** The third flag. */
254     @Injectable
255     boolean thirdFlag = true;
256 
257     /**
258      * Verify instantiation of tested objects through constructors with non mocked parameters.
259      */
260     @Test
261     void verifyInstantiationOfTestedObjectsThroughConstructorsWithNonMockedParameters() {
262         assertNotNull(tested0);
263         assertNotNull(tested1);
264         assertNotNull(tested2);
265         assertNotNull(tested3);
266         assertNotNull(tested4);
267         assertNotNull(tested5);
268         assertNotNull(tested6);
269     }
270 }