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
WitheBox.setInternalState on private static final field #673
Comments
How did you manage to do that? Afaik the JVM inlines this field and simply replace the value of the field at those places where it's referenced. So even if you change the field value you it won't impact the code that are using since field (at compile time at least) |
I do it at runtime I don't know what JVM inlining is done behind the scenes. Here is where all the magic happens. I basically removed the final modifier from the field. My implementation leaves the fields like that but I can implement something that restores the fields modifier after the value has been set. |
I've added test case where you solution is failed. And for the case with String (or any primitives) you will never be able change internal state due to the fact how compiler works in this case. I think that PowerMock already could set internal state for |
That is interesting. I will investigate. Thank you! |
@johanhaleby @thekingnothing Did you have the time to take a look at my pull request? |
@andreicristianpetcu Thank you for your pull request. I hope I'll have a time to review your pull request tomorrow. |
Thank you, @thekingnothing it's good to know when you can look at it :) |
@thekingnothing any update on this pull request? |
This would be very useful 👍 |
@thekingnothing any idea when you can look at my PR? |
@andreicristianpetcu I'm really sorry for so long delay. I was focus on moving my family to another country. |
@thekingnothing no problem for the delay :) I added the changelog.txt and apparently the Travis build now fails. Apparently there are some tests failing that are unrelated to my pull request. LargeMethodTest.largeMethodShouldBeAbleToBeSuppressed
LargeMethodTest.largeMethodShouldBeOverridden
LargeMethodTest.largeMethodShouldBeAbleToBeMocked
LargeMethodTest.largeMethodShouldBeAbleToBeMockedAndThrowException Any clue what might have caused this? The commit that triggered the build is really small and it is in a text file. |
@andreicristianpetcu I don't have any clue what was it...but locally everything is fine and the build is okay after repeat. |
@thekingnothing thank you for merging this pull request. When will the next release be published? v1.6.6 |
@andreicristianpetcu as soon as we resolve all issue which was scheduled for next release. |
@thekingnothing are there any of them good for beginners? Can you put a label on the ones that might be good for new contributors? |
Is this added in PowerMock 1.7.4? |
yes it is in 1.7.4 |
Weird... I am getting next issue:
While running next test:
With the following dependencies on JDK 1.8:
Do you mind to confirm if something is wrong @andreicristianpetcu ? |
I don't use powermock anymore. I don't work for the company that I used to work for when I contributed this change. I try to limit my time invested in free software. If I were you, I would report a new issue, clone this project and debug it locally. I know very little about this project. I basically copy/pasted from stack overflow into this repo :D |
Could you please take a look at this issue. I would be thankful for any help. |
@rainbow702 the compiler inlines primitives and strings. Integer is an object, not a primitive. I cannot change something inlined by the compiler. Try avoiding this or getting the String object and modify it's internal state. |
thanks |
Hi,
I see that WitheBox.setInternalState cannot set private static final fields. Why is that? Lack of time or some other reason?
I sent a pull request to Mockito to implement this and they do not want it in Mockito. Would you accept a similar implementation in Powermock? Am I using Powermock wrong?
Thank you!
The text was updated successfully, but these errors were encountered: