Get rid of powermock
See original GitHub issueIn this comment https://github.com/apache/pulsar/pull/16884#issuecomment-1201512995 I wrote:
I don’t like powermock as it lacks maintenance. It seems all usage of powermock is
Whitebox
. We can get rid of it with simple reflections. This can be a separate issue, though.
Thus I file this issue to investigate whether we can remove powermock from our testing framework.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How to mock static method without powermock - Stack Overflow
So: if you can get rid of the static call (even when just using the workaround suggested in the other answer) - all...
Read more >Remove powermock · Issue #6439 - GitHub
If that isn't acceptable, the next best thing is to completely isolate powermock tests to their own class(es) but this probably won't solve...
Read more >Mockito Mock Static Method - PowerMock - DigitalOcean
Hello Pankaj , For mocking static methods , if we use PowerMockito , it will increse the memory consumption and soon we will...
Read more >Mocking Static Methods With Mockito - Baeldung
In this tutorial, we'll take a look at how we can now mock static methods using the latest version of Mockito. To learn...
Read more >[powermock] Using PowerMock for mocking static properties ...
If I remove @InjectMocks, remove the TestController instantiation on definition, and do controllerUT = new TestController() in the test function, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Shoothzj thank you. I’ll consider this approach when protptyping. There’re some cases we try to hijack third-party lib’s field, like
eventLoopGroup
in bookkeeper code. In those situations, we should still use reflections. (… or patching upstream, or change testing logics)But yes, we can use multiple alternatives properly in each concrete case.
I draft an incompleted patch on #16997.
However, I notice that there’s some code we hack in “set final” field, like:
https://github.com/apache/pulsar/blob/21634edd30bbe33d231ec73e8045d7666a8ad366/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java#L1071-L1072
… or even “set static final” field, like:
https://github.com/apache/pulsar/blob/21634edd30bbe33d231ec73e8045d7666a8ad366/pulsar-functions/runtime/src/test/java/org/apache/pulsar/functions/runtime/thread/ThreadRuntimeFactoryTest.java#L111
It seems
powermock-reflect
is the best library existing to handle these cases since JDK12+ it’s banned changingfinal
field instead you have to useUnsafe
. I tend not to maintain such unsafe hacks within Pulsar codebase. And perhaps we should gradually refactor code to avoid depending on such manners.cc @Shoothzj @eolivelli @nicoloboschi