|
Re: Testing classes with injected IEclipsePreferences [message #1802427 is a reply to message #1802412] |
Fri, 08 February 2019 16:39 |
Eclipse User |
|
|
|
Hi Ralf.
There are a few issues here. First, your Mockito `when` clause is missing a `do` action. You probably want something like (totally untested):
Mockito.when(preferences.getInt("foo", Mockito.anyInt())).doReturn(Integer.valueOf(4)));
But IIRC (and code in org.eclipse.e4.core.internal.di.InjectorImpl seems to confirm) the injector will see the `@Preference` annotation and only consult the corresponding preferences object supplier.
One way to work around this is to have a setter method that will receive the injected preference value, and call it manually in your test.
@Inject
@Preference(nodePath="/instance/certainlocation")
@VisibleForTests /* guava annotation */
void setEclipsePreferences(IEclipsePreferences eclipsePrefs) {
someValue = eclipsePrefs.getInt("foo", Integer.valueOf(1));
}
HTH
|
|
|
|
Powered by
FUDForum. Page generated in 0.04932 seconds