@Test public void testAllTogether() throws Exception { DSInjector injector = DependencyShot.getInjector( new AOPBinder() { @Override public void configure() { bind(Service.class).to(HelloService.class); cut(HelloService.class).with(HelloInterceptor.class); cut("cx*.all.HelloService").with(ClassPatternInterceptor.class); cut("cx.ath.*.all.HelloS*.hell*()").with(MethodPatternInterceptor.class); } }); Service service = injector.getInstance(Service.class); ResultSingleton result = injector.getInstance(ResultSingleton.class); service.hello(); Assert.assertTrue(result.getBeforeCall() == 4); Assert.assertTrue(result.getAfterCall() == 4); service.hello(); Assert.assertTrue(result.getBeforeCall() == 8); Assert.assertTrue(result.getAfterCall() == 8); service.something(); Assert.assertTrue(result.getBeforeCall() == 12); Assert.assertTrue(result.getAfterCall() == 12); service.goodbye(); Assert.assertTrue(result.getBeforeCall() == 12); Assert.assertTrue(result.getAfterCall() == 12); }
@Test public void testEasySpecificInstancesInjection() { DSInjector injector = DependencyShot.getInjector(new EasyInstanceBinder()); Module module1 = injector.getInstance(InstanceModule.class); Module module2 = injector.getInstance(InstanceModule2.class); Module module3 = injector.getInstance(InstanceModule3.class); module1.start(); module2.start(); module3.start(); assertTrue(module1.getName().equals(EasyInstanceBinder.MY_MODULE)); assertTrue(module2.getName().equals(EasyInstanceBinder.MY_OTHER_MODULE)); assertTrue(module3.getName().equals(EasyInstanceBinder.YAM)); assertEquals(module1.getNullString(), null); assertEquals(module2.getNullString(), null); assertEquals(module3.getNullString(), null); }
@Test public void testInstanceInjection() { DSInjector injector = DependencyShot.getInjector(new EasyInstanceBinder()); ServiceClient client = injector.getInstance(ServiceClient.class); assertTrue(client.getService().getValue().equals(EasyInstanceBinder.MY_MODULE)); }