Junit 参数不同!需要:实际调用具有不同的参数:

Junit 参数不同!需要:实际调用具有不同的参数:,junit,mockito,Junit,Mockito,服务级别: public void createManualEvaluationReductionChangeHistory(Long key, String accountId, RegisterReductionPerFunction registerReductionPerFunction, String languageCode, String comments, String pagRedFlag) { ProfessionalCustomerHistory professio

服务级别:

public void createManualEvaluationReductionChangeHistory(Long key, String accountId, RegisterReductionPerFunction registerReductionPerFunction, String languageCode, String comments, String pagRedFlag) {
    ProfessionalCustomerHistory professionalCustomerHistory = new ProfessionalCustomerHistory();
    professionalCustomerHistory.setDescription(comments);
    professionalCustomerHistory.setReductionCategory(registerReductionPerFunction.getReductionCategoryCode());
    professionalCustomerHistory.setReductionType(registerReductionPerFunction.getReductionTypeCode());
    professionalCustomerHistory.setValidityId(registerReductionPerFunction.getValidityId().longValue());
    professionalCustomerHistory.setReductionPercentage(reductionCategoryService.getReductionPercentage(languageCode,
            registerReductionPerFunction.getReductionCategoryCode(), registerReductionPerFunction.getReductionTypeCode()));
    professionalCustomerHistory.setTotalReduction(professionalCustomerHistory.getReductionPercentage());
    professionalCustomerHistory.setPagFixedReductionFlag(pagRedFlag);
    setCommonHistoryDetails(professionalCustomerHistory, Constants.NO, accountId, key, Constants.HISTORY_TYPE_REDUCTIONS);
    professionalCustomerHistoryDlService.create(professionalCustomerHistory);
}
Junit测试: @试验

当我测试它时,它会低于错误

参数不同!通缉: 实际调用有不同的参数:

但是我看到所有的参数都是一样的。是什么导致了这个问题


ProfessionalCustomerHistory是一个DB实体,我没有
equals
hashcode

假设只有第二次
验证失败,这就是问题所在

目前,您在测试和逻辑中创建了一个不同的
ProfessionalCustomerHistory
对象。它们可能具有相同的内容,但如果没有正确实现
equals
hashcode
方法,java中的默认实现只关心对象引用

如果您使用IDE,它可能有一些生成方法,允许您生成适当的
equals
hashCode
方法


如果您只想验证调用了正确的方法,而不关心确切的内容,则可以使用:

Mockito.verify(professionalCustomerHistoryDlService)
       .create(Mockito.any(ProfessionalCustomerHistory.class));

如果您不能或不想更改
ProfessionalCustomerHistory
类,您可以使用
ArgumentCaptor
然后比较不同的字段


ProfessionalCustomerHistory是一个DB实体,我没有
equals
hashcode

假设只有第二次
验证失败,这就是问题所在

目前,您在测试和逻辑中创建了一个不同的
ProfessionalCustomerHistory
对象。它们可能具有相同的内容,但如果没有正确实现
equals
hashcode
方法,java中的默认实现只关心对象引用

如果您使用IDE,它可能有一些生成方法,允许您生成适当的
equals
hashCode
方法


如果您只想验证调用了正确的方法,而不关心确切的内容,则可以使用:

Mockito.verify(professionalCustomerHistoryDlService)
       .create(Mockito.any(ProfessionalCustomerHistory.class));


如果您不能或不想更改
ProfessionalCustomerHistory
类,您可以使用
ArgumentCaptor
,然后比较不同的字段。

您能提供一个和您的
验证
调用失败的信息吗?
ProfessionalCustomerHistory
是否实现了正确的
equals
hashCode
方法?ProfessionalCustomerHistory是一个DB实体,我没有equals和hashCode。您可以提供一个和您的
验证
调用失败的信息吗?
ProfessionalCustomerHistory
是否实现了正确的
equals
hashCode
方法?ProfessionalCustomerHistory是一个DB实体,我没有equals和hashCode解析它。setHistoryDate(新日期());在上面的行中,日期设置为不同的毫秒。我刚刚实现了不包括date的equals哈希代码。它现在运转良好。谢谢你抽出时间来解决这个问题。setHistoryDate(新日期());在上面的行中,日期设置为不同的毫秒。我刚刚实现了不包括date的equals哈希代码。它现在运转良好。谢谢你抽出时间