Skip to content

Commit

Permalink
Add tests for spring-projectsgh-25109
Browse files Browse the repository at this point in the history
  • Loading branch information
midumitrescu committed May 28, 2020
1 parent 644cc30 commit dd91a7e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Expand Up @@ -452,7 +452,8 @@ private static class DefaultBodyBuilder implements BodyBuilder {

protected DefaultBodyBuilder(String methodValue, URI url) {
Assert.isTrue(StringUtils.hasLength(methodValue) &&
StringUtils.hasLength(methodValue.trim()), "HTTP methodValue must not be empty");
StringUtils.hasLength(methodValue.trim()), "HttpMethod is required. " +
"Please initialize it to non empty value");
this.methodValue = methodValue.trim();
this.url = url;
}
Expand Down
Expand Up @@ -17,11 +17,18 @@
package org.springframework.mock.http.server.reactive;

import java.util.Arrays;
import java.util.stream.Stream;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.web.util.UriComponentsBuilder;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -56,4 +63,22 @@ void queryParams() throws Exception {
assertThat(request.getURI().toString()).isEqualTo("/foo%20bar?a=b&name%20A=value%20A1&name%20A=value%20A2&name%20B=value%20B1");
}

@ParameterizedTest
@MethodSource("invalidMockServerHttpRequestBuilds")
void httpMethodNotNullOrEmpty(Executable executable) {
IllegalArgumentException expectedIllegalArgumentException = Assertions.assertThrows(IllegalArgumentException.class,
executable);
assertThat(expectedIllegalArgumentException.getMessage()).contains("HttpMethod is required.");
}

static Stream<Executable> invalidMockServerHttpRequestBuilds() {
String uriTemplate = "/foo bar?a=b";
return Stream.of(
() -> MockServerHttpRequest.method(null, UriComponentsBuilder.fromUriString(uriTemplate).build("")).build(),
() -> MockServerHttpRequest.method((HttpMethod) null, uriTemplate).build(),
() -> MockServerHttpRequest.method((String) null, uriTemplate).build(),
() -> MockServerHttpRequest.method("", uriTemplate).build(),
() -> MockServerHttpRequest.method(" ", uriTemplate).build()
);
}
}

0 comments on commit dd91a7e

Please sign in to comment.