Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   how to create two new instances in my junit test (http://www.velocityreviews.com/forums/t597646-how-to-create-two-new-instances-in-my-junit-test.html)

mike 03-11-2008 06:51 AM

how to create two new instances in my junit test
 
Hi,

I am using junit 4 and jmock 2.

In my unit under test I had the following code:

public class CommandHandler{
........
context.setAPartyCallLeg(new CallLeg(sipFactory, request,
request.getFrom()));
........
}


We changed that to using a factory method:

public class CommandHandler{
......
ICallLeg callLeg = createCallLeg(sipFactory, request,
request.getFrom());
context.setAPartyCallLeg(callLeg);
....

protected ICallLeg createCallLeg(SipFactory sipFactory,
SipServletRequest request, Address address) throws
IOException,ServletException {
return new CallLeg(sipFactory, request, address);
}

}

My unit test has the following code for testing:

public class MyTest{

CallLeg mockCallLeg = context.mock(ICallLeg.class);

public void testdoInvite() throws ServletException,IOException {
CommandHandler ch = new CommandHandler(mockSipFactory) {
protected ICallLeg createCallLeg(SipFactory sipFactory,
SipServletRequest request, Address address) {
return mockCallLeg;
}};
}

}

My problem is that in my unit under test I have another instance of
CallLeg being created. So how can I make another instance to be used
in my test?

cheers,

//mike


All times are GMT. The time now is 06:59 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.