Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mocking private static methods with PowerMock

 
Max Ulanovskiy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is folow:
I need to test some public method which is calling private static method. To test them separately I want to mock the second one.
PowerMock has method to expect call of private static. Also we can mock selected method of object with and it works for simple private methods.


But how can I make my tested obj to call mocked class method instead of its reall class method?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make the private static method public and non-static. Seriously. Why would you not?
 
Max Ulanovskiy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately I have no permissions to change this brainfack code. It's a legacy system. But I've found a solution. Perhaps it would be useful for somebody

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic