mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Polish "Fix null customizer checks in HTTP client builders"
See gh-51509
This commit is contained in:
+1
@@ -70,6 +70,7 @@ public interface ClientHttpRequestFactoryBuilder<T extends ClientHttpRequestFact
|
||||
* @return a new {@link ClientHttpRequestFactoryBuilder} instance
|
||||
*/
|
||||
default ClientHttpRequestFactoryBuilder<T> withCustomizer(Consumer<T> customizer) {
|
||||
Assert.notNull(customizer, "'customizer' must not be null");
|
||||
return withCustomizers(List.of(customizer));
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -68,6 +68,7 @@ public interface ClientHttpConnectorBuilder<T extends ClientHttpConnector> {
|
||||
* @return a new {@link ClientHttpConnectorBuilder} instance
|
||||
*/
|
||||
default ClientHttpConnectorBuilder<T> withCustomizer(Consumer<T> customizer) {
|
||||
Assert.notNull(customizer, "'customizer' must not be null");
|
||||
return withCustomizers(List.of(customizer));
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ public interface ClientHttpConnectorBuilder<T extends ClientHttpConnector> {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T extends ClientHttpConnector> ClientHttpConnectorBuilder<T> of(Class<T> clientHttpConnectorType) {
|
||||
Assert.notNull(clientHttpConnectorType, "'clientHttpConnectorType' must not be null");
|
||||
Assert.notNull(clientHttpConnectorType, "'requestFactoryType' must not be null");
|
||||
Assert.isTrue(clientHttpConnectorType != ClientHttpConnector.class,
|
||||
"'clientHttpConnectorType' must be an implementation of ClientHttpConnector");
|
||||
if (clientHttpConnectorType == ReactorClientHttpConnector.class) {
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public final class HttpComponentsClientHttpConnectorBuilder
|
||||
*/
|
||||
public HttpComponentsClientHttpConnectorBuilder withHttpClientCustomizer(
|
||||
Consumer<HttpAsyncClientBuilder> httpClientCustomizer) {
|
||||
Assert.notNull(httpClientCustomizer, "'httpClientCustomizer' must not be null");
|
||||
Assert.notNull(httpClientCustomizer, "'customizer' must not be null");
|
||||
return new HttpComponentsClientHttpConnectorBuilder(getCustomizers(),
|
||||
this.httpClientBuilder.withCustomizer(httpClientCustomizer));
|
||||
}
|
||||
|
||||
+8
@@ -54,6 +54,7 @@ import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Base class for {@link ClientHttpRequestFactoryBuilder} tests.
|
||||
@@ -76,6 +77,13 @@ abstract class AbstractClientHttpRequestFactoryBuilderTests<T extends ClientHttp
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("NullAway") // Test null check
|
||||
void withCustomizerWhenCustomizerIsNullThrowsException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.builder.withCustomizer(null))
|
||||
.withMessage("'customizer' must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildReturnsRequestFactoryOfExpectedType() {
|
||||
T requestFactory = this.builder.build();
|
||||
|
||||
-10
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.boot.http.client;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
@@ -26,7 +25,6 @@ import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
@@ -83,14 +81,6 @@ class SimpleClientHttpRequestFactoryBuilderTests
|
||||
super.redirectDontFollow(httpMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("NullAway") // Test null check
|
||||
void withCustomizerWhenCustomizerIsNullThrowsException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ClientHttpRequestFactoryBuilder.simple().withCustomizer(null))
|
||||
.withMessage("'customizer' must not be null");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpStatus getExpectedRedirect(HttpMethod httpMethod) {
|
||||
return (httpMethod != HttpMethod.GET) ? HttpStatus.FOUND : HttpStatus.OK;
|
||||
|
||||
+8
@@ -56,6 +56,7 @@ import org.springframework.web.reactive.function.client.WebClientRequestExceptio
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Base class for {@link ClientHttpConnectorBuilder} tests.
|
||||
@@ -77,6 +78,13 @@ abstract class AbstractClientHttpConnectorBuilderTests<T extends ClientHttpConne
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("NullAway") // Test null check
|
||||
void withCustomizerWhenCustomizerIsNullThrowsException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.builder.withCustomizer(null))
|
||||
.withMessage("'customizer' must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildReturnsConnectorOfExpectedType() {
|
||||
T connector = this.builder.build();
|
||||
|
||||
-9
@@ -39,7 +39,6 @@ import org.springframework.http.client.reactive.HttpComponentsClientHttpConnecto
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link HttpComponentsClientHttpConnectorBuilder} and
|
||||
@@ -81,14 +80,6 @@ class HttpComponentsClientHttpConnectorBuilderTests
|
||||
defaultRequestConfigCustomizer1.assertCalled();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("NullAway") // Test null check
|
||||
void withHttpClientCustomizerWhenCustomizerIsNullThrowsException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ClientHttpConnectorBuilder.httpComponents().withHttpClientCustomizer(null))
|
||||
.withMessage("'httpClientCustomizer' must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithPackageResources("test.jks")
|
||||
void withTlsSocketStrategyFactory() {
|
||||
|
||||
-8
@@ -28,7 +28,6 @@ import org.springframework.http.client.reactive.JdkClientHttpConnector;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link JdkClientHttpConnectorBuilder} and {@link JdkHttpClientBuilder}.
|
||||
@@ -53,13 +52,6 @@ class JdkClientHttpConnectorBuilderTests extends AbstractClientHttpConnectorBuil
|
||||
httpClientCustomizer2.assertCalled();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("NullAway") // Test null check
|
||||
void withCustomizerWhenCustomizerIsNullThrowsException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> ClientHttpConnectorBuilder.jdk().withCustomizer(null))
|
||||
.withMessage("'customizer' must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withExecutor() {
|
||||
Executor executor = new SimpleAsyncTaskExecutor();
|
||||
|
||||
Reference in New Issue
Block a user