Mocking Reflection based calls

后端 未结 2 1456
悲&欢浪女
悲&欢浪女 2020-12-16 15:23

I am trying to mock some reflection based methods. Below you can see the details,

Class Under Test

public class TracerLog {
    @AroundInvoke
    pu         


        
2条回答
  •  独厮守ぢ
    2020-12-16 15:54

    Yeah the problem is that mockContext.getMethod() is going to return null. So every time you run this, then call something on the result (getDeclaringClass() or getName()) you'll get the NPE. You probably want to use the RETURNS_DEEP_STUBS default answer, when you set up the mock. Something like

    @Mock( answer = RETURNS_DEEP_STUBS ) private InvocationContext mockContext; 
    

    should do the trick.

提交回复
热议问题