diff --git a/spring-web/src/test/java/org/springframework/web/util/UriComponentsTests.java b/spring-web/src/test/java/org/springframework/web/util/UriComponentsTests.java index 543ab81c1c0..ffa6a975d22 100644 --- a/spring-web/src/test/java/org/springframework/web/util/UriComponentsTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/UriComponentsTests.java @@ -196,16 +196,20 @@ class UriComponentsTests { @ParameterizedTest // gh-28521 @EnumSource - void invalidPort(ParserType parserType) { + void invalidPortParsed(ParserType parserType) { assertThatExceptionOfType(InvalidUrlException.class) .isThrownBy(() -> fromUriString("https://example.com:XXX/bar", parserType)); - assertExceptionsForInvalidPort(fromUriString("https://example.com/bar", parserType).port("XXX").build()); } - private void assertExceptionsForInvalidPort(UriComponents uriComponents) { + @ParameterizedTest + @EnumSource + void invalidPortSet(ParserType parserType) { + UriComponents uriComponents = fromUriString("https://example.com/bar", parserType).port("XXX").build(); + assertThatIllegalStateException() .isThrownBy(uriComponents::getPort) .withMessage("The port must be an integer: XXX"); + assertThatIllegalStateException() .isThrownBy(uriComponents::toUri) .withMessage("The port must be an integer: XXX");