use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class PostofficeProviderTest method verifySingletonProviderAndInstance.
@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);
// cache provider should be a singleton
assertThat(provider, sameInstance(injector.getInstance(PostofficeProvider.class)));
assertThat(provider, sameInstance(injector.getInstance(PostofficeProvider.class)));
Postoffice postoffice = provider.get();
// cache should be a singleton
assertThat(postoffice, sameInstance(provider.get()));
assertThat(postoffice, sameInstance(injector.getInstance(Postoffice.class)));
}
use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class PostofficeProviderTest method missingImplementationThrowsExceptionOnUseNotCreate.
@Test
public void missingImplementationThrowsExceptionOnUseNotCreate() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty(PostofficeConstant.postofficeImplementation, "not_existing_implementation");
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
Provider<Postoffice> provider = injector.getProvider(Postoffice.class);
// this will not work => we expect a runtime exception...
thrown.expect(RuntimeException.class);
Postoffice postoffice = injector.getInstance(Postoffice.class);
}
use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class MigrationEngineProviderTest method defaultImplementation.
@Test
public void defaultImplementation() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty(NinjaConstant.MIGRATION_ENGINE_IMPLEMENTATION, null);
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
Provider<MigrationEngine> provider = injector.getProvider(MigrationEngine.class);
assertThat(provider.get(), instanceOf(MigrationEngineFlyway.class));
}
use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class ImplFromPropertiesFactoryTest method missingImplementation.
@Test
public void missingImplementation() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty("i.am.a.test.implementation", "does_not_exist");
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
// this will not work => we expect a runtime exception with the impl missing
thrown.expect(RuntimeException.class);
ImplFromPropertiesFactory<MockInterface> factory = new ImplFromPropertiesFactory<>(injector, ninjaProperties, "i.am.a.test.implementation", MockInterface.class, null, false, logger);
}
use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class CacheProviderTest method missingImplementationThrowsExceptionOnUseNotCreate.
@Test
public void missingImplementationThrowsExceptionOnUseNotCreate() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty(NinjaConstant.CACHE_IMPLEMENTATION, "not_existing_implementation");
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
Provider<Cache> provider = injector.getProvider(Cache.class);
// this will not work => we expect a runtime exception...
thrown.expect(RuntimeException.class);
Cache cache = injector.getInstance(Cache.class);
}
Aggregations