You need a Method object and a Class object. According to your comment, Mokito cannot scoff at the Method, so you need a real one. I have not tested this, but I believe that it will work. Instead:
when(mockContext.getMethod().getName()).thenReturn("someMethod"); when(mockContext.getMethod().getDeclaringClass().getName()).thenReturn("someClass");
You need:
// any method will do, but here is an example of how to get one. Method testMethod = this.getClass().getMethod("logCallTest"); when(mockContext.getMethod()).thenReturn(testMethod);
Obviously, getName() will no longer return "someMethod", but getDeclaringClass().getName() will return the name of this test class (in the example), but although you could not choose what they returned, what they returned is still determinate so that you can verify everything you need. (Of course, if you need to spy on or verify that the call was made on the Method object itself, you get stuck anyway.)
jhericks
source share