-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mock(SecureRandom.class) and mock(Random.class) fails #2560
Comments
This has been resolved in some projects by adding an extra arg to the jvm
|
I think the annotations on
Making the |
Does this also happen if you use the inline mockmaker? (Assuming you are using the default subclass mockmaker) Please see https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#0.2 for instructions on how to do so. |
It does not. Is that a barrier to working around this in the default subclass mockmaker?
|
We had a short discussion about this in #1728 In general, the subclass mockmaker will be more and more difficult to work correctly on newer versions of the JDk, for which the inline mockmaker will work as expected. This is primarily because the subclass mockmaker has to access internal types that are slowly but surely locked off in the JDK. The inline mockmaker does not have the same limitations. Therefore, we are considering switching the default mockmaker to the inline mockmaker to make Mockito future-proof. Especially in the last few months, the amount of JDK 16-17+ related issues have significantly ramped up. Therefore, I think we have to consider doing so sooner rather than later. |
Closing this per #2589 |
Trying to mock SecureRandom or Random throws exception.
Throws exception:
However, if I disable the annotation mocking, this code completes successfully.
Random and SecureRandom seem relatively common, perhaps this can be handled more gracefully? Or perhaps the error message can highlight that this may be an annotation only problem and thus can be worked around?
The text was updated successfully, but these errors were encountered: