use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class ImplFromPropertiesFactoryTest method implementationNotAnInstanceOfTarget.
@Test
public void implementationNotAnInstanceOfTarget() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty("i.am.a.test.implementation", "java.lang.Object");
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
ImplFromPropertiesFactory<MockInterface> factory = new ImplFromPropertiesFactory<>(injector, ninjaProperties, "i.am.a.test.implementation", MockInterface.class, null, true, logger);
thrown.expect(RuntimeException.class);
MockInterface mockObject = factory.create();
}
use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class CacheProviderTest method verifySingletonProviderAndInstance.
@Test
public void verifySingletonProviderAndInstance() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty(NinjaConstant.CACHE_IMPLEMENTATION, CacheMockImpl.class.getCanonicalName());
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
CacheProvider cacheProvider = injector.getInstance(CacheProvider.class);
// cache provider should be a singleton
assertThat(cacheProvider, sameInstance(injector.getInstance(CacheProvider.class)));
assertThat(cacheProvider, sameInstance(injector.getInstance(CacheProvider.class)));
Cache cache = cacheProvider.get();
// cache should be a singleton
assertThat(cache, sameInstance(cacheProvider.get()));
assertThat(cache, sameInstance(injector.getInstance(Cache.class)));
}
use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class CacheProviderTest method defaultImplementation.
@Test
public void defaultImplementation() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty(NinjaConstant.CACHE_IMPLEMENTATION, null);
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
CacheProvider cacheProvider = injector.getInstance(CacheProvider.class);
assertThat(cacheProvider.get(), instanceOf(CacheEhCacheImpl.class));
}
use of ninja.BaseAndClassicModules in project ninja by ninjaframework.
the class CacheProviderTest method configuredImplementation.
@Test
public void configuredImplementation() {
NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
ninjaProperties.setProperty(NinjaConstant.CACHE_IMPLEMENTATION, CacheMemcachedImpl.class.getName());
// just a dummy to test that loading works
ninjaProperties.setProperty(NinjaConstant.MEMCACHED_HOST, "127.0.0.1:1234");
Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
Provider<Cache> cacheProvider = injector.getProvider(Cache.class);
assertThat(cacheProvider.get(), instanceOf(CacheMemcachedImpl.class));
}
Aggregations