@Test public void testSmokeEveryThingThroughInjectionFramework() throws Exception { @SuppressWarnings("unchecked") final Class<? extends Tobacco>[] tobaccos = new Class[]{ OldTobyTobacco.class, RivendellTobacco.class, SecondBreakfastTobacco.class }; for (final Class<? extends Tobacco> tobaccoClass : tobaccos) { final Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(Tobacco.class).to(tobaccoClass); } }); final GuiceWizard guiceWizard = injector.getInstance(GuiceWizard.class); guiceWizard.smoke(); assertEquals("GuiceWizard smoking " + tobaccoClass.getSimpleName(), appender.getLastMessage()); } assertEquals(tobaccos.length, appender.getLogSize()); }
@Override public void smoke() { tobacco.smoke(this); }
GuiceWizard implements Wizard { @Override public void smoke() { tobacco.smoke(this); } }
GuiceWizard implements Wizard { @Override public void smoke() { tobacco.smoke(this); } @Inject  GuiceWizard(Tobacco tobacco); }
GuiceWizard implements Wizard { @Override public void smoke() { tobacco.smoke(this); } @Inject  GuiceWizard(Tobacco tobacco); @Override void smoke(); }
GuiceWizard implements Wizard { @Override public void smoke() { tobacco.smoke(this); } @Inject  GuiceWizard(Tobacco tobacco); @Override void smoke();  }