Browse Source

Polishing contribution

Closes gh-26905
pull/26918/head
Rossen Stoyanchev 5 years ago
parent
commit
e0fa58aa0f
  1. 42
      spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

42
spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

@ -38,7 +38,7 @@ import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.fail; import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** /**
* Unit tests for {@link UriComponentsBuilder}. * Unit tests for {@link UriComponentsBuilder}.
@ -1275,40 +1275,12 @@ class UriComponentsBuilderTests {
@Test @Test
void verifyNonNumberPort() { void verifyInvalidPort() {
UriComponents numberPort = UriComponentsBuilder.fromUriString("http://localhost:8080/path").build(); String url = "http://localhost:port/path";
assertThat(numberPort.getScheme()).isEqualTo("http"); assertThatThrownBy(() -> UriComponentsBuilder.fromUriString(url).build().toUri())
assertThat(numberPort.getHost()).isEqualTo("localhost"); .isInstanceOf(NumberFormatException.class);
assertThat(numberPort.getPort()).isEqualTo(8080); assertThatThrownBy(() -> UriComponentsBuilder.fromHttpUrl(url).build().toUri())
assertThat(numberPort.getPath()).isEqualTo("/path"); .isInstanceOf(NumberFormatException.class);
UriComponents stringPort = UriComponentsBuilder.fromUriString("http://localhost:port/path").build();
try{
stringPort.getPort();
fail("port must be a number");
}catch (NumberFormatException e){
}
assertThat(stringPort.getScheme()).isEqualTo("http");
assertThat(stringPort.getHost()).isEqualTo("localhost");
assertThat(stringPort.getPath()).isEqualTo("/path");
UriComponents httpNumberPort = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/path").build();
assertThat(httpNumberPort.getScheme()).isEqualTo("http");
assertThat(httpNumberPort.getPort()).isEqualTo(8080);
assertThat(httpNumberPort.getHost()).isEqualTo("localhost");
assertThat(httpNumberPort.getPath()).isEqualTo("/path");
UriComponents httpStringPort= UriComponentsBuilder.fromHttpUrl("http://localhost:port/path").build();
try{
httpStringPort.getPort();
fail("port must be a number");
}catch (NumberFormatException e){
}
assertThat(httpStringPort.getScheme()).isEqualTo("http");
assertThat(httpStringPort.getHost()).isEqualTo("localhost");
assertThat(httpStringPort.getPath()).isEqualTo("/path");
} }
} }

Loading…
Cancel
Save