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.
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With