Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to substitute an SWT class
How to substitute an SWT class [message #487294] Tue, 22 September 2009 17:01 Go to next message
Eric Jain is currently offline Eric JainFriend
Messages: 266
Registered: July 2009
Senior Member
I need to replace the FileDialog class with a mock implementation for testing. What's the best way to go about that?

Tried e.g. providing the substitute implementation via a fragment, but that doesn't work as fragments are searched only after the bundle to which they are attached...
Re: How to substitute an SWT class [message #487410 is a reply to message #487294] Wed, 23 September 2009 07:10 Go to previous messageGo to next message
Michael Pellaton is currently offline Michael PellatonFriend
Messages: 289
Registered: July 2009
Senior Member
Hello

Have you tried providing your replacement class in a separate bundle and
putting the dependency to that extra bundle before the dependency of to
the bundle containing the original implementation?

Another idea is to use IoC instead of instantiating the class directly.
Peaberry is one example of IoC frameworks working within OSGi bundles.

HTH

Michael

Eric Jain wrote:
> I need to replace the FileDialog class with a mock implementation for
> testing. What's the best way to go about that?
>
> Tried e.g. providing the substitute implementation via a fragment, but
> that doesn't work as fragments are searched only after the bundle to
> which they are attached...
>
Re: How to substitute an SWT class [message #487627 is a reply to message #487410] Wed, 23 September 2009 19:47 Go to previous messageGo to next message
Eric Jain is currently offline Eric JainFriend
Messages: 266
Registered: July 2009
Senior Member
Michael Pellaton wrote on Wed, 23 September 2009 03:10
Have you tried providing your replacement class in a separate bundle and putting the dependency to that extra bundle before the dependency of to the bundle containing the original implementation?


Doesn't work. Perhaps because the bundle that contains the mock FileDialog implementation needs to import org.eclipse.swt.widgets itself (the constructor takes a Shell argument). So classloading ends up being delegated to the real bundle no matter what...

Quote:
Another idea is to use IoC instead of instantiating the class directly. Peaberry is one example of IoC frameworks working within OSGi bundles.


I'm already using IoC (Spring). Can't inject a FileDialog because 1. the constructor requires a reference to a Shell and 2. to switch between alternative implementations a common interface (or superclass) is required but there is no IFileDialog. I could inject a FileDialogFactory that returns an IFileDialogWrapper for which there are two implementations (one that delegates to the real FileDialog and one that doesn't). But I was hoping for a less convoluted solution...
Re: How to substitute an SWT class [message #487634 is a reply to message #487627] Wed, 23 September 2009 20:02 Go to previous message
Michael Pellaton is currently offline Michael PellatonFriend
Messages: 289
Registered: July 2009
Senior Member
I guess in that case you need to provide a patched bundle that
substitutes the original one for your tests.
Previous Topic:TreeViewer with Columns Redraw issue
Next Topic:I can't scale my images.
Goto Forum:
  


Current Time: Sun Dec 21 16:48:52 GMT 2014

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

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