Im using MockRestServiceServer for mocking http responses. In a specific scenario i call an endpoint two times and want a different response the second time.
But when i write a second expectation it's like it overwrites my first expectation.
How does one write multiple responses for the same request?
I've found it after some research:
When instantiating a MockRestServiceServer it default gets an UnorderedRequestExpectationManager. Changing this via the Builder in a SimpleRequestExpectationManager adds support for adding multiple responses in the order of defining them.
private MockRestServiceServer createMockServerBy(Class<? extends
RestTemplate> requiredType) {
RestTemplate template = context.getBean(requiredType);
return MockRestServiceServer.bindTo(template).build(new
SimpleRequestExpectationManager());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With