Jason,
I don't know that much about reflection (time to learn?) - will
something like this work?:
// the class we want to test
IControlA controlA = new ControlAImpl();
// controlA's reference to IControlB that we want to mock
IControlB mockControlB = new MockControlBImpl();
Field field = controlA.getClass().getDeclaredField("controlB");
field.setAccessible(true);
field.set(controlA, mockControlB);
Many thanks,
Chris
On 30 Aug 2007, at 16:47, jason knox wrote:
Hi Chris --
One option that I've taken is to test the implementation of
ControlA directly. With this approach one can either use A.) a
protected setter and set the ControlB mock in the testclass
(provided they share the same directory structure) or B.) simply
set the control using reflection either explicitly or with a
private setter. Although I've most recently used option B.) our
team has come to the conclusion that option A.) is sufficient.
Hope this helps,
Jason.
-----Original Message-----
From: Christopher Snow [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 30, 2007 6:46 AM
To: [email protected]
Subject: testing controls
I have a control (ControlA) that has a reference to another
control (ControlB).
I would like to test ControlA using a mock of ControlB. I have
created a
setting to set ControlA's reference to ControlB from the test
case. However to
do this, I need to put the setter in the business interface. Is
there a better
way?
Thanks in advance ...
@ControlImplementation
public class ControlAImpl ... {
@Control
private ControlB controlB;
public void setControlB( ControlB control ) {
controlB = control
}
// business logic
}
@ControlInterface
public interface ControlA ...{
// bad idea? non business method in business interface
public void setControlB( ControlB control );
}
public class ControlAImplTest extends ControlTestCase {
@Control
private ControlA controlA;
public void testX() {
ControlB mockControlB = // create mock of ControlB
controlA.setControlB( mockControlB )
// test business logic here
}
}
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
---------------------------------
Choose the right car based on your needs. Check out Yahoo! Autos
new Car Finder tool.
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.