Just pass in null for the panel parameter.
LayerRenderer lr = new LayerRenderer(null, null);
will return you a LayerRenderer object.


On 5/3/07, Sunburned Surveyor <[EMAIL PROTECTED]> wrote:

I'm trying to cook up a mock object for the LayerViewPanel class, which
will allow me to test elements of OpenJUMP's rendering system. However, I've
never had a lot of experience writing or using mock objects in unit testing,
and I have run into a couple of challenges. I was hoping I could explain my
situation and then get some help from the other developers.

I'm trying to test one of my RendererFactoryTool implementations, which
basically creates an instance of
com.vividsolutions.workbench.ui.renderer.LayerRenderer wjhen asked by the
RendererFactory. (This is done whenever an instance of
com.vividsolutions.workbench.model.Layer needs to be rendered for the
first time.) The LayerRenderer class requires a LayerViewPanel as one of the
arguments to its constructor. (This makes sense. The renderer needs a
reference to an object that it can paint on.)

When I am unit testing I don't want to pass the LayerRenderer constructor
a real LayerViewPanel, because that means that I have to create all types of
other unnecessary objects for my test. I just want to pass the constructor a
"dumb" LayerViewPanel and see if it gives me back a Renderer. I need a mock
object.

I thought I could do this by simply extending the LayerViewPanel class and
overriding the methods. This presents two problems:

[1] To have a truly dumb object for my test I'd also need to override the
methods of all the classes in the LayerViewPanel's inheritance tree. (Do you
know how many methods JComponent has???) :[

[2] I still have to make a call to super() in the constructor of my mock
object class, which means I've come full circle to the original problem I
was trying to avoid: Calling the constructor of the LayerViewPanel.

the LayerViewPanel class ins't an interface, so I can't just implement its
methods in my mock object class. What is the solution? Do I set up an
alternate com.vividsolutions.workbench.ui package in my unit testing
project in Eclipse and provide my own version of the LayerViewPanel class?
(I think this will work if I don't make any other imports in my project from
which I want to use the real com.vividsolutions.workbench.ui package.)

Is there another, more elegant solution?

Thanks in advance for the help. I'm really scratching my head on this one.

The Sunburned Surveyor

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to