Issue
I want to mock a line of code which is
List<FGUBeskaeftigelsesStatus> beskaeftigelseStatus = forloeb.getUng().getFguBeskaeftigelseStatus().stream().filter(fguBeskaeftigelsePredicate).collect(Collectors.toList());
I tried using mocks
but its throwing null pointer in Mockito. How can I mock this line so that my list is not empty and returns what I pass through thenReturn. Do I need to set mockForloeb/mockungs seperately again if i m mocking them already
Solution
You need to mock each part in the chain.
Ung mockedUng = Mockito.mock(Ung.class);
when(mockedUng.getFguBeskaeftigelseStatus()).thenReturn(fGUBeskaeftigelsesStatusList);
when(mockforloeb.getUng()).thenReturn(mockedUng);
Answered By - Pavel Polivka