[英]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. 我是Junit的新手而且我遇到了问题。 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 prepareServiceRequest()方法如下
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. 假设
iRequest
和control
是模拟对象,则需要重放它们。
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. 您正在测试的方法中调用
inquiryRequest.getPin()
两次,但您只将模拟行为添加到一个调用中。 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. 或者更改实现以将
inquiryRequest.getPin()
存储在变量中,应该会让你更进一步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.