我正在尝试模拟一个SimpleDateFormat对象,但 Mockito 说我的参数数量错误。代码:
SimpleDateFormat spyDateFormat = spy(new SimpleDateFormat(DateFormatManager.MAIN_ACTIVITY_TITLE_FORMAT));
// exception points to below line
when(spyDateFormat.format(any(Date.class))).thenReturn("foo format");
Run Code Online (Sandbox Code Playgroud)
例外:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
3 matchers expected, 1 recorded:
Run Code Online (Sandbox Code Playgroud)
该方法存在于其父 DateFormat 中:
http://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html#format(java.util.Date)
尝试切换到 DateFormat,使用spy. 没有运气。