MissingMethodInvocationException when mocking a org.apache.log4j.Level class
java, mockito
Solution
Did you check the `MissingMethodInvocationException` exception message ?
It says :
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:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
2. inside when() you don't call method on mock but on some other object.
3. the parent of the mocked class is not public.
It is a limitation of the mock engine.
Either the class `Level` is final (clearly not as I remember extending this class) or the `getSyslogEquivalent` is final (best guess).
So you should either revise your design or test design or maybe try Powermock, which offers final class/method mocking.
Hope that helps
Problem
The following code results in org.mockito.exceptions.misusing.MissingMethodInvocationException: ``` Level level = mock(Level.class); IOException ioException = new IOException("test"); when(level.getSyslogEquivalent()).thenThrow(ioException); ```