Junit 自定义hamcrest匹配器成功,但测试失败

Junit 自定义hamcrest匹配器成功,但测试失败,junit,java-8,mockito,matcher,hamcrest,Junit,Java 8,Mockito,Matcher,Hamcrest,我有一个自定义匹配器: public class CofmanStringMatcher extends TypeSafeMatcher<String> { private List<String> options; private CofmanStringMatcher(final List<String> options) { this.options = Lists.newArrayList(options);

我有一个自定义匹配器:

public class CofmanStringMatcher extends TypeSafeMatcher<String> {
    private List<String> options;


    private CofmanStringMatcher(final List<String> options) {
        this.options = Lists.newArrayList(options);
    }

    @Override
    protected boolean matchesSafely(final String sentResult) {
        return options.stream().anyMatch(option -> option.equals(sentResult));
    }


    public static CofmanStringMatcher isCofmanStringOnOfTheStrings(List<String> options) {
        return new CofmanStringMatcher(options);
    }

    @Override
    public void describeTo(final Description description) {
        System.out.println("in describeTo");
//        description.appendText("expected to be equal to of the list: "+options);
    }
}
我得到这个错误:

Comparison Failure:  <Click to see difference>

Argument(s) are different! Wanted:
cofmanService.updateStgConfigAfterSimulation(
    ,
    "add partner request id = 1234"
);
-> at com.waze.sdkService.services.pubsub.callback.RequestToCofmanSenderTest.localAndRtValidationSucceeds_deployCofmanStg(RequestToCofmanSenderTest.java:131)
Actual invocation has different arguments:
cofmanService.updateStgConfigAfterSimulation(
    "some text"
);
比较失败:
参数不同!通缉:
cofmanService.updateStgConfigAfterSimulation(
,
“添加合作伙伴请求id=1234”
);
->在com.waze.sdkService.services.pubsub.callback.RequestToOfMansenderTest.localAndRtValidationSucceeds_deployCofmanStg(RequestTofMansenderTest.java:131)上
实际调用有不同的参数:
cofmanService.updateStgConfigAfterSimulation(
“一些文本”
);
即使方法
updateStgConfigAfterSimulation
调用与列表元素中的第1个参数匹配的第1个参数,测试仍然失败

我正在使用
mockito1.10
hamcrest 1.3

这是该方法的签名


void updatesgconfigaftersimulation(String conditionsMap,String CommitsMg)引发异常

你能发布你的updatesgconfigaftersimulation方法吗?你的代码无法编译,该
参数接受一个
参数匹配器
,但你传递了一个
匹配器
。您是如何得到这样一个错误的?快速浏览一下您的
updatesgconfigaftersimulation
,您希望使用两个参数调用您的
,一个用于匹配器,另一个等于
常量。addcommitsg+一些请求ID
-但是您的方法仅使用一个参数调用-
一些文本。正如@Plog所建议的,请您在Simulation之后添加
updateStgConfigAfterSimulation
实现(可能需要一个字符串vararg?!)。@holi java没有指定版本,但可能他使用的是mockito2和Import,它需要一个hamcrest匹配器作为参数,因此该方法需要两个参数,但是调用失败消息只描述了一个奇怪的消息,可能是之前运行的输入错误或复制粘贴?!。我根据您的描述创建了一个本地测试,我可以很容易地让它通过,因此在这一点上,我认为需要一个测试来进行更仔细的检查或调试。您可以发布您的UpdatesgConfigAfterSimulation方法吗?您的代码无法编译,
参数接受
参数匹配器,但您通过了
匹配器。您是如何得到这样一个错误的?快速浏览一下您的
updatesgconfigaftersimulation
,您希望使用两个参数调用您的
,一个用于匹配器,另一个等于
常量。addcommitsg+一些请求ID
-但是您的方法仅使用一个参数调用-
一些文本。正如@Plog所建议的,请您在Simulation之后添加
updateStgConfigAfterSimulation
实现(可能需要一个字符串vararg?!)。@holi java没有指定版本,但可能他使用的是mockito2和Import,它需要一个hamcrest匹配器作为参数,因此该方法需要两个参数,但是调用失败消息只描述了一个奇怪的消息,可能是之前运行的输入错误或复制粘贴?!。我根据您的描述创建了一个本地测试,我可以很容易地使它通过,所以在这一点上,我觉得需要一个测试来进行更仔细的检查或调试。
Comparison Failure:  <Click to see difference>

Argument(s) are different! Wanted:
cofmanService.updateStgConfigAfterSimulation(
    ,
    "add partner request id = 1234"
);
-> at com.waze.sdkService.services.pubsub.callback.RequestToCofmanSenderTest.localAndRtValidationSucceeds_deployCofmanStg(RequestToCofmanSenderTest.java:131)
Actual invocation has different arguments:
cofmanService.updateStgConfigAfterSimulation(
    "some text"
);