我試圖嘲弄Spring的MessageSource.getMessage
方法,但Mockito
它與無用信息抱怨,我使用:模擬Spring的MessageSource.getMessage方法
when(mockMessageSource.getMessage(anyString(), any(Object[].class), any(Locale.class)))
.thenReturn(anyString());
的錯誤信息是:
You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
when(mock.get(anyInt())).thenReturn(null);
doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
verify(mock).someMethod(contains("foo"))
Also, this error might show up because you use argument matchers with methods
that cannot be mocked Following methods *cannot* be stubbed/verified: final/private/equals()
/hashCode().
任何想法我做錯了什麼?
謝謝,工作。 – user86834