Re: Ideal BDD using JMock
Thanks Steve and Nat for your interest.
There are several variations of this problem, but the an "easy
one" to describe is the use of TableCellRenderer (http://java.sun.com/
javase/6/docs/api/javax/swing/table/TableCellRenderer.html).
TableCellRenderer describes an interface that returns a properly
configured Component that a JTable uses to "paint" its cells.
Although the table cell renderer is specified as an interface, two
important collaborators, the component and the table, are not. From
a JMock point-of-view I want to ensure that appropriate query methods
are invoked on the JTable and appropriate configuration methods are
invoked on the Component. Notice that like all Swing components,
JTable and the relatively abstract Component, are not defined as
interfaces. Since the collaborators are declared as objects I am
forced to mock objects not interfaces.
Another example is a group of classes used to implement drag-and-
drop behavior on JComponents. The class TransferHandler (http://
java.sun.com/javase/6/docs/api/javax/swing/TransferHandler.html)
collaborates with a variety of objects that are not specified as
interfaces. Aside from JComponent, it uses the TransferSupport
class, a family of classes descended from DropLocation, and the
DataFlavor class. I have found it very difficult to test (specify)
the behavior drag-and-drop classes and I don't think that even what I
have accomplished is possible without mocking objects.
Again thanks for taking time to think about these problems. Any
insight is welcome.
On Sep 30, 2007, at 11:47 PM, Nat Pryce wrote:
> Which components are causing you trouble? Most Swing components
> interact with their model through a model interface and listener
> interfaces. What are you trying to mock out?
>
> --Nat
>
> On 27/09/2007, Tom Lanning <tom.lanning@...> wrote:
>> I do a lot of Swing-based development and routinely delegate the
>> behavior of Swing components using object injection. Unfortunately,
>> many of the Swing components specify (abstract) delegate objects
>> instead of interfaces. Therefore I routinely need to subclass
>> unalterable provided (abstract) classes. I know I can use JMock with
>> ClassImposteriser but I often end up mocking most of the base class'
>> behavior to verify my over-ridden methods.
>>
>> How do "interface-only purists" handle this problem? (I don't
>> mean any offense by the term "interface-only purist". I am becoming
>> one myself; hence the question.)
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
> http://xircles.codehaus.org/manage_email
>
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email