PowerMockito: получено исключение InvalidUseOfMatchersException при использовании насильственного статического метода соответствия
Когда я тестирую этот статический метод
public class SomeClass {
public static long someMethod(Map map, String string, Long l, Log log) {
...
}
}
с
import org.apache.commons.logging.Log;
@RunWith(PowerMockRunner.class)
//@PrepareForTest(SomeClass.class)
public class Tests {
@Test
public void test() {
...
PowerMockito.mockStatic(SomeClass.class);
Mockito.when(SomeClass.someMethod(anyMap(), anyString(), anyLong(), isA(Log.class))).thenReturn(1L);
...
}
}
я получилInvalidUseOfMatchersException
, Мои вопросы:
isA(Log.class)
returns null.
When I add the @PrepareForTest
annotation to the test class and run the test, the junit makes no response. Why?
РЕДАКТИРОВАТЬ
Я пытался не использовать сопоставления аргументов, и получил
org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles);
Also, this error might show up because:
you stub either of: final/private/equals()/hashCode() methods. Those methods cannot be stubbed/verified.
inside when() you don't call method on mock but on some other object.
at ...
Так что похоже из-заsomeMethod
сам. Естьsynchronized блок в методе. Мне интересно, может ли Powermockito высмеивать такой метод или нет.