Skip to content

Commit

Permalink
Merge pull request #40611 from snicoll
Browse files Browse the repository at this point in the history
* pr/40611:
  Polish "Avoid using OkHttp3ClientHttpRequestFactory in test"
  Avoid using OkHttp3ClientHttpRequestFactory in test

Closes gh-40611
  • Loading branch information
mhalbritter committed May 2, 2024
2 parents 3b7d477 + 1534bc8 commit 447ffb5
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,6 @@
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.mock.http.client.MockClientHttpRequest;
Expand Down Expand Up @@ -86,15 +85,15 @@ void simple() {

@Test
void doNotReplaceCustomRequestFactory() {
RestTemplateBuilder builder = new RestTemplateBuilder().requestFactory(OkHttp3ClientHttpRequestFactory.class);
RestTemplateBuilder builder = new RestTemplateBuilder().requestFactory(TestClientHttpRequestFactory.class);
TestRestTemplate testRestTemplate = new TestRestTemplate(builder);
assertThat(testRestTemplate.getRestTemplate().getRequestFactory())
.isInstanceOf(OkHttp3ClientHttpRequestFactory.class);
.isInstanceOf(TestClientHttpRequestFactory.class);
}

@Test
void useTheSameRequestFactoryClassWithBasicAuth() {
OkHttp3ClientHttpRequestFactory customFactory = new OkHttp3ClientHttpRequestFactory();
TestClientHttpRequestFactory customFactory = new TestClientHttpRequestFactory();
RestTemplateBuilder builder = new RestTemplateBuilder().requestFactory(() -> customFactory);
TestRestTemplate testRestTemplate = new TestRestTemplate(builder).withBasicAuth("test", "test");
RestTemplate restTemplate = testRestTemplate.getRestTemplate();
Expand Down Expand Up @@ -386,4 +385,8 @@ interface TestRestTemplateCallback {

}

static class TestClientHttpRequestFactory extends SimpleClientHttpRequestFactory {

}

}

0 comments on commit 447ffb5

Please sign in to comment.