|
From: Anuj B. <AB...@La...> - 2004-02-05 12:05:02
|
Hi,
I have a class that I want to test but I'm having trouble creating
MockObjects for the classes referenced by my class. Consider the code below:
public class MyClassToTest
{
private ClassA a = ClassAFactory().instance().getGlobalClassA()
public MyClassToTest()
{ }
public myMethodToTest()
{
ClassB classBInst = new ClassB();
}
}
I want to mock ClassA and ClassB. ClassA internally accesses a database and
ClassB makes a JNDI lookup and both classes read configuration info from a
properties file. Actually most of my classes read config from properties
files using something like:
private static final Properties PROPERTIES =
PropertiesLoader.load(PROPERTIES_FILE_NAME);
This is another thing that I want to mock.
But how do I get the Mocks for ClassA and ClassB to MyClassToTest? The only
way to do it seems to me to pass instances of ClassA and ClassB to the class
constructor and to the method as parameters. But this changes the public
interface of my class and I don't want the clients of this class to be
burdened with the details of creating ClassA and ClassB. So how can I
effectively test MyClassToTest?
Thanks
Anuj
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
|