use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class MigrationEngineProviderTest method missingImplementationThrowsExceptionOnUseNotCreate.
@Test
public void missingImplementationThrowsExceptionOnUseNotCreate() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty(NinjaConstant.MIGRATION_ENGINE_IMPLEMENTATION, "not_existing_implementation");
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
Provider<MigrationEngine> provider = injector.getProvider(MigrationEngine.class);
// this will not work => we expect a runtime exception...
thrown.expect(RuntimeException.class);
MigrationEngine migrationEngine = injector.getInstance(MigrationEngine.class);
}
use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class PostofficeProviderTest method defaultImplementation.
@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));
}
use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class ImplFromPropertiesFactoryTest method defaultImplementation.
@Test
public void defaultImplementation() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
//ninjaProperties.setProperty("i.am.a.test.implementation", null);
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
// inner class requires $ symbol
ImplFromPropertiesFactory<MockInterface> factory = new ImplFromPropertiesFactory<>(injector, ninjaProperties, "i.am.a.test.implementation", MockInterface.class, "ninja.utils.ImplFromPropertiesFactoryTest$MockInterfaceImpl", false, logger);
MockInterface mockObject = factory.create();
assertThat(mockObject, instanceOf(MockInterfaceImpl.class));
}
use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class ImplFromPropertiesFactoryTest method missingImplementationDeferredUntilGet.
@Test
public void missingImplementationDeferredUntilGet() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty("i.am.a.test.implementation", "does_not_exist");
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
// this should be okay since we want to defer the resolution until a 'get'
ImplFromPropertiesFactory<MockInterface> factory = new ImplFromPropertiesFactory<>(injector, ninjaProperties, "i.am.a.test.implementation", MockInterface.class, null, true, logger);
// this will not work => we expect a runtime exception with the impl missing
thrown.expect(RuntimeException.class);
factory.create();
}
use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class ImplFromPropertiesFactoryTest method configuredImplementation.
@Test
public void configuredImplementation() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty("i.am.a.test.implementation", "ninja.utils.ImplFromPropertiesFactoryTest$MockInterfaceImpl");
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
ImplFromPropertiesFactory<MockInterface> factory = new ImplFromPropertiesFactory<>(injector, ninjaProperties, "i.am.a.test.implementation", MockInterface.class, null, false, logger);
MockInterface mockObject = factory.create();
assertThat(mockObject, instanceOf(MockInterfaceImpl.class));
}
Aggregations