File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
main/java/org/springframework/boot/test/web/client
test/java/org/springframework/boot/test/web/client Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,19 @@ public class TestRestTemplate {
8282
8383 private final RestTemplate restTemplate ;
8484
85+ /**
86+ * Create a new {@link TestRestTemplate} instance.
87+ * @param restTemplateBuilder builder used to configure underlying {@link RestTemplate}
88+ */
89+ public TestRestTemplate (RestTemplateBuilder restTemplateBuilder ) {
90+ this (buildRestTemplate (restTemplateBuilder ));
91+ }
92+
93+ private static RestTemplate buildRestTemplate (RestTemplateBuilder restTemplateBuilder ) {
94+ Assert .notNull (restTemplateBuilder , "RestTemplateBuilder must not be null" );
95+ return restTemplateBuilder .build ();
96+ }
97+
8598 /**
8699 * Create a new {@link TestRestTemplate} instance.
87100 * @param httpClientOptions client options to use if the Apache HTTP Client is used
Original file line number Diff line number Diff line change 2424
2525import org .springframework .boot .test .web .client .TestRestTemplate .CustomHttpComponentsClientHttpRequestFactory ;
2626import org .springframework .boot .test .web .client .TestRestTemplate .HttpClientOption ;
27+ import org .springframework .boot .web .client .RestTemplateBuilder ;
2728import org .springframework .http .HttpMethod ;
2829import org .springframework .http .client .HttpComponentsClientHttpRequestFactory ;
2930import org .springframework .http .client .InterceptingClientHttpRequestFactory ;
3334import org .springframework .web .client .RestTemplate ;
3435
3536import static org .assertj .core .api .Assertions .assertThat ;
37+ import static org .mockito .BDDMockito .given ;
3638import static org .mockito .Mockito .mock ;
3739
3840/**
4345 */
4446public class TestRestTemplateTests {
4547
48+ @ Test
49+ public void fromRestTemplateBuilder () {
50+ RestTemplateBuilder builder = mock (RestTemplateBuilder .class );
51+ RestTemplate delegate = new RestTemplate ();
52+ given (builder .build ()).willReturn (delegate );
53+ assertThat (new TestRestTemplate (builder ).getRestTemplate ())
54+ .isEqualTo (delegate );
55+ }
56+
4657 @ Test
4758 public void simple () {
4859 // The Apache client is on the classpath so we get the fully-fledged factory
You can’t perform that action at this time.
0 commit comments