Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit testing static method which uses a resource bundle
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COYeah, this method isn't really unit testable in its present form. Not because it's static, but because of the call to `ResourceBundle.getBundle`. In theory, you could do it with PowerMock, if you really had to, although refactoring would be a much better option. But I look at your question and I wonder why you are unit testing a legacy class. Surely, if it's a legacy class, then most of the opportunity to benefit from unit testing has already passed? And if you're not allowed to change it, then what will you do if your testing uncovers a bug?
      singulars
    2. COThanks for your answer. I agree with you completely about the value derived by writing Junits now. The thing is we have this project and part of the code is covered by JUnits and part of the code is not. The idea is to bring the whole code upto date with Junits and cover new development also with unit test cases. The code being legacy and being tested and stable, is the reason we dont want to refactor it (at least at this point in time). But having said that, and looking at your comment, it would be very helpful if you could point me towards how to do this with Powermock.
      singulars
    3. COI am going straight to mock hell for this - but https://code.google.com/p/powermock/wiki/MockitoUsage13 has information about how to mock static methods. About one screen down from the top. But honestly, try Rogério's way first if you can.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload