【问题标题】:Unexpected method call in EasyMockEasyMock 中的意外方法调用
【发布时间】:2019-10-29 17:52:06
【问题描述】:

我有一段代码:

if (wfStepExDetails.isPresent()) {
   this.postInterruptActionsExecutor.takeActionAfterWFInterrupted(wfStepExDetails.get(), this.pAccId, interrupts, this.workflowStepDefinition);
} 

内部测试类:

@Test
public void testHandlePostInterruptActions() {
postInterruptActionsExecutor.takeActionAfterWFInterrupted(getWfStepExecutionDetails().get(0), pAccId, interrupt, wfStep);
    expectLastCall();
    replay(postInterruptActionsExecutor);
    orchestrator.handlePostInterruptActions(interrupt);
    EasyMock.verify(postInterruptActionsExecutor, orcDepProvider, pwaDAO, pdh);
}

由于参数不匹配,测试失败:

[junit]   Unexpected method call PostInterruptActionsExecutor.takeActionAfterWFInterrupted(WorkflowStepExecutionDetails(wfStepName=null, wfId=4c46f286-c368-49e7-a7db-30c39d72d1b8, planId=null, resultBranch=null, wfStepStatus=null, creationTime=null, workflowStepRequirements=null, attemptCount=null, parentWfStepId=null, wfStepType=null, wfStepDependencyResponseId=null), "81bd1b7e-7433-4116-bf46-52318b493e93", [com.amazon.verificationorchestration.plan.Interrupt@9e781b8e], com.amazon.verificationorchestration.plan.InitiateTokenVerificationWorkflowStep@860a7ec9):
[junit]   PostInterruptActionsExecutor.takeActionAfterWFInterrupted(WorkflowStepExecutionDetails(wfStepName=null, wfId=4c46f286-c368-49e7-a7db-30c39d72d1b8, planId=null, resultBranch=null, wfStepStatus=null, creationTime=null, workflowStepRequirements=null, attemptCount=null, parentWfStepId=null, wfStepType=null, wfStepDependencyResponseId=null), "81bd1b7e-7433-4116-bf46-52318b493e93", [com.amazon.verificationorchestration.plan.Interrupt@9e781b8e], com.amazon.verificationorchestration.plan.InitiateTokenVerificationWorkflowStep@860a7ec9): expected: 1, actual: 0

即使预期调用和实际调用包含相同的参数,测试仍然失败。我在这里有什么遗漏吗?

【问题讨论】:

  • 您的错误消息实际上是在说什么,通过您的模拟,您表明您希望使用这些参数进行特定调用,但在测试期间实际上并未进行该调用。
  • 其实恰恰相反。打了一个意外的电话。

标签: java easymock


【解决方案1】:

我认为您使用的是稍旧的 EasyMock 版本,否则信息会更清晰。是哪个版本的?

EasyMock 使用eq() 作为默认匹配器。在这里,我怀疑 WorkflowStepExecutionDetails 的 toString() 使它们看起来相同,但 Object.equals 可能没有被覆盖。由于它们是两个不同的实例,因此它们不等于 Object.equals(即 ==)。

【讨论】:

    猜你喜欢
    • 2017-03-06
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 2012-05-22
    • 1970-01-01
    相关资源
    最近更新 更多