When I test this static method
public class SomeClass { public static long someMethod(Map map, String string, Long l, Log log) { ... } }
from
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); ... } }
I got an InvalidUseOfMatchersException
. My questions:
- Why did I get this exception when all arguments use matches? How to solve it? I debugged it, found that
isA(Log.class)
returns null. - When I add the
@PrepareForTest
annotation to the test class and run the test, junit is not responding. Why?
EDIT
I tried not to use argument arguments and got
org.mockito.exceptions.misusing.MissingMethodInvocationException: when () requires an argument, which should be a "method call to the layout". For example: when (mock.getArticles ()) thenReturn (articles) ;.
In addition, this error may appear because:
you drown either of the following: final / private / equals () / hashCode (). These methods cannot be erased / verified.
inside when () you do not call the method on mock, but on some other object.
at ...
So it seems, because of someMethod
itself. The method has a synchronized block. I am wondering if Powermockito can mock this method or not.
source share