aspose file tools*
The moose likes Testing and the fly likes mocking private static methods with PowerMock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "mocking private static methods with PowerMock" Watch "mocking private static methods with PowerMock" New topic
Author

mocking private static methods with PowerMock

Max Ulanovskiy
Greenhorn

Joined: Aug 01, 2009
Posts: 3
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

Joined: Jul 11, 2001
Posts: 14112
Make the private static method public and non-static. Seriously. Why would you not?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Max Ulanovskiy
Greenhorn

Joined: Aug 01, 2009
Posts: 3
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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mocking private static methods with PowerMock