本文整理汇总了Java中com.google.inject.binder.AnnotatedBindingBuilder.toInstance方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedBindingBuilder.toInstance方法的具体用法?Java AnnotatedBindingBuilder.toInstance怎么用?Java AnnotatedBindingBuilder.toInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.inject.binder.AnnotatedBindingBuilder
的用法示例。
在下文中一共展示了AnnotatedBindingBuilder.toInstance方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bind
import com.google.inject.binder.AnnotatedBindingBuilder; //导入方法依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
private Block bind(final String name, final Class type) {
return unit -> {
Object value = unit.get(type);
AnnotatedBindingBuilder abbce = unit.mock(AnnotatedBindingBuilder.class);
abbce.toInstance(value);
Binder binder = unit.get(Binder.class);
if (name == null) {
expect(binder.bind(Key.get(type))).andReturn(abbce);
} else {
expect(binder.bind(Key.get(type, Names.named(name)))).andReturn(abbce);
}
};
}
示例2: sessionStore
import com.google.inject.binder.AnnotatedBindingBuilder; //导入方法依赖的package包/类
private MockUnit.Block sessionStore(SessionStore<WebContext> ss) {
return unit -> {
org.pac4j.core.config.Config config = unit.get(org.pac4j.core.config.Config.class);
expect(config.getSessionStore()).andReturn(ss);
if (ss != null) {
config.setSessionStore(ss);
}
AnnotatedBindingBuilder aab = unit.mock(AnnotatedBindingBuilder.class);
if (ss == null) {
expect(aab.to(Pac4jSessionStore.class)).andReturn(aab);
expect(aab.to(Pac4jSessionStore.class)).andReturn(aab);
} else {
aab.toInstance(ss);
aab.toInstance(ss);
}
Binder binder = unit.get(Binder.class);
expect(binder.bind(SSTORE)).andReturn(aab);
expect(binder.bind(SessionStore.class)).andReturn(aab);
};
}
示例3: serviceKey
import com.google.inject.binder.AnnotatedBindingBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Block serviceKey(final String db) {
return unit -> {
Env env = unit.get(Env.class);
ServiceKey skey = new Env.ServiceKey();
expect(env.serviceKey()).andReturn(skey).times(2);
AnnotatedBindingBuilder<DataSource> binding = unit.mock(AnnotatedBindingBuilder.class);
binding.toInstance(unit.get(HikariDataSource.class));
binding.toInstance(unit.get(HikariDataSource.class));
Binder binder = unit.get(Binder.class);
expect(binder.bind(Key.get(DataSource.class))).andReturn(binding);
expect(binder.bind(Key.get(DataSource.class, Names.named(db)))).andReturn(binding);
};
}
示例4: serviceKey
import com.google.inject.binder.AnnotatedBindingBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Block serviceKey(final String db, String dbtype) {
return unit -> {
Env env = unit.get(Env.class);
expect(env.serviceKey()).andReturn(new Env.ServiceKey());
AnnotatedBindingBuilder<DataSource> binding = unit.mock(AnnotatedBindingBuilder.class);
binding.toInstance(unit.get(HikariDataSource.class));
binding.toInstance(unit.get(HikariDataSource.class));
Binder binder = unit.get(Binder.class);
expect(binder.bind(Key.get(DataSource.class))).andReturn(binding);
expect(binder.bind(Key.get(DataSource.class, Names.named(db)))).andReturn(binding);
expect(env.set(Key.get(DataSource.class), unit.get(HikariDataSource.class))).andReturn(env);
expect(env.set(Key.get(DataSource.class, Names.named(db)), unit.get(HikariDataSource.class)))
.andReturn(env);
if (dbtype != null) {
expect(env.set(Key.get(String.class, Names.named(db + ".dbtype")), dbtype)).andReturn(env);
}
};
}
示例5: createModule
import com.google.inject.binder.AnnotatedBindingBuilder; //导入方法依赖的package包/类
protected com.google.inject.Module createModule(final Grammar grammar) {
final com.google.inject.Module _function = (Binder binder) -> {
binder.<Grammar>bind(Grammar.class).toInstance(grammar);
binder.<Naming>bind(Naming.class).toInstance(this.getNaming());
AnnotatedBindingBuilder<IGrammarAccess> _bind = binder.<IGrammarAccess>bind(IGrammarAccess.class);
Xtend2GeneratorFragment.GenericGrammarAccess _genericGrammarAccess = new Xtend2GeneratorFragment.GenericGrammarAccess(grammar);
_bind.toInstance(_genericGrammarAccess);
this.addLocalBindings(binder);
};
return _function;
}
示例6: configureIEncodingProvider
import com.google.inject.binder.AnnotatedBindingBuilder; //导入方法依赖的package包/类
public void configureIEncodingProvider(final Binder binder) {
AnnotatedBindingBuilder<IEncodingProvider> _bind = binder.<IEncodingProvider>bind(IEncodingProvider.class);
IEncodingProvider.Runtime _runtime = new IEncodingProvider.Runtime();
final Procedure1<IEncodingProvider.Runtime> _function = (IEncodingProvider.Runtime it) -> {
it.setDefaultEncoding(this.code.getEncoding());
};
IEncodingProvider.Runtime _doubleArrow = ObjectExtensions.<IEncodingProvider.Runtime>operator_doubleArrow(_runtime, _function);
_bind.toInstance(_doubleArrow);
}
示例7: configure
import com.google.inject.binder.AnnotatedBindingBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void configure() {
Binder binder = createNiceMock(Binder.class);
AnnotatedBindingBuilder<LangFactory> bindLangFactory = createMock(AnnotatedBindingBuilder.class);
AnnotatedBindingBuilder<ILinkingDiagnosticMessageProvider.Extended> bindLinkingDMP = createMock(AnnotatedBindingBuilder.class);
AnnotatedBindingBuilder<ILaunchManager> bindLaunchManager = createMock(AnnotatedBindingBuilder.class);
final ILaunchManager launchManager = createMock(ILaunchManager.class);
final AnnotatedBindingBuilder<Console> bindConsole = createMock(AnnotatedBindingBuilder.class);
final Console console = createMock(Console.class);
expect(binder.bind(LangFactory.class)).andReturn(bindLangFactory);
expect(binder.bind(ILinkingDiagnosticMessageProvider.Extended.class)).andReturn(bindLinkingDMP);
expect(binder.bind(ILaunchManager.class)).andReturn(bindLaunchManager);
expect(binder.bind(Console.class)).andReturn(bindConsole);
bindLangFactory.toInstance(LangFactory.eINSTANCE);
expect(bindLinkingDMP.to(Antlr4MissingReferenceMessageProvider.class)).andReturn(null);
bindLaunchManager.toInstance(launchManager);
bindConsole.toInstance(console);
Object[] mocks = {binder, bindLangFactory, bindLinkingDMP, launchManager, console };
replay(mocks);
new Antlr4RuntimeModule() {
@Override
protected ILaunchManager getLaunchManager() {
return launchManager;
}
@Override
protected Console getConsole() {
return console;
}
}.configure(binder);
verify(mocks);
}
示例8: consulIsBuiltAndBound
import com.google.inject.binder.AnnotatedBindingBuilder; //导入方法依赖的package包/类
private MockUnit.Block consulIsBuiltAndBound(String name, Config config) {
return unit -> {
Config consulConfig = consulConfigWithFallback(name, config);
Consul consul = unit.get(Consul.class);
Consul.Builder consulBuilder = unit.mock(Consul.Builder.class);
expect(consulBuilder.withUrl(consulConfig.getString("url"))).andReturn(consulBuilder);
expect(consulBuilder.build()).andReturn(consul);
unit.mockStatic(Consul.class);
expect(Consul.builder()).andReturn(consulBuilder);
Env env = unit.get(Env.class);
expect(env.onStop(isA(Throwing.Runnable.class))).andReturn(env);
//noinspection unchecked
AnnotatedBindingBuilder<Consul> consulABB = unit.mock(AnnotatedBindingBuilder.class);
consulABB.toInstance(consul);
consulABB.toInstance(consul);
Binder binder = unit.get(Binder.class);
expect(binder.bind(Key.get(Consul.class))).andReturn(consulABB);
expect(binder.bind(Key.get(Consul.class, Names.named(name)))).andReturn(consulABB);
};
}
示例9: configureExecutorService
import com.google.inject.binder.AnnotatedBindingBuilder; //导入方法依赖的package包/类
public void configureExecutorService(final Binder binder) {
AnnotatedBindingBuilder<ExecutorService> _bind = binder.<ExecutorService>bind(ExecutorService.class);
_bind.toInstance(this.executorService);
}
示例10: jade
import com.google.inject.binder.AnnotatedBindingBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Block jade(final String suffix, final boolean caching, final boolean prettyPrint) {
return unit -> {
JadeConfiguration jadeConfiguration = unit.mockConstructor(JadeConfiguration.class);
jadeConfiguration.setCaching(caching);
jadeConfiguration.setPrettyPrint(prettyPrint);
Env env = unit.get(Env.class);
Map<String, Object> sharedVariables = unit.constructor(HashMap.class)
.build(2);
expect(sharedVariables.put(eq( "env"), eq(env))).andReturn(null);
expect(sharedVariables.put(eq( "xss"), isA(XssHelper.class))).andReturn(null);
jadeConfiguration.setSharedVariables(sharedVariables);
ClasspathTemplateLoader classpathTemplateLoader = unit
.mockConstructor(ClasspathTemplateLoader.class);
jadeConfiguration.setTemplateLoader(classpathTemplateLoader);
expect(jadeConfiguration.getTemplateLoader()).andReturn(classpathTemplateLoader);
Jade.IOTemplateLoader safetl = unit
.constructor(Jade.IOTemplateLoader.class)
.build(classpathTemplateLoader);
jadeConfiguration.setTemplateLoader(safetl);
AnnotatedBindingBuilder<JadeConfiguration> configBB = unit
.mock(AnnotatedBindingBuilder.class);
configBB.toInstance(jadeConfiguration);
Binder binder = unit.get(Binder.class);
expect(binder.bind(JadeConfiguration.class)).andReturn(configBB);
Engine engine = unit.mockConstructor(
Engine.class, new Class[]{JadeConfiguration.class, String.class },
jadeConfiguration, suffix);
LinkedBindingBuilder<Renderer> ffLBB = unit.mock(LinkedBindingBuilder.class);
ffLBB.toInstance(engine);
Multibinder<Renderer> formatter = unit.mock(Multibinder.class);
expect(formatter.addBinding()).andReturn(ffLBB);
unit.mockStatic(Multibinder.class);
expect(Multibinder.newSetBinder(binder, Renderer.class)).andReturn(formatter);
};
}