Fix tests

Signed-off-by: Mario Daniel Ruiz Saavedra <desiderantes93@gmail.com>
This commit is contained in:
Mario Daniel Ruiz Saavedra 2025-09-08 17:53:19 -03:00
parent 11f2634c02
commit 89a7ee5519
2 changed files with 12 additions and 12 deletions

View File

@ -33,6 +33,7 @@ import org.assertj.core.api.ThrowingConsumer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
@ -54,7 +55,6 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.entry;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.HttpMethod.QUERY;
/**
* Tests for building a {@link MockHttpServletRequest} with
@ -420,13 +420,13 @@ class MockHttpServletRequestBuilderTests {
assertThat(request.getParameterMap().get("foo")).containsExactly("bar", "baz");
}
@Test
@ValueSource(strings = {"POST", "QUERY"})
@ParameterizedTest()
void requestParameterFromRequestBodyFormData() {
void requestParameterFromRequestBodyFormData(String methodName) {
String contentType = "application/x-www-form-urlencoded;charset=UTF-8";
String body = "name+1=value+1&name+2=value+A&name+2=value+B&name+3";
for (HttpMethod method : List.of(POST, QUERY)) {
HttpMethod method = HttpMethod.valueOf(methodName);
MockHttpServletRequest request = new MockHttpServletRequestBuilder(method).uri("/foo")
.contentType(contentType).content(body.getBytes(UTF_8))
.buildRequest(this.servletContext);
@ -434,7 +434,7 @@ class MockHttpServletRequestBuilderTests {
assertThat(request.getParameterMap().get("name 1")).containsExactly("value 1");
assertThat(request.getParameterMap().get("name 2")).containsExactly("value A", "value B");
assertThat(request.getParameterMap().get("name 3")).containsExactly((String) null);
}
}
@Test

View File

@ -256,10 +256,10 @@ abstract class AbstractMockWebServerTests {
Buffer buf = new Buffer();
buf.write(responseBody);
return new MockResponse.Builder()
.code(200)
.setHeader(CONTENT_TYPE, contentType)
.setHeader(CONTENT_LENGTH, responseBody.length)
.body(buf)
.code(200)
.build();
}