Description of the problem:
When I use a mocked list of anything, LocalDateTime.now() and make a stream out of a list, an exception occured: java.lang.IllegalStateException: stream has already been operated upon or closed
Here is a minimal code example (junit-test) @Test public void whyThisError(@Mocked List<Integer> doNothingWith) { LocalDateTime.now(); Optional<String> any = Arrays.asList("a").stream().findAny(); }
If you comment out LocalDateTime.now() or the mocked List ... no exception occurs
I use openjdk11 and inteliJ as IDE.
Could anybody explain this for me?
Greets
Dennis
The text was updated successfully, but these errors were encountered:
It happens because (in Java 8+) interfaces such as List and Collection have methods with implementations, which are being mocked due to the @Mocked List, affecting all List instances.
So, to avoid unexpected failures like this, said interfaces should be (and will be) regarded as unmockable.
Please provide the following information:
Version of JMockit that was used:
1.44
Description of the problem:
When I use a mocked list of anything, LocalDateTime.now() and make a stream out of a list, an exception occured:
java.lang.IllegalStateException: stream has already been operated upon or closed
Here is a minimal code example (junit-test)
@Test public void whyThisError(@Mocked List<Integer> doNothingWith) { LocalDateTime.now(); Optional<String> any = Arrays.asList("a").stream().findAny(); }
If you comment out LocalDateTime.now() or the mocked List ... no exception occurs
I use openjdk11 and inteliJ as IDE.
Could anybody explain this for me?
Greets
Dennis
The text was updated successfully, but these errors were encountered: