Skip to content

MockRestServiceServerAutoConfiguration with RestTemplate and RestClient together throws incorrect exception #38820

@michaldo

Description

@michaldo

It should be possible to have together RestTemplate and RestClient in application and test them independently.

Unfortunately, currently if RestTemplate is used, RestClient cannot be tested:

org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerAutoConfiguration.DeferredRequestExpectationManager#getDelegate

if (!restTemplateExpectationManagers.isEmpty()) {
    Assert.state(restTemplateExpectationManagers.size() == 1,
            "Unable to use auto-configured MockRestServiceServer since "
                    + "MockServerRestTemplateCustomizer has been bound to more than one RestTemplate");
    return restTemplateExpectationManagers.values().iterator().next();
}
Assert.state(restClientExpectationManagers.size() == 1,
        "Unable to use auto-configured MockRestServiceServer since "
                + "MockServerRestClientCustomizer has been bound to more than one RestClient");
return restClientExpectationManagers.values().iterator().next();

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions