尝试将我的项目从Java 11更新到Java 17,但在一个特定的测试中,Mockito出现了意外错误。
mock(java.util.Random.class);
抛出异常
Feb 04, 2022 3:07:01 PM com.google.inject.internal.MessageProcessor visit
INFO: An exception was caught and reported. Message: java.lang.IllegalAccessException: class
net.bytebuddy.description.annotation.AnnotationDescription$ForLoadedAnnotation cannot access interface
jdk.internal.util.random.RandomSupport$RandomGeneratorProperties (in module java.base)
because module java.base does not export jdk.internal.util.random to unnamed module @2f54a33d
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class java.util.Random.
Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.
Java : 17
JVM vendor name : Oracle Corporation
JVM vendor version : 17.0.2+8-86
JVM name : OpenJDK 64-Bit Server VM
JVM version : 17.0.2+8-86
JVM info : mixed mode, sharing
OS name : Mac OS X
OS version : 12.1
不确定为什么Mockito在这个测试中失败了。
Random
实例。 - OneCricketeer