I am getting below error when I am using Java 19. I tried using --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
, but that also does not help to resolve below issue. How can I mock ThreadLocalRandom when using Java 19? I am not getting any error if I use Java 17 or below version. Below is the code that generates this error.
final ThreadLocalRandom random = Mockito.mock(ThreadLocalRandom.class);
Mockito.when(random.nextInt(Mockito.anyInt())).thenReturn(0);
[ERROR] Failures: [ERROR] Mockito
Cannot mock/spy class java.util.concurrent.ThreadLocalRandom Mockito cannot mock/spy following:final classes anonymous classes primitive types
I tried --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
. I am expecting it should work as it was working in Java 17.