Search in sources :

Example 6 with BaseAndClassicModules

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);
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 7 with BaseAndClassicModules

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));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) PostofficeMockImpl(ninja.postoffice.mock.PostofficeMockImpl) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 8 with BaseAndClassicModules

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));
}
Also used : Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 9 with BaseAndClassicModules

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();
}
Also used : Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 10 with BaseAndClassicModules

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));
}
Also used : Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Aggregations

Injector (com.google.inject.Injector)14 BaseAndClassicModules (ninja.BaseAndClassicModules)14 Test (org.junit.Test)14 NinjaPropertiesImpl (ninja.utils.NinjaPropertiesImpl)9 MigrationEngineFlyway (ninja.migrations.flyway.MigrationEngineFlyway)1 PostofficeMockImpl (ninja.postoffice.mock.PostofficeMockImpl)1