Is there any way we can mock the static util method while testing in JUnit?
I know Powermock can mock static calls, but I don\'t want to use Powermock.
Are
When you have static code that gives you trouble in your unit tests; so that you feel you have to "mock it away", you have exactly these options:
In other words: if you want to use a mocking framework, you have to use one of those listed above. On the one side, that is absolutely fair. static is one part of the Java language; so why not use a framework that allows you to deal with it?
But of course: you still have the static call in your production code then. Leading to tight coupling, and preventing polymorphism.
So: if you can get rid of the static call (even when just using the workaround suggested in the other answer) - all the better. If not: Mockito can't help; you need the magic of byte code manipulation resp. JVM agents.