|
38 | 38 |
|
39 | 39 | import static org.assertj.core.api.Assertions.assertThat;
|
40 | 40 | 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; |
42 | 42 |
|
43 | 43 | /**
|
44 | 44 | * Unit tests for {@link UriComponentsBuilder}.
|
@@ -1275,40 +1275,12 @@ void verifyDoubleSlashReplacedWithSingleOne() {
|
1275 | 1275 |
|
1276 | 1276 |
|
1277 | 1277 | @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); |
1312 | 1284 | }
|
1313 | 1285 |
|
1314 | 1286 | }
|
0 commit comments