Skip to content

Commit e0fa58a

Browse files
committed
Polishing contribution
Closes gh-26905
1 parent 65797d0 commit e0fa58a

File tree

1 file changed

+7
-35
lines changed

1 file changed

+7
-35
lines changed

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

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
import static org.assertj.core.api.Assertions.assertThat;
4040
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
41-
import static org.assertj.core.api.Assertions.fail;
41+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4242

4343
/**
4444
* Unit tests for {@link UriComponentsBuilder}.
@@ -1275,40 +1275,12 @@ void verifyDoubleSlashReplacedWithSingleOne() {
12751275

12761276

12771277
@Test
1278-
void verifyNonNumberPort() {
1279-
UriComponents numberPort = UriComponentsBuilder.fromUriString("http://localhost:8080/path").build();
1280-
assertThat(numberPort.getScheme()).isEqualTo("http");
1281-
assertThat(numberPort.getHost()).isEqualTo("localhost");
1282-
assertThat(numberPort.getPort()).isEqualTo(8080);
1283-
assertThat(numberPort.getPath()).isEqualTo("/path");
1284-
1285-
UriComponents stringPort = UriComponentsBuilder.fromUriString("http://localhost:port/path").build();
1286-
try{
1287-
stringPort.getPort();
1288-
fail("port must be a number");
1289-
}catch (NumberFormatException e){
1290-
1291-
}
1292-
assertThat(stringPort.getScheme()).isEqualTo("http");
1293-
assertThat(stringPort.getHost()).isEqualTo("localhost");
1294-
assertThat(stringPort.getPath()).isEqualTo("/path");
1295-
1296-
UriComponents httpNumberPort = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/path").build();
1297-
assertThat(httpNumberPort.getScheme()).isEqualTo("http");
1298-
assertThat(httpNumberPort.getPort()).isEqualTo(8080);
1299-
assertThat(httpNumberPort.getHost()).isEqualTo("localhost");
1300-
assertThat(httpNumberPort.getPath()).isEqualTo("/path");
1301-
1302-
UriComponents httpStringPort= UriComponentsBuilder.fromHttpUrl("http://localhost:port/path").build();
1303-
try{
1304-
httpStringPort.getPort();
1305-
fail("port must be a number");
1306-
}catch (NumberFormatException e){
1307-
1308-
}
1309-
assertThat(httpStringPort.getScheme()).isEqualTo("http");
1310-
assertThat(httpStringPort.getHost()).isEqualTo("localhost");
1311-
assertThat(httpStringPort.getPath()).isEqualTo("/path");
1278+
void verifyInvalidPort() {
1279+
String url = "http://localhost:port/path";
1280+
assertThatThrownBy(() -> UriComponentsBuilder.fromUriString(url).build().toUri())
1281+
.isInstanceOf(NumberFormatException.class);
1282+
assertThatThrownBy(() -> UriComponentsBuilder.fromHttpUrl(url).build().toUri())
1283+
.isInstanceOf(NumberFormatException.class);
13121284
}
13131285

13141286
}

0 commit comments

Comments
 (0)