@@ -392,4 +392,109 @@ public void testOverrideMethodInjection() {
392
392
.and ()
393
393
.generatesSources (expectedSource );
394
394
}
395
+
396
+ @ Test
397
+ public void testMethodInjection_withException () {
398
+ JavaFileObject source =
399
+ JavaFileObjects .forSourceString (
400
+ "test.TestMethodInjection" ,
401
+ Joiner .on ('\n' )
402
+ .join ( //
403
+ "package test;" , //
404
+ "import javax.inject.Inject;" , //
405
+ "public class TestMethodInjection {" , //
406
+ " @Inject" , //
407
+ " public void m(Foo foo) throws Exception {}" , //
408
+ "}" , //
409
+ "class Foo {}" //
410
+ ));
411
+
412
+ JavaFileObject expectedSource =
413
+ JavaFileObjects .forSourceString (
414
+ "test/TestMethodInjection__MemberInjector" ,
415
+ Joiner .on ('\n' )
416
+ .join ( //
417
+ "package test;" , //
418
+ "" , //
419
+ "import java.lang.Exception;" , //
420
+ "import java.lang.Override;" , //
421
+ "import java.lang.RuntimeException;" , //
422
+ "import toothpick.MemberInjector;" , //
423
+ "import toothpick.Scope;" , //
424
+ "" , //
425
+ "public final class TestMethodInjection__MemberInjector implements MemberInjector<TestMethodInjection> {" , //
426
+ " @Override" , //
427
+ " public void inject(TestMethodInjection target, Scope scope) {" , //
428
+ " Foo param1 = scope.getInstance(Foo.class);" , //
429
+ " try {" , //
430
+ " target.m(param1);" , //
431
+ " } catch(Exception e1) {" , //
432
+ " throw new RuntimeException(e1);" , //
433
+ " } " , //
434
+ " }" , //
435
+ "}" //
436
+ ));
437
+
438
+ assert_ ()
439
+ .about (javaSource ())
440
+ .that (source )
441
+ .processedWith (memberInjectorProcessors ())
442
+ .compilesWithoutError ()
443
+ .and ()
444
+ .generatesSources (expectedSource );
445
+ }
446
+
447
+ @ Test
448
+ public void testMethodInjection_withExceptions () {
449
+ JavaFileObject source =
450
+ JavaFileObjects .forSourceString (
451
+ "test.TestMethodInjection" ,
452
+ Joiner .on ('\n' )
453
+ .join ( //
454
+ "package test;" , //
455
+ "import javax.inject.Inject;" , //
456
+ "public class TestMethodInjection {" , //
457
+ " @Inject" , //
458
+ " public void m(Foo foo) throws Exception, Throwable {}" , //
459
+ "}" , //
460
+ "class Foo {}" //
461
+ ));
462
+
463
+ JavaFileObject expectedSource =
464
+ JavaFileObjects .forSourceString (
465
+ "test/TestMethodInjection__MemberInjector" ,
466
+ Joiner .on ('\n' )
467
+ .join ( //
468
+ "package test;" , //
469
+ "" , //
470
+ "import java.lang.Exception;" , //
471
+ "import java.lang.Override;" , //
472
+ "import java.lang.RuntimeException;" , //
473
+ "import java.lang.Throwable;" , //
474
+ "import toothpick.MemberInjector;" , //
475
+ "import toothpick.Scope;" , //
476
+ "" , //
477
+ "public final class TestMethodInjection__MemberInjector implements MemberInjector<TestMethodInjection> {" , //
478
+ " @Override" , //
479
+ " public void inject(TestMethodInjection target, Scope scope) {" , //
480
+ " Foo param1 = scope.getInstance(Foo.class);" , //
481
+ " try {" , //
482
+ " target.m(param1);" , //
483
+ " } catch(Exception e1) {" , //
484
+ " throw new RuntimeException(e1);" , //
485
+ " } catch(Throwable e2) {" , //
486
+ " throw new RuntimeException(e2);" , //
487
+ " } " , //
488
+ " }" , //
489
+ "}" //
490
+ ));
491
+
492
+ assert_ ()
493
+ .about (javaSource ())
494
+ .that (source )
495
+ .processedWith (memberInjectorProcessors ())
496
+ .compilesWithoutError ()
497
+ .and ()
498
+ .generatesSources (expectedSource );
499
+ }
395
500
}
0 commit comments