Expand PowerMockWhiteboxToJavaReflection to cover more Whitebox APIs#1013
Closed
MBoegers wants to merge 1 commit into
Closed
Expand PowerMockWhiteboxToJavaReflection to cover more Whitebox APIs#1013MBoegers wants to merge 1 commit into
MBoegers wants to merge 1 commit into
Conversation
| } | ||
|
|
||
| private @Nullable String buildReplacementTemplate(Statement statement, J.MethodInvocation mi, | ||
| private JavaType.@Nullable Method resolveFor(J.MethodInvocation mi) { |
Contributor
There was a problem hiding this comment.
Might suggest making the name more reflect the fact it's just for the invoke methods
5fc96ec to
4ad8941
Compare
Adds migration of getField, getMethod, invokeConstructor, static invokeMethod(Class,..), the where-Class get/setInternalState overloads, and non-literal field/method names, alongside the existing setInternalState/getInternalState/invokeMethod support. Primitive results are cast through their wrapper type, and the explicit Class[]/varargs-array overloads of invokeMethod/invokeConstructor are deliberately left untouched (no faithful mechanical translation).
4ad8941 to
dfdc2d0
Compare
Collaborator
Author
|
I will reshape the PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The PowerMock → Mockito migration removes the
org.powermock:powermock-reflectdependency, butPowerMockWhiteboxToJavaReflectionpreviously migrated onlysetInternalState/getInternalState/invokeMethod, leaving the rest of theWhiteboxAPI as uncompilable references after the dependency is dropped.This expands the recipe to also migrate, to plain
java.lang.reflect:getField/getMethod→getDeclaredField/getDeclaredMethod+setAccessibleinvokeConstructor(both overloads) →Constructor.newInstanceinvokeMethod(Class, …)→invoke(null, …)Class wheregetInternalState/setInternalStateoverloadsNotes:
(Integer)etc.), since a direct(int) objectcast does not compile.Class[]/ varargs-array overloads ofinvokeMethod/invokeConstructorare intentionally left untouched — there is no faithful mechanical translation (a follow-up recipe flags them).getDeclaredField/getDeclaredConstructoron the named class, which differs from PowerMock for members inherited from a superclass (documented in the recipe description).Adds unit tests covering each new signature plus the primitive-cast and array-overload cases.