I have a query statement which returns a PaginatedQueryList
and I assign it to a List. Then I operate on the list.
List<MyClass> entries= mapper.query(MyClass.class, queryExpression);
//Logic to test
Map<String, Map> map = entries.stream()
.collect(Collectors.toMap(MyClass::getA, MyClass::getB));
....
....
I tried to test it like
when(mapper.query(eq(MyClass.class), any(DynamoDBQueryExpression.class)))
.thenReturn((PaginatedQueryList<MyClass>) list);
where list
is List<MyClass>
(ArrayList) that I construct myself and want to pass it to the main program to test the main logic.
But it throws
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList
How can I send the list when it executes mappper.query(..)
.
The motive is to send the list that I constructed to entries
when executing mapper.query(..)
.
NOTE:
I also tried sending a mocked
PaginatedQueryList but when it does entries.stream()
I want to send the actual stream. I tried like
when(paginatedQueryList.stream()).thenReturn(Stream.of(list.get(0), list.get(1)));
It throws
java.lang.IllegalStateException: stream has already been operated upon or closed at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:229)
Aucun commentaire:
Enregistrer un commentaire