Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Ready-made mock of IEclipsePreferences
Ready-made mock of IEclipsePreferences [message #1387104] Tue, 24 June 2014 07:25 Go to next message
Andreas Sewe is currently offline Andreas SeweFriend
Messages: 51
Registered: June 2013
E4's use of dependency injection makes unit testing much easier. Alas, mocking the IEclipsePreferences injected through @Preference is still cumbersome.

I thus wonder whether there exists a ready-made mock of said interface which, unlike EclipsePreferences and subclasses, never persists things to disk (and into a space shared among tests, no less).

It's certainly not hard to write such a mock (essentially a collection of nested Maps), but it's still time-consuming as the interface has ton of methods. I am thus wondering whether such a thing already exists somewhere.

Any pointers are much appreciated.
Re: Ready-made mock of IEclipsePreferences [message #1691571 is a reply to message #1387104] Wed, 08 April 2015 08:56 Go to previous message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 151
Registered: September 2014
Location: Brussels - Belgium
Senior Member

Nobody has an answer for this question ? I also have to mock an instance of IEclipsePreferences for a unit test to work. I merely need to retrieve an instance of a single String :
@Inject @Preference(nodePath="", value="user")
String User ;

And in the unit test, using EasyMock to prepare the mock object :
IEclipsePreferences prefsRootMock = createMock(IEclipsePreferences.class);
IEclipsePreferences prefsMock = createMock(IEclipsePreferences.class);
expect(prefsRootMock.node("")).andReturn(prefsMock) ;
expect(prefsMock.get("user", "BENOIT")).andReturn("BENOIT") ;

But now, how do I place this mock object in the context ?Coding simply "context.set(IEclipsePreferences.class, prefsMock);" will not do.

Do we have to provide a custom ExtendedObjectSupplier for IEclipsePreferences in such a case, isn't there something easier ?

Thomas Elskens
Previous Topic:Letting a custom class inject services
Next Topic:Eclipse e4 Maven Tycho InjectionException
Goto Forum:

Current Time: Tue Oct 06 08:33:41 GMT 2015

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

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