Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Test a bundle with injected TranslationService
Test a bundle with injected TranslationService [message #1837240] Mon, 25 January 2021 20:31 Go to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
Hi all,
I've a class which has a translation injected:

    @Inject
    @Translation
    protected Messages msg;


This class is part of a bundle which I want to test. Now, if I start my JUnit plugin test, I get an exception about a missing ResourceBundleProvider:

!STACK 0
org.eclipse.e4.core.di.InjectionException: Unable to process "TranslationObjectSupplier.provider": no actual value was found for the argument "ResourceBundleProvider".
	at org.eclipse.e4.core.internal.di.InjectorImpl.reportUnresolvedArgument(InjectorImpl.java:482)
	at org.eclipse.e4.core.internal.di.InjectorImpl.resolveRequestorArgs(InjectorImpl.java:473)
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:129)
	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:96)
	at org.eclipse.e4.core.internal.di.osgi.ProviderHelper.findProvider(ProviderHelper.java:83)
	at org.eclipse.e4.core.internal.di.InjectorImpl.findExtendedSupplier(InjectorImpl.java:633)
	at org.eclipse.e4.core.internal.di.InjectorImpl.resolveArgs(InjectorImpl.java:519)
	at org.eclipse.e4.core.internal.di.InjectorImpl.resolveRequestorArgs(InjectorImpl.java:463)
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:129)
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:405)
	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:332)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:202)
	at com.mypackage.preferences.DefaultValuesInitializer.initializeDefaultPreferences(DefaultValuesInitializer.java:85)


I've created a mocked EclipseContext, but I don't know how to advice the InjectionFactory to create such a ResourceBundleProvider. Are there any hints or examples how to do this?

Thanks in advance,
Ralf.
Re: Test a bundle with injected TranslationService [message #1837261 is a reply to message #1837240] Tue, 26 January 2021 11:40 Go to previous message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
ok, found it by myself :-)

Solution:
        ctx = EclipseContextFactory.getServiceContext(Activator.getContext());
        ContextInjectionFactory.setDefault(ctx);
Previous Topic:How to clear persisted state if application model has changed?
Next Topic:Eclipse 2020-12, RCP project export fails
Goto Forum:
  


Current Time: Fri Apr 26 06:00:15 GMT 2024

Powered by FUDForum. Page generated in 0.03006 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top