-
Notifications
You must be signed in to change notification settings - Fork 583
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
PowerMockRunner with mock-maker-inline Classloader issues #1034
Comments
rxue
added a commit
to rxue/powermock
that referenced
this issue
Jan 23, 2021
…h mockito-inline dependency Fix powermock#1034
rxue
added a commit
to rxue/powermock
that referenced
this issue
Jan 23, 2021
…ockito-inline dependency Fix powermock#1034 The root cause of the powermock#1034 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* coexists, the invoking of `MockClassLoader.getResources("mocito-extensions/org.mockito.plugins.MockMaker")` with `"mocito-extensions/org.mockito.plugins.MockMaker"` as agument returns an instance of `Enumeration<URL>` and first element is the URL of *mockito-inline* instead of the expected *powermock-api-mockito2* jar
rxue
added a commit
to rxue/powermock
that referenced
this issue
Jan 23, 2021
…ockito-inline dependency Fix powermock#1034 The root cause of the powermock#1034 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-kapi-mockito2 coexists, the invoking of MockClassLoader.getResources with "mocito-extensions/org.mockito.plugins.MockMaker" as agument returns an instance of Enumeration<URL> where the first element is the URL of mockito-inline instead of that of expected powermock-api-mockito2 jar. This should be handled as a special case
rxue
added a commit
to rxue/powermock
that referenced
this issue
Jan 23, 2021
…ine dependency Fix powermock#1034 The root cause of the powermock#1034 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-kapi-mockito2 coexists, the invoking of MockClassLoader.getResources with "mocito-extensions/org.mockito.plugins.MockMaker" as agument returns an instance of Enumeration<URL> where the first element is the URL of mockito-inline instead of that of expected powermock-api-mockito2 jar. This should be handled as a special case
rxue
added a commit
to rxue/powermock
that referenced
this issue
Jan 24, 2021
…ine dependency Fix powermock#1034 The root cause of the powermock#1034 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-kapi-mockito2 coexists, the invoking of MockClassLoader.getResources with "mocito-extensions/org.mockito.plugins.MockMaker" as agument returns an instance of Enumeration<URL> where the first element is the URL of mockito-inline instead of that of expected powermock-api-mockito2 jar. This should be handled as a special case Based on the document of ClassLoader, the method to override should be protected findResources in stead of the public getResources
rxue
added a commit
to rxue/powermock
that referenced
this issue
Jan 24, 2021
…ne dependency Fix powermock#1034 The root cause of the powermock#1034 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-kapi-mockito2 coexists, the invoking of MockClassLoader.getResources with "mocito-extensions/org.mockito.plugins.MockMaker" as agument returns an instance of Enumeration<URL> where the first element is the URL of mockito-inline instead of that of expected powermock-api-mockito2 jar. This should be handled as a special case Based on the document of ClassLoader, the method to override should be protected findResources in stead of the public getResources
rxue
added a commit
to rxue/powermock
that referenced
this issue
Jan 24, 2021
Fix powermock#1034 The root cause of the powermock#1034 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-kapi-mockito2 coexists, the invoking of MockClassLoader.getResources with "mocito-extensions/org.mockito.plugins.MockMaker" as agument returns an instance of Enumeration<URL> where the first element is the URL of mockito-inline instead of that of expected powermock-api-mockito2 jar. This should be handled as a special case Based on the document of ClassLoader, the method to override should be protected findResources in stead of the public getResources
rxue
added a commit
to rxue/powermock
that referenced
this issue
Jan 24, 2021
Fix powermock#1034 The root cause of the powermock#1034 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-kapi-mockito2 coexists, the invoking of MockClassLoader.getResources with "mocito-extensions/org.mockito.plugins.MockMaker" as agument returns an instance of Enumeration<URL> where the first element is the URL of mockito-inline instead of that of expected powermock-api-mockito2 jar. This should be handled as a special case Based on the document of ClassLoader, the method to override should be protected findResources in stead of the public getResources
rxue
added a commit
to rxue/powermock
that referenced
this issue
Jan 31, 2021
… 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 "mocito-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 file mocito-extensions/org.mockito.plugins.MockMaker. Whereas when executing a test annotated with RunWith(PowerMockRunner.class), the needed MockMaker should be based on the mocito-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
rxue
added a commit
to rxue/powermock
that referenced
this issue
Jan 31, 2021
… 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Versions:
byte-buddy - 1.10.8
Mockito - 3.0.0
Powermock - 2.0.0
Scenario:
Test case involving PowerMock (to mock and spy static classes and methods)
Mockito2 -> Normal mocking and it is done on a Spring context as well.
mock-maker-inline configuration
Earlier issue of PowerMockRule + mock-maker-inline configuration issue is resolved as per
Stackoverflow link
After the above fix, Facing class loader issues when multiple test cases make use of similar configuration.
Additional discussions on byte-buddy github page here
Error Log:
Suggestions based on response here
Please suggest if there is a fix available for this. Thanks in advance!
The text was updated successfully, but these errors were encountered: