Skip to content

Commit 0e84761

Browse files
committed
Return Builder from sslInfo() builder method for MockServerHttpRequest
Prior to this commit, the sslInfo() method in MockServerHttpRequest's BaseBuilder returned void, which prevented it from being used with the intended fluent Builder pattern. This commit changes the return type to the builder (B) for proper method chaining. Closes gh-35075
1 parent 5d0fc72 commit 0e84761

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public interface BaseBuilder<B extends BaseBuilder<B>> {
258258
/**
259259
* Set SSL session information and certificates.
260260
*/
261-
void sslInfo(SslInfo sslInfo);
261+
B sslInfo(SslInfo sslInfo);
262262

263263
/**
264264
* Add one or more cookies.
@@ -443,8 +443,9 @@ public BodyBuilder localAddress(InetSocketAddress localAddress) {
443443
}
444444

445445
@Override
446-
public void sslInfo(SslInfo sslInfo) {
446+
public BodyBuilder sslInfo(SslInfo sslInfo) {
447447
this.sslInfo = sslInfo;
448+
return this;
448449
}
449450

450451
@Override

spring-test/src/test/java/org/springframework/mock/http/server/reactive/MockServerHttpRequestTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.jupiter.api.Test;
2626
import org.junit.jupiter.params.ParameterizedTest;
2727
import org.junit.jupiter.params.provider.MethodSource;
28+
import org.mockito.internal.util.MockUtil;
2829

2930
import org.springframework.http.HttpCookie;
3031
import org.springframework.http.HttpHeaders;
@@ -33,6 +34,7 @@
3334
import static org.assertj.core.api.Assertions.assertThat;
3435
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
3536
import static org.junit.jupiter.api.Named.named;
37+
import static org.mockito.Mockito.mock;
3638

3739
/**
3840
* Tests for {@link MockServerHttpRequest}.
@@ -66,6 +68,19 @@ void queryParams() {
6668
assertThat(request.getURI().toString()).isEqualTo("/foo%20bar?a=b&name%20A=value%20A1&name%20A=value%20A2&name%20B=value%20B1");
6769
}
6870

71+
/**
72+
* Ensure that {@code sslInfo()} can be used with the fluent builder pattern.
73+
*/
74+
@Test // gh-35075
75+
void sslInfo() {
76+
MockServerHttpRequest request = MockServerHttpRequest.get("/test")
77+
.sslInfo(mock())
78+
.build();
79+
80+
assertThat(request.getSslInfo()).as("is mock").satisfies(sslInfo -> MockUtil.isMock(sslInfo));
81+
assertThat(request.getURI().toString()).isEqualTo("/test");
82+
}
83+
6984
@ParameterizedTest(name = "[{index}] {0}")
7085
@MethodSource
7186
void httpMethodNotNullOrEmpty(ThrowingCallable callable) {

spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public interface BaseBuilder<B extends BaseBuilder<B>> {
258258
/**
259259
* Set SSL session information and certificates.
260260
*/
261-
void sslInfo(SslInfo sslInfo);
261+
B sslInfo(SslInfo sslInfo);
262262

263263
/**
264264
* Add one or more cookies.
@@ -458,8 +458,9 @@ public BodyBuilder localAddress(InetSocketAddress localAddress) {
458458
}
459459

460460
@Override
461-
public void sslInfo(SslInfo sslInfo) {
461+
public BodyBuilder sslInfo(SslInfo sslInfo) {
462462
this.sslInfo = sslInfo;
463+
return this;
463464
}
464465

465466
@Override

0 commit comments

Comments
 (0)