我试着运行最简单的测试
与mockito参数匹配器:
import org.mockito.ArgumentMatcher;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.*;
@Test
public void test123() throws Exception {
MyClient cofmanClient = mock(MyClient.class);
cofmanClient.holy("zigzag");
MyClient verify = verify(cofmanClient);
verify.holy(argThat(new MyMatcher()));
}
private static class MyClient {
public void holy(String s) {
System.out.println("Called with: " + s);
}
}
private static class MyMatcher extends ArgumentMatcher<String> {
@Override
public boolean matches(Object argument) {
System.out.println("Deadly cow! s=" + argument.getClass().getName());
return argument.getClass() == Class.class;
}
}
然而我的匹配器从未被调用。
我错过了什么?
try this:
public boolean matches(String argument)
我的问题是,在"verify"
方法中,intelllij的断点阻塞在ArgumentMatcher
中的断点上停止。