For the Above Code in JunitTest Case i need to use spy.
Spy need new Instance. But Main Class is Final Class as well it is private constructor so using reflection i created instance but if i pass that instance inside it throwing eror
Normally when I start to think "oh PowerMock would help me out with this test" I take that as a massive alarm bell that there's likely something wrong with my design or that I'm trying to test the wrong thing.
In this example the class MainClass is completely useless as you can't instantiate it through normal programming, i.e. without hoking behind the scenes with reflection. So, if the class cannot be used then why is it there at all?
The code you gave as an example does not provide a good basis for a useful discussion. It's like talking about what you'd need to do to be able to kick yourself in the head: first, you'd need to be some kind of contortionist to pull it off and second, why?!!! That's pretty much the thing I see with what you seem to be trying to do there with that code, to be honest.
In MainClass all the methods are Static i need to do Junit for Code Coverage. i completed almost but for Exception i need to do junit code cover.. Above code i have created similar to my utillity class.
Now Please Help on this to cover code coverage... What i need to ...
It's really simple. You write tests that exercise the functionality of the methods. No need to use any mocking frameworks for this, just run the real code.