@@ -196,22 +196,26 @@ public void captureClassWhichImplementsCapturedBaseInterfaceAndExtendsUnrelatedB
196
196
static class Base <T > {
197
197
T doSomething () { return null ; }
198
198
void doSomething (T t ) { System .out .println ("test" );}
199
+ T doSomethingReturn (T t ) { return t ;}
199
200
}
200
201
201
202
static final class Impl extends Base <Integer > {
202
203
@ Override Integer doSomething () { return 1 ; }
203
204
@ Override void doSomething (Integer i ) {}
205
+ @ Override Integer doSomethingReturn (Integer t ) { return null ;}
204
206
}
205
207
206
208
@ Test
207
209
public void captureImplementationsOfGenericType (@ Capturing final Base <Integer > anyInstance ) {
208
210
new Expectations () {{
209
211
anyInstance .doSomething (); result = 2 ;
212
+ anyInstance .doSomethingReturn (0 );
210
213
anyInstance .doSomething (0 );
211
214
}};
212
215
213
216
Base <Integer > impl = new Impl ();
214
217
int i = impl .doSomething ();
218
+ impl .doSomethingReturn (0 );
215
219
impl .doSomething (0 );
216
220
217
221
assertEquals (2 , i );
@@ -263,4 +267,48 @@ public void captureLibraryClassImplementingInterfaceFromAnotherLibrary(@Capturin
263
267
264
268
new Verifications () {{ mock .contextInitialized (null ); }};
265
269
}
270
+
271
+ static class BaseGenericReturnTypes {
272
+ Class <?> methodOne () {return null ;}
273
+ Class <?> methodTwo () {return null ;}
274
+ }
275
+ static class SubGenericReturnTypes extends BaseGenericReturnTypes {}
276
+
277
+ @ Test
278
+ public void captureMethodWithGenericReturnTypes (@ Capturing final BaseGenericReturnTypes mock ) {
279
+ new Expectations () {{
280
+ mock .methodOne ();
281
+ result = BaseGenericReturnTypes .class ;
282
+ times = 1 ;
283
+
284
+ mock .methodTwo ();
285
+ result = SubGenericReturnTypes .class ;
286
+ times = 1 ;
287
+ }};
288
+ SubGenericReturnTypes subBaseGenericReturnTypes = new SubGenericReturnTypes ();
289
+ assertEquals (BaseGenericReturnTypes .class , subBaseGenericReturnTypes .methodOne ());
290
+ assertEquals (SubGenericReturnTypes .class , subBaseGenericReturnTypes .methodTwo ());
291
+ }
292
+
293
+ static class BaseR {
294
+ void foo () {};
295
+ void bar () {};
296
+ }
297
+
298
+ static class SubR extends BaseR {}
299
+
300
+ @ Test
301
+ public void captureR (@ Capturing final BaseR mock ) {
302
+ new Expectations () {{
303
+ mock .foo ();
304
+ times = 1 ;
305
+
306
+ mock .bar ();
307
+ times = 1 ;
308
+ }};
309
+ SubR subR = new SubR ();
310
+ subR .foo ();
311
+ subR .bar ();
312
+ }
313
+
266
314
}
0 commit comments