how to create two new instances in my junit test

Discussion in 'Java' started by mike, Mar 11, 2008.

  1. mike

    mike Guest

    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
    mike, Mar 11, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom Koenning
    Replies:
    0
    Views:
    1,423
    Tom Koenning
    Jul 28, 2003
  2. John Wohlbier
    Replies:
    2
    Views:
    356
    Josiah Carlson
    Feb 22, 2004
  3. Anarki
    Replies:
    1
    Views:
    282
    Alf P. Steinbach
    Aug 12, 2007
  4. Replies:
    8
    Views:
    444
    James Stroud
    Jan 29, 2009
  5. Ian Trudel
    Replies:
    15
    Views:
    245
    Eric Hodel
    Mar 3, 2009
Loading...

Share This Page