Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How addAll works with mocked paginated query

I have to add the PaginatedQueryList from to secondList which comes from dynamoDbMapper.query for testing. How can I achieve it?

List exampleList = secondList.addAll(dynamoDbMapper.query(MyDAOClass.class, queryExpression));

I tried to mock the PaginatedQueryList but am getting null pointer exception because elements in mocked PaginatedQueryList is empty.

Any suggestions please?

like image 727
Joe Avatar asked Nov 25 '25 10:11

Joe


1 Answers

You can do the following and it will work:

  1. Create mock for paginated result.

    @Mock private PaginatedQueryList<Object> queryResult;

  2. Return mocked result when query is called.

    when(dynamoDBMapper.query(any(), any())).thenReturn(queryResult);

  3. set result in paginated result by mocking it with an array of expected list, say, firstList.

    when(queryResult.toArray()).thenReturn(firstList);

  4. Add result in secondList.

    List exampleList = secondList.addAll(firstlist)

like image 74
Nikita Avatar answered Nov 27 '25 23:11

Nikita