Reputation: 1940
I am trying to test a method using mockito and powermockito, this method internally calling a method which returns void, i wanted to mock this method since i dont care about the result of that method. i have been trying on this but unable to find the solution please help me on this.
I tries using powermockito as
SearchProcedureCodeControllerBean mock = mock(SearchProcedureCodeControllerBean.class);
PowerMockito.doNothing().when(mock).setErrorMessage((String)anyObject(), Mockito.anyList().toArray(), (String)anyObject(), (String)anyObject());
setErrorMessage is the void method, signature for this method is as follows
public void setErrorMessage(String errorName, Object[] arguments,
String messageBundle, String componentId) {
}
Upvotes: 0
Views: 1564
Reputation: 5220
You can stub method of a mocked object only. Tested object is definitely not mocked. With Power Mockito you can stub static methods, it's not your case. If you don't care about the method behavior just leave it like this. It`s void so it will baisically don't matter. If it does and you would like to suppress it's influence, it would mean the real problem is with the design as the class under test owns too much responsibility. Extract the method to another class and then mock it.
Upvotes: 2