Mer*_*cer 1 java exception mockito
我正在尝试模拟一些类,但以下代码给了我一些问题:
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
运行这个让我:
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));
Run Code Online (Sandbox Code Playgroud)
正如错误所说,如果你使用匹配器,那么所有的参数都需要使用它们,例如:
eq(new LocalDate())
Run Code Online (Sandbox Code Playgroud)
或者,如果您不关心LocalDate使用的价值:
any(LocalDate.class)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1202 次 |
| 最近记录: |