-
Notifications
You must be signed in to change notification settings - Fork 6
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
Restore previously deleted methods associated with MockUp classes. #158
Restore previously deleted methods associated with MockUp classes. #158
Conversation
Hi @yukkes, yes very much appreciate this. The original author I could never understand why he consistently deleted support making upgrades next to impossible. So I get everything is a work in progress and welcome all your efforts here to restore any needed features that will make your own migrations and others much easier. I think we all know this library is just maintenance but it needs to work and easily and hopefully up through higher jdks than current as the cost of migrating is high. I do know open rewrite is working on trying to have a migration path to mockito and are very well aware of this fork. I think their hurdles have been much of the lost support which makes it hard for them to have the latest here and somehow upgrade the older copies. So I think this will greatly help so keep it coming :) |
As noted on the other PR, I think we need both 11 and 17 working here before we merge. 21 is going to fail. I can just remove it from the builds when I get some time as its an ongoing issue. But the master currently work son 11 and 17. |
For the sun.reflect, can you write that any differently so it might work on 17? Presume that was when it was either entirely blocked or maybe removed, not sure. Would need to look. Its ok if the code doesn't come back exactly like it was. The main thing is that it just works for the folks that need it. |
holding off this one for now since jdk 17 failed. Please look into that a bit more. |
Thanks for the code review. I'll check back later as I'm spending time with my family right now. |
Fixed not to reference the sun.reflect package. public static <T> T newUninitializedInstance(@Nonnull Class<T> aClass) {
SunReflectionFactoryInstantiator<T> ref = new SunReflectionFactoryInstantiator<>(aClass);
return ref.newInstance();
} |
@hazendaz, thanks for the accurate review remarks. I committed to this project because we plan to continue using JMockit after Java 21. I hope others will find it useful in the future. |
The reason for the test failure in Java 21 is that the class to be mocked is now a sealed class.
public class InetAddress implements java.io.Serializable {
public sealed class InetAddress implements Serializable permits Inet4Address, Inet6Address { |
Agreed, I started looking at migrating most of the tests to junit 5 only using open rewrite but it had a very hard issue here. So my plan is to do that then simply disable for higher jdk. Thank you for finding the info. Do note this did not prevent this from working on java 21. I use it at work without issues already at that level. But for our audience faster we fix to show it works on each the more contributors may want to engage and feel more comfortable its working. |
main/pom.xml
Outdated
@@ -9,7 +9,6 @@ | |||
<version>1.51.1-SNAPSHOT</version> | |||
</parent> | |||
|
|||
<groupId>com.github.hazendaz.jmockit</groupId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add this back, its a strong preference of mine to be strict in poms of the GAV. I know m2e in eclipse is all messed up since it has warnings even if set to not warn in recent releases. Won't bother you with that here, I'll take care of no issues.
throw new IllegalArgumentException( | ||
"Unsupported fake for private " + kindOfMember + privateMemberDesc + " found"); | ||
} | ||
// Supported fake for private method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yukkes Can you add a simple further note here that we are keeping commented out code from original changes? Normally I'd say delete it but I think in this case I agree commenting it out is fine but want to make sure its obvious why we are keeping commented out code, otherwise someone will delete it it in the future.
thrown.expectMessage("Component"); | ||
thrown.expectMessage("checkCoalescing()"); | ||
thrown.expectMessage("found"); | ||
// Enabled to fake a private constructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same on these, just a bit more clarlity as to why we are keeping commented out code.
@yukkes Very minor asks to make it a bit more clear why intention to keep commented out code. You may want to date it as well I typically will add a todo as well so its easily seen, something like this with XXX (your initials) // TODO 12/2/2023 XXX Reason why we are doing something odd |
10d7e67
to
8bbc18a
Compare
@hazendaz , thanks for the code review. I fixed the code. |
Please wait for the merge as we are in the process of resolving JMockit-related errors in our internal project. |
No problem. Thank you for all you are doing.
Sent from my Verizon, Samsung Galaxy smartphone
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: yukkes ***@***.***>
Sent: Saturday, December 9, 2023 1:52:59 AM
To: hazendaz/jmockit1 ***@***.***>
Cc: Jeremy Landis ***@***.***>; Mention ***@***.***>
Subject: Re: [hazendaz/jmockit1] Restore previously deleted methods associated with MockUp classes. (PR #158)
Please wait for the merge as we are in the process of resolving JMockit-related errors in our internal project.
It is expected to take about a week.
—
Reply to this email directly, view it on GitHub<#158 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAHODI2UYL6IY5PGSSZUY43YIQDEXAVCNFSM6AAAAABACMZ7YWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBYGI3DQMRYGU>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I have restored MockUp class and test class based on JMockit ver. 1.35, please review and merge if there is no problem. The following test class is restored and all tests PASS.
However, the MockUpForSingleInterfaceInstanceTest failed the test as is, so I commented it out with a TODO comment. The reason for this is that the FieldInjection class has changed and no longer sets default values. |
@yukkes Are you good at this point for me to push a release? |
@hazendaz Yes, please release. Note that the annotation to determine the number of method invocations has been restored as shown below, but since there is no judgment process, there is no error even if the number of invocations is different. |
Release is out now. Let me know how that works out for you. |
@hazendaz Thank you for the release. |
@hazendaz |
Thanks you for your excellent work, I have restored previously deleted methods associated with MockUp classes.
I have attempted to fully restore the processing of past versions of JMockit, but have had some setbacks.
I hope you recognize this as an area for future improvement.
The number of invocations is ignored because there is no judgment process such as @mock(invocations = 1).
The following errors have been resolved. (12/12/2023)
The javadoc generation fails because ConstructorReflection refers to "sun.reflect.*" of a private package in Java 9 or later. The error has been avoided by adding "--ignore-source-errors".The test fails because only the last value set in the following test case can be retrieved.