为什么我的ArgumentMatcher从未被调用过?

时间:2016-10-18 09:57:46

标签: java unit-testing intellij-idea mocking mockito

我尝试运行最简单的测试

使用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;
            }
        }

然而我的匹配器从未被调用过。

我错过了什么?

2 个答案:

答案 0 :(得分:0)

试试这个:

public boolean matches(String argument)

答案 1 :(得分:0)

我的问题是intellij超过"verify"方法的断点阻止了ArgumentMatcher内的断点停止。