I have a helper class which contains an public static method getProductHandler(String name)
:
public class ProductHandlerManager {
public static Handler getProductHandler(String name) {
Handler handler = findProductHandler(name);
return handler;
}
}
A CustomerService
class uses the above ProductHandlerManager
:
public class CustomerService {
...
public void handleProduct() {
Handler appleHandler = ProductHandlerManager.getProductHandler("apple");
appleHandler.post(new Runnable() {
@Override
public void run() {
//...
}
});
}
}
I want to unit test handleProduct()
method in CustomerService
class. I tried using mockito to mock the ProductManager.getProductHandler("apple")
part in test, however, mockito doesn't support static method mocking. How can I use Mockito to unit test handleProduct()
function then?
Please don't suggest me to use Powermock, since I read some article which says if I need to mock static method, it indicates a bad design. But I can accept suggestions about code refactoring to make it testable.