有没有其他方法可以使这种情况失败?

时间:2021-02-23 11:24:03

标签: mockito

为了在 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本身抛出的,不去实际的方法。有人可以帮我吗?

0 个答案:

没有答案