Skip to content

Commit 60445a5

Browse files
committed
Polish "Fix null customizer checks in HTTP client builders"
See gh-51509
1 parent 93a24ea commit 60445a5

8 files changed

Lines changed: 20 additions & 29 deletions

module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/ClientHttpRequestFactoryBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ default T build() {
7070
* @return a new {@link ClientHttpRequestFactoryBuilder} instance
7171
*/
7272
default ClientHttpRequestFactoryBuilder<T> withCustomizer(Consumer<T> customizer) {
73+
Assert.notNull(customizer, "'customizer' must not be null");
7374
return withCustomizers(List.of(customizer));
7475
}
7576

module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/reactive/ClientHttpConnectorBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ default T build() {
6868
* @return a new {@link ClientHttpConnectorBuilder} instance
6969
*/
7070
default ClientHttpConnectorBuilder<T> withCustomizer(Consumer<T> customizer) {
71+
Assert.notNull(customizer, "'customizer' must not be null");
7172
return withCustomizers(List.of(customizer));
7273
}
7374

@@ -139,7 +140,7 @@ static JdkClientHttpConnectorBuilder jdk() {
139140
*/
140141
@SuppressWarnings("unchecked")
141142
static <T extends ClientHttpConnector> ClientHttpConnectorBuilder<T> of(Class<T> clientHttpConnectorType) {
142-
Assert.notNull(clientHttpConnectorType, "'clientHttpConnectorType' must not be null");
143+
Assert.notNull(clientHttpConnectorType, "'requestFactoryType' must not be null");
143144
Assert.isTrue(clientHttpConnectorType != ClientHttpConnector.class,
144145
"'clientHttpConnectorType' must be an implementation of ClientHttpConnector");
145146
if (clientHttpConnectorType == ReactorClientHttpConnector.class) {

module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/reactive/HttpComponentsClientHttpConnectorBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private HttpComponentsClientHttpConnectorBuilder(
6666
*/
6767
public HttpComponentsClientHttpConnectorBuilder withHttpClientCustomizer(
6868
Consumer<HttpAsyncClientBuilder> httpClientCustomizer) {
69-
Assert.notNull(httpClientCustomizer, "'httpClientCustomizer' must not be null");
69+
Assert.notNull(httpClientCustomizer, "'customizer' must not be null");
7070
return new HttpComponentsClientHttpConnectorBuilder(getCustomizers(),
7171
this.httpClientBuilder.withCustomizer(httpClientCustomizer));
7272
}

module/spring-boot-http-client/src/test/java/org/springframework/boot/http/client/AbstractClientHttpRequestFactoryBuilderTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
import static org.assertj.core.api.Assertions.assertThat;
5656
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
57+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
5758

5859
/**
5960
* Base class for {@link ClientHttpRequestFactoryBuilder} tests.
@@ -76,6 +77,13 @@ abstract class AbstractClientHttpRequestFactoryBuilderTests<T extends ClientHttp
7677
this.builder = builder;
7778
}
7879

80+
@Test
81+
@SuppressWarnings("NullAway") // Test null check
82+
void withCustomizerWhenCustomizerIsNullThrowsException() {
83+
assertThatIllegalArgumentException().isThrownBy(() -> this.builder.withCustomizer(null))
84+
.withMessage("'customizer' must not be null");
85+
}
86+
7987
@Test
8088
void buildReturnsRequestFactoryOfExpectedType() {
8189
T requestFactory = this.builder.build();

module/spring-boot-http-client/src/test/java/org/springframework/boot/http/client/SimpleClientHttpRequestFactoryBuilderTests.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.boot.http.client;
1818

19-
import org.junit.jupiter.api.Test;
2019
import org.junit.jupiter.params.ParameterizedTest;
2120
import org.junit.jupiter.params.provider.ValueSource;
2221

@@ -26,7 +25,6 @@
2625
import org.springframework.test.util.ReflectionTestUtils;
2726

2827
import static org.assertj.core.api.Assertions.assertThat;
29-
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
3028
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
3129

3230
/**
@@ -83,14 +81,6 @@ void redirectDontFollow(String httpMethod) throws Exception {
8381
super.redirectDontFollow(httpMethod);
8482
}
8583

86-
@Test
87-
@SuppressWarnings("NullAway") // Test null check
88-
void withCustomizerWhenCustomizerIsNullThrowsException() {
89-
assertThatIllegalArgumentException()
90-
.isThrownBy(() -> ClientHttpRequestFactoryBuilder.simple().withCustomizer(null))
91-
.withMessage("'customizer' must not be null");
92-
}
93-
9484
@Override
9585
protected HttpStatus getExpectedRedirect(HttpMethod httpMethod) {
9686
return (httpMethod != HttpMethod.GET) ? HttpStatus.FOUND : HttpStatus.OK;

module/spring-boot-http-client/src/test/java/org/springframework/boot/http/client/reactive/AbstractClientHttpConnectorBuilderTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
import static org.assertj.core.api.Assertions.assertThat;
5858
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
59+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
5960

6061
/**
6162
* Base class for {@link ClientHttpConnectorBuilder} tests.
@@ -77,6 +78,13 @@ abstract class AbstractClientHttpConnectorBuilderTests<T extends ClientHttpConne
7778
this.builder = builder;
7879
}
7980

81+
@Test
82+
@SuppressWarnings("NullAway") // Test null check
83+
void withCustomizerWhenCustomizerIsNullThrowsException() {
84+
assertThatIllegalArgumentException().isThrownBy(() -> this.builder.withCustomizer(null))
85+
.withMessage("'customizer' must not be null");
86+
}
87+
8088
@Test
8189
void buildReturnsConnectorOfExpectedType() {
8290
T connector = this.builder.build();

module/spring-boot-http-client/src/test/java/org/springframework/boot/http/client/reactive/HttpComponentsClientHttpConnectorBuilderTests.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.test.util.ReflectionTestUtils;
4040

4141
import static org.assertj.core.api.Assertions.assertThat;
42-
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
4342

4443
/**
4544
* Tests for {@link HttpComponentsClientHttpConnectorBuilder} and
@@ -81,14 +80,6 @@ void withCustomizers() {
8180
defaultRequestConfigCustomizer1.assertCalled();
8281
}
8382

84-
@Test
85-
@SuppressWarnings("NullAway") // Test null check
86-
void withHttpClientCustomizerWhenCustomizerIsNullThrowsException() {
87-
assertThatIllegalArgumentException()
88-
.isThrownBy(() -> ClientHttpConnectorBuilder.httpComponents().withHttpClientCustomizer(null))
89-
.withMessage("'httpClientCustomizer' must not be null");
90-
}
91-
9283
@Test
9384
@WithPackageResources("test.jks")
9485
void withTlsSocketStrategyFactory() {

module/spring-boot-http-client/src/test/java/org/springframework/boot/http/client/reactive/JdkClientHttpConnectorBuilderTests.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.test.util.ReflectionTestUtils;
2929

3030
import static org.assertj.core.api.Assertions.assertThat;
31-
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
3231

3332
/**
3433
* Tests for {@link JdkClientHttpConnectorBuilder} and {@link JdkHttpClientBuilder}.
@@ -53,13 +52,6 @@ void withCustomizers() {
5352
httpClientCustomizer2.assertCalled();
5453
}
5554

56-
@Test
57-
@SuppressWarnings("NullAway") // Test null check
58-
void withCustomizerWhenCustomizerIsNullThrowsException() {
59-
assertThatIllegalArgumentException().isThrownBy(() -> ClientHttpConnectorBuilder.jdk().withCustomizer(null))
60-
.withMessage("'customizer' must not be null");
61-
}
62-
6355
@Test
6456
void withExecutor() {
6557
Executor executor = new SimpleAsyncTaskExecutor();

0 commit comments

Comments
 (0)