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

Tests with @RunWith(PowerMockRunner.class) passes now with mockito-inline dependency also #1090

Open
wants to merge 1 commit into
base: release/2.x
Choose a base branch
from

Conversation

rxue
Copy link

@rxue rxue commented Jan 23, 2021

Fix #1034

… issues

The root cause of the error is still in the class loader - org.powermock.core.classloader.MockClassLoader:

When executing a test annotated with RunWith(PowerMockRunner.class) where mockito-inline and powermock-api-mockito2 dependencies coexists, the invoking of MockClassLoader.getResources with "mockito-extensions/org.mockito.plugins.MockMaker" as argument returns an instance of Enumeration<URL> whose first element is the URL of mockito-inline. So the class loader will load the unexpected InlineByteBuddyMockMaker, which is defined in the mockito-inline jar. Whereas when executing a test annotated with RunWith(PowerMockRunner.class), the needed MockMaker should be based on the mockito-extensions/org.mockito.plugins.MockMaker file from the powermock-api-mockito2 jar: https://github.com/powermock/powermock/blob/release/2.x/powermock-api/powermock-api-mockito2/src/main/resources/mockito-extensions/org.mockito.plugins.MockMaker

As per the implementation, based on the document of ClassLoader, the method to override should be the protected findResources in stead of the public getResources and, the current implementation is just an extra if condition. In future if more if condition is to be added, refactor will be needed
@dmitryfisko
Copy link

dmitryfisko commented Mar 10, 2022

@rxue @johanhaleby Do you have any updates? Why is PR still not merged?

@Furytron
Copy link

Can this be looked at please?

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

Successfully merging this pull request may close these issues.

PowerMockRunner with mock-maker-inline Classloader issues
3 participants