Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to create two new instances in my junit test

Reply
Thread Tools

how to create two new instances in my junit test

 
 
mike
Guest
Posts: n/a
 
      03-11-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Marshal.load does not create new instances? Ian Trudel Ruby 15 03-03-2009 10:20 PM
dicts,instances,containers, slotted instances, et cetera. ocschwar@gmail.com Python 8 01-29-2009 09:52 AM
list of class instances within a list of a class instances John Wohlbier Python 2 02-22-2004 08:41 AM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments