PostofficeProvider implements Provider<Postoffice> { @Override public Postoffice get() { return this.supplier.get(); } @Inject  PostofficeProvider(Injector injector, NinjaProperties ninjaProperties); @Override Postoffice get();  }
@Test public void defaultImplementation() { NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test); ninjaProperties.setProperty(PostofficeConstant.postofficeImplementation, null); Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties)); PostofficeProvider postofficeProvider = injector.getInstance(PostofficeProvider.class); assertThat(postofficeProvider.get(), instanceOf(PostofficeMockImpl.class)); }
@Test public void verifySingletonProviderAndInstance() { NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test); ninjaProperties.setProperty(PostofficeConstant.postofficeImplementation, null); Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties)); PostofficeProvider provider = injector.getInstance(PostofficeProvider.class); assertThat(provider, sameInstance(injector.getInstance(PostofficeProvider.class))); assertThat(provider, sameInstance(injector.getInstance(PostofficeProvider.class))); Postoffice postoffice = provider.get(); assertThat(postoffice, sameInstance(provider.get())); assertThat(postoffice, sameInstance(injector.getInstance(Postoffice.class))); }