Reputation: 540
I am trying to mock a static method
StaticClass.staticMethod(id).setContentType("text/plain").build();
I was able to mock static method and its return type using PowerMockito as below :
PowerMockito.when(StaticClass.staticMethod(id)).thenReturn(returnValue);
But How do I send that value to the chained method setContentType()?
Upvotes: 0
Views: 996
Reputation: 1337
You need multiple whens. You'll need to mock a couple more objects staticMethod
and contentType
.
PowerMockito.when(StaticClass.staticMethod(id)).thenReturn(staticMethod);
PowerMockito.when(staticMethod.setContentType("text/plain")).thenReturn(contentType);
PowerMockito.when(contentType.build()).thenReturn(returnValue);
Upvotes: 2