Skip to content
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

mockito-core : 3.9.0 - Java 17 Test case failed #2525

Closed
sau3078 opened this issue Dec 20, 2021 · 1 comment
Closed

mockito-core : 3.9.0 - Java 17 Test case failed #2525

sau3078 opened this issue Dec 20, 2021 · 1 comment

Comments

@sau3078
Copy link

sau3078 commented Dec 20, 2021

Executable mockExecutable = Mockito.mock(Executable.class);
Above lines failed.
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class java.lang.reflect.Executable.

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.

@sau3078 sau3078 changed the title mockito-core : 3.90.0 - Java 17 Test case failed mockito-core : 3.9.0 - Java 17 Test case failed Dec 20, 2021
@TimvdLippe
Copy link
Contributor

Unfortunately, Executable is one of the classes that Mockito relies on internally for its behavior. Stubbing Executable will therefore lead to undefined behavior. Additionally, it is advised not to mock classes you don't own: https://github.com/mockito/mockito/wiki/How-to-write-good-tests#dont-mock-a-type-you-dont-own We are working on improving the user experience by working on a DoNotMock feature to avoid mocking classes/methods that are known to crash Mockito internals (#1833). Therefore, I am closing this as "Infeasible". Apologies for the uninformative exception that is thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants