Reputation: 1029
Code below:
List<Object> list = spy(new LinkedList<>());
list.stream().map(item -> item);
is not working, causing an exception during test:
Cannot call real method on java interface. Interface does not have any implementation!
Calling real methods is only possible when mocking concrete classes.
//correct example:
when(mockOfConcreteClass.doStuff()).thenCallRealMethod();
However, calling size()
is working okay. What is wrong with stream()
method? I am using Mockito 1.8.4
ver.
Upvotes: 3
Views: 2395
Reputation: 902
The method java.util.List.stream()
is a default method in java.util.Collection
. Mockito versions older than 1.10.5 (maybe 1.10.0) cannot handle default methods (it's missing the java.lang.reflect.Method.isDefault()
check and maybe some spy-specifics for dealing with such methods).
I've verified that it works with Mockito 1.10.19, so I recommend upgrading when writing code in Java 8.
Upvotes: 6