Java Mockito-MatcherException的无效使用

Java Mockito-MatcherException的无效使用,java,exception,mockito,Java,Exception,Mockito,我试图模拟一些类,但以下代码给了我一些问题: @RunWith(MockitoJUnitRunner.class) public class CalendarServiceTest { private Calendar calendar; @Mock MyClient myClient; @InjectMocks CalendarService calendarService; @Before public void initMoc

我试图模拟一些类,但以下代码给了我一些问题:

@RunWith(MockitoJUnitRunner.class)
public class CalendarServiceTest {

    private Calendar calendar;

    @Mock
    MyClient myClient;

    @InjectMocks
    CalendarService calendarService;

    @Before
    public void initMocks() {
        List<Proposal> proposals = new ArrayList<>();
        calendar = org.mockito.Mockito.mock(Calendar.class);
        Proposal proposal = new Proposal();
        proposal.setAmount((float) 109.5);
        proposals.add(proposal);
        calendar.getProposal().addAll(proposals);
        when(calendar.getProposal()).thenReturn(proposals);
    }

    @Test
    public void getCalendar(){
        initMocks();
        when(myClient.getCalendar(anyString(), anyString(), anyString(), new LocalDate(), new LocalDate(), new LocalDate(), new LocalDate(), anyString(), anyString(), anyString())).thenReturn(calendar); // <<== exception here
        Assert.assertNotNull(calendar);
    }
}

如错误所述,如果使用匹配器,则所有参数都需要使用匹配器,例如:

eq(new LocalDate())
或者,如果您不关心
LocalDate
s的值,请使用:

any(LocalDate.class)
any(LocalDate.class)