Skip to content

Commit b43d97b

Browse files
Document the need to explicitly reset mock servers
When MockServerRestTemplateCustomizer and MockServerRestClientCustomizer are used directly instead of via auto-configuration, it is necessary to manually reset the MockRestServiceServer expectations between tests. Closes gh-41848
1 parent c0e61d1 commit b43d97b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/MockServerRestClientCustomizer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
* obtain the mock server. If the customizer has been used more than once the
5151
* {@link #getServer(RestClient.Builder)} or {@link #getServers()} method must be used to
5252
* access the related server.
53+
* <p>
54+
* If a mock server is used in more than one test case in a test class, it might be
55+
* necessary to reset the expectations on the server between tests using
56+
* {@code getServer().reset()} or {@code getServer(restClientBuilder).reset()}.
5357
*
5458
* @author Scott Frederick
5559
* @since 3.2.0

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/MockServerRestTemplateCustomizer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
* obtain the mock server. If the customizer has been used more than once the
4949
* {@link #getServer(RestTemplate)} or {@link #getServers()} method must be used to access
5050
* the related server.
51+
* <p>
52+
* If a mock server is used in more than one test case in a test class, it might be
53+
* necessary to reset the expectations on the server between tests using
54+
* {@code getServer().reset()} or {@code getServer(restTemplate).reset()}.
5155
*
5256
* @author Phillip Webb
5357
* @author Moritz Halbritter

0 commit comments

Comments
 (0)