如何使用 when...then 模拟层次结构 getter
How to mock hierarchy getters using when...then
我想模拟一行代码是
List<Status> Status = xyz.stream().filter(Predicate).collect(Collectors.toList());
我试过使用模拟
但它在 Mockito 中抛出空指针。我怎样才能模拟这一行,使我的列表不为空并且 returns 我通过 thenReturn.
您需要模拟链中的每个部分。
Ung mockedUng = Mockito.mock(Ung.class);
when(mockedUng.getFguBeskaeftigelseStatus()).thenReturn(fGUBeskaeftigelsesStatusList);
when(mockforloeb.getUng()).thenReturn(mockedUng);
我想模拟一行代码是
List<Status> Status = xyz.stream().filter(Predicate).collect(Collectors.toList());
我试过使用模拟
但它在 Mockito 中抛出空指针。我怎样才能模拟这一行,使我的列表不为空并且 returns 我通过 thenReturn.
您需要模拟链中的每个部分。
Ung mockedUng = Mockito.mock(Ung.class);
when(mockedUng.getFguBeskaeftigelseStatus()).thenReturn(fGUBeskaeftigelsesStatusList);
when(mockforloeb.getUng()).thenReturn(mockedUng);