use of com.google.inject.Provides in project ratpack by ratpack.
the class TextTemplateModule method provideGroovyTemplateRenderingEngine.
@Provides
@Singleton
TextTemplateRenderingEngine provideGroovyTemplateRenderingEngine(ServerConfig serverConfig, ExecController execController, ByteBufAllocator bufferAllocator, Config config) {
String templatesPath = config.getTemplatesPath();
FileSystemBinding templateDir = serverConfig.getBaseDir().binding(templatesPath);
if (templateDir == null) {
throw new IllegalStateException("templatesPath '" + templatesPath + "' is outside the file system binding");
}
return new TextTemplateRenderingEngine(bufferAllocator, templateDir, serverConfig.isDevelopment(), config.staticallyCompile);
}
use of com.google.inject.Provides in project roboguice by roboguice.
the class DefaultRoboModule method providesAndroidId.
@Provides
@Named(Settings.Secure.ANDROID_ID)
public String providesAndroidId() {
String androidId = null;
final ContentResolver contentResolver = application.getContentResolver();
try {
androidId = Secure.getString(contentResolver, Secure.ANDROID_ID);
} catch (RuntimeException e) {
// ignore Stub! errors for Secure.getString() when mocking in test cases since there's no way to mock static methods
Log.e(DefaultRoboModule.class.getName(), "Impossible to get the android device Id. This may fail 'normally' when testing.", e);
}
if (!"".equals(androidId)) {
return androidId;
} else {
throw new RuntimeException("No Android Id.");
}
}
use of com.google.inject.Provides in project roboguice by roboguice.
the class FactoryModuleBuilderTest method testExplicitForwardingAssistedBindingCreatesNewObjects.
public void testExplicitForwardingAssistedBindingCreatesNewObjects() {
final Mustang providedMustang = new Mustang(Color.BLUE);
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().implement(Car.class, Mustang.class).build(ColoredCarFactory.class));
}
@Provides
Mustang provide() {
return providedMustang;
}
});
assertSame(providedMustang, injector.getInstance(Mustang.class));
ColoredCarFactory factory = injector.getInstance(ColoredCarFactory.class);
Mustang created = (Mustang) factory.create(Color.GREEN);
assertNotSame(providedMustang, created);
assertEquals(Color.BLUE, providedMustang.color);
assertEquals(Color.GREEN, created.color);
}
use of com.google.inject.Provides in project roboguice by roboguice.
the class ProviderMethodsTest method testVoidProviderMethods.
public void testVoidProviderMethods() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
}
@Provides
void provideFoo() {
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "1) Provider methods must return a value. Do not return void.", getClass().getName(), ".provideFoo(ProviderMethodsTest.java:");
}
}
use of com.google.inject.Provides in project ratpack by ratpack.
the class ThymeleafModule method provideTemplateResolver.
@Provides
@Singleton
ITemplateResolver provideTemplateResolver(ServerConfig serverConfig, Config config) {
IResourceResolver resourceResolver = new FileSystemBindingThymeleafResourceResolver(serverConfig.getBaseDir());
TemplateResolver templateResolver = new TemplateResolver();
templateResolver.setResourceResolver(resourceResolver);
templateResolver.setTemplateMode(getTemplatesModeSetting(config));
templateResolver.setPrefix(getTemplatesPrefixSetting(config));
templateResolver.setSuffix(getTemplatesSuffixSetting(config));
templateResolver.setCacheable(getCacheSizeSetting(config) > 0);
// Never use TTL expiration
templateResolver.setCacheTTLMs(null);
return templateResolver;
}
Aggregations