简体   繁体   English

上述方法调用缺少行为定义:用法是:expect(a.foo())。和XXXX()

[英]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. 假设iRequestcontrol是模拟对象,则需要重放它们。

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.

相关问题 java.lang.IllegalStateException:缺少前面方法调用 getMessage(“title”) 的行为定义 - java.lang.IllegalStateException: missing behavior definition for the preceding method call getMessage(“title”) java.lang.IllegalStateException:前面的方法调用getLast(...)的行为定义缺失 - java.lang.IllegalStateException: missing behavior definition for the preceding method call getLast(…) JUnit缺少STATIC方法调用的行为定义 - JUnit missing behavior definition for STATIC method call IllegalStateException:在同一方法中有两次调用时缺少行为定义 - IllegalStateException: missing behavior definition when having a double call in same method 即使定义了行为,“ IllegalStateException:在方法调用之前缺少行为定义” - 'IllegalStateException: missing behavior definition for preceeding method call' even though behavior is defined 构造函数调用中的另一个方法定义? - Another Method Definition in Constructor call? 在方法定义中使用@deprecated和参数类型更改 - Usage of @deprecated with parameter type change in method definition 方法调用中的构造函数定义 - constructor definition within a method call EasyMock期望使用参数的Collection类型调用方法 - EasyMock expect to call method with Collection type of parameter 尽管期望方法声明,EasyMock还是“意外方法调用” - EasyMock “Unexpected method call” despite of expect method declaration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM