use of javax.inject.Provider in project xwiki-platform by xwiki.
the class ComponentScriptServiceTest method configure.
@Before
public void configure() throws Exception {
this.dab = this.mocker.getInstance(DocumentAccessBridge.class);
this.contextComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "context");
Provider<ComponentManager> contextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(contextComponentManagerProvider.get()).thenReturn(this.contextComponentManager);
this.contextrootComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "context/root");
Provider<ComponentManager> contextrootComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context/root");
when(contextrootComponentManagerProvider.get()).thenReturn(this.contextrootComponentManager);
this.rootComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "root");
this.componentManagerManager = this.mocker.getInstance(ComponentManagerManager.class);
when(this.componentManagerManager.getComponentManager(null, false)).thenReturn(this.rootComponentManager);
this.execution = this.mocker.getInstance(Execution.class);
}
use of javax.inject.Provider in project xwiki-platform by xwiki.
the class LocalizationScriptServiceTest method setUp.
@Before
public void setUp() throws Exception {
componentManager = mock(ComponentManager.class);
Provider<ComponentManager> componentManagerProvider = mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(componentManager);
renderer = mock(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString());
when(componentManager.getInstance(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString())).thenReturn(renderer);
localizationContext = mocker.getInstance(LocalizationContext.class);
localizationManager = mocker.getInstance(LocalizationManager.class);
localizationScriptService = (LocalizationScriptService) mocker.getComponentUnderTest();
translation = mock(Translation.class);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
WikiPrinter printer = (WikiPrinter) invocation.getArguments()[1];
printer.print("print result");
return null;
}
}).when(renderer).render(eq(new WordBlock("message")), any(WikiPrinter.class));
when(translation.render(Locale.ROOT, ArrayUtils.EMPTY_OBJECT_ARRAY)).thenReturn(new WordBlock("message"));
when(localizationManager.getTranslation("key", Locale.ROOT)).thenReturn(translation);
when(localizationContext.getCurrentLocale()).thenReturn(Locale.ROOT);
environment = mocker.getInstance(Environment.class);
}
use of javax.inject.Provider in project xwiki-platform by xwiki.
the class ExportURLFactoryTest method setUp.
@Before
public void setUp() throws Exception {
this.urlFactory = new ExportURLFactory();
this.tmpDir = this.tmpDirRule.newFolder("xwikitests");
new File(this.tmpDir, "attachment").mkdir();
Provider<FilesystemExportContext> exportContextProvider = this.oldcoreRule.getMocker().getInstance(new DefaultParameterizedType(null, Provider.class, FilesystemExportContext.class));
this.exportContext = exportContextProvider.get();
doReturn("/xwiki").when(this.oldcoreRule.getSpyXWiki()).getWebAppPath(any(XWikiContext.class));
XWikiContext context = this.oldcoreRule.getXWikiContext();
XWikiRequest request = mock(XWikiRequest.class);
context.setRequest(request);
context.setURL(new URL("http://www.xwiki.org/"));
this.urlFactory.init(null, this.tmpDir, this.exportContext, context);
}
use of javax.inject.Provider in project eclipse.platform.runtime by eclipse.
the class InjectorImpl method getProviderType.
/**
* Returns null if not a provider
*/
private Class<?> getProviderType(Type type) {
if (!(type instanceof ParameterizedType))
return null;
Type rawType = ((ParameterizedType) type).getRawType();
if (!Provider.class.equals(rawType))
return null;
Type[] actualTypes = ((ParameterizedType) type).getActualTypeArguments();
if (actualTypes.length != 1)
return null;
if (!(actualTypes[0] instanceof Class<?>))
return null;
return (Class<?>) actualTypes[0];
}
use of javax.inject.Provider in project actframework by actframework.
the class GenieInjector method genie.
public Genie genie() {
if (null == genie) {
synchronized (this) {
if (null == genie) {
InjectListener listener = new GenieListener(this);
genie = Genie.create(listener, modules.toArray(new Object[modules.size()]));
for (Map.Entry<Class, DependencyInjectionBinder> entry : binders.entrySet()) {
genie.registerProvider(entry.getKey(), entry.getValue());
}
$.F2<Class, NamedProvider, Void> namedProviderRegister = new $.F2<Class, NamedProvider, Void>() {
@Override
public Void apply(Class aClass, NamedProvider namedProvider) throws NotAppliedException, Osgl.Break {
genie.registerNamedProvider(aClass, namedProvider);
return null;
}
};
$.F2<Class, Provider, Void> register = new $.F2<Class, Provider, Void>() {
@Override
public Void apply(Class aClass, Provider provider) throws NotAppliedException, Osgl.Break {
genie.registerProvider(aClass, provider);
return null;
}
};
genie.registerQualifiers(Bind.class, Param.class);
genie.registerScopeAlias(Singleton.class, Stateless.class);
genie.registerScopeAlias(Singleton.class, InheritedStateless.class);
genie.registerScopeAlias(StopInheritedScope.class, Stateful.class);
List<ActionMethodParamAnnotationHandler> list = Act.pluginManager().pluginList(ActionMethodParamAnnotationHandler.class);
for (ActionMethodParamAnnotationHandler h : list) {
Set<Class<? extends Annotation>> set = h.listenTo();
for (Class<? extends Annotation> c : set) {
genie.registerQualifiers(c);
}
}
ActProviders.registerBuiltInProviders(ActProviders.class, register);
ActProviders.registerBuiltInProviders(GenieProviders.class, register);
ActProviders.registerBuiltInNamedProviders(ActProviders.class, namedProviderRegister);
ActProviders.registerBuiltInNamedProviders(GenieProviders.class, namedProviderRegister);
for (Class<? extends Annotation> injectTag : injectTags) {
genie.registerInjectTag(injectTag);
}
genie.registerProvider(Genie.class, new Provider<Genie>() {
@Override
public Genie get() {
return genie;
}
});
}
}
}
return genie;
}
Aggregations