In my implementation I'm grabbing data from ElasticSearch via ElasticsearchTemplate#stream() which returns CloseableIterator<>.
I'd like to mock this method by doing:
List<MyClass> foo = new ArrayList<>(); // and then I add some elements
when(mockTemplate.stream(any(SearchQuery.class), eq(MyClass.class))
.thenReturn(foo.iterator());
but iterator() returns Iterator<MyClass> which is not CloseableIterator<MyClass> and I have no clue how to cast it or find a workaround.