Your querylist
is declared, but not initialized.
It is bad practice to @Mock the whole list - See this question and answers. In the snippets provided the @Mock
annotation doesn't even seem necessary.
There are a couple of options, the first seems most applicable to your situation:
@Mock
annotation, initialize the list List<UserLoginOutput> queryList = new ArrayList<>();
and add the expectedOutput
directly to the list with queryList.add(expectedOutput);
. Mocking the call to size()
is no longer necessary.List<UserLoginOutput> queryList = Arrays.asList(mockedUserLoginOutput);
This would remove the need to mock the call to size()
and the @Mock
annotation.expectedOutput
to the list and keep mocking the call to size. You might run into other issues as described in the linked article if other tests use Collection
functions like iterator()
.