Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing behavior definition for the preceding method call:Usage is: expect(a.foo()).andXXX()

I'm New to Junit and am stuck on an issue. Any help would be really appreciated.

public void testGuaranteedRates() throws Exception
{

    ParticipantSummary summary = new ParticipantSummary();

    EasyMock.expect( iRequest.getPIN() ).andReturn( "1060720" );
    DateFormat dateFormat = new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss" );
    Date date = new Date();
    EasyMock.expect( iRequest.getTradeDate() ).andReturn( date ).anyTimes();
    EasyMock.expect( control.prepareServiceRequest( iRequest ) ).andReturn( rtvint );
    EasyMock.replay();
    ems.replayAll();
}

The method prepareServiceRequest() is as below

org.tiaa.transact.generated.jaxb.inquiry.RetrieveRetirementVintages prepareServiceRequest(InquiryRequest inquiryRequest)
{

    logger.debug( "prepareServiceRequest enter" );
    org.tiaa.transact.generated.jaxb.inquiry.ObjectFactory objectFactory = new org.tiaa.transact.generated.jaxb.inquiry.ObjectFactory();
    org.tiaa.transact.generated.jaxb.inquiry.RetrieveRetirementVintages retirementVintages = objectFactory.createRetrieveRetirementVintages();

    if( ( inquiryRequest ) != null )
    {
        if( ( inquiryRequest.getPIN() ) != null )
        {
            retirementVintages.setPIN( inquiryRequest.getPIN() );
        }
        if( ( inquiryRequest.getTradeDate() != null ) )
        {
            Calendar cal = new GregorianCalendar();
            //retirementVintages.setTradeDate( TPDateUtil.convertDatetoXMLGregorianCalendar( inquiryRequest.getTradeDate() ) );
            //retirementVintages.setTradeDate(( inquiryRequest.getTradeDate() );
        }
    }
    logger.debug( "prepareServiceRequest exit" );
    return retirementVintages;
}

When i tried to test it , I'm getting an error as below

java.lang.IllegalStateException: missing behavior definition for the preceding method call: InquiryRequest.getPIN()

Could anyone please let me know if anything is wrong here.

like image 691
Btla Deva Avatar asked Jun 14 '14 10:06

Btla Deva


2 Answers

Assuming that iRequest and control are mock objects, you need to replay them.

So, instead of:

EasyMock.replay();

try this:

EasyMock.replay(iRequest);
EasyMock.replay(control);
like image 102
mokarakaya Avatar answered Sep 18 '22 03:09

mokarakaya


You're calling inquiryRequest.getPin() twice in the method you are testing, but you only add the mock behaviour to one call. So, changing to:

 EasyMock.expect( iRequest.getPIN() ).andReturn( "1060720" ).anyTimes(); 

or changing the implementation to store the inquiryRequest.getPin() in a variable, should get you further.

like image 32
Louise Miller Avatar answered Sep 19 '22 03:09

Louise Miller