为了在 mockito 中执行 else 块,我想使这个条件失败。
if (!StringUtils.isEmpty(parentObj.getChildObj().getChildMessage()))
我尝试了以下方法,
when(StringUtils.isEmpty(any())).thenReturn(true);
这会抛出 org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Mockito.when(parentObj.getChildObj().getChildMessage()).thenReturn(null);
Mockito.when(parentObj.getChildObj().getChildMessage()).thenReturn("");
都抛出,NullPointerException。
上面的异常是在testcase本身抛出的,不去实际的方法。有人可以帮我吗?