Junit Mockito matchers InvalidUseofMatchers异常返回null

Junit Mockito matchers InvalidUseofMatchers异常返回null,junit,mocking,mockito,Junit,Mocking,Mockito,我需要从以下位置返回null: Cookie controlCookieValue = getCookie(cookiesConfigBean.getControlCookieName()); 我正在做: when(baseHandler.getCookie(any(String.class))).thenReturn(null); 但是代码抛出InvalidUseofMatcherException。我试着使用anyObject()和anyString(),但没有任何效果。基本句柄< /代

我需要从以下位置返回null:

Cookie controlCookieValue = getCookie(cookiesConfigBean.getControlCookieName());
我正在做:

when(baseHandler.getCookie(any(String.class))).thenReturn(null);

但是代码抛出
InvalidUseofMatcherException
。我试着使用
anyObject()
anyString()
,但没有任何效果。<代码>基本句柄< /代码>对象是一个模拟。

所以你的<代码> GoCudie()/Case>方法调用<代码> BaseHuffer-<代码> >请在你的<代码> GoCukieBaseHandler类是受保护的还是公共的,以及
getCookie
是非最终的,是受保护的还是公共的?