|
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 | 42 |
|
42 | 43 | /**
|
43 | 44 | * Unit tests for {@link UriComponentsBuilder}.
|
@@ -1272,4 +1273,42 @@ void verifyDoubleSlashReplacedWithSingleOne() {
|
1272 | 1273 | assertThat(path).isEqualTo("/home/path");
|
1273 | 1274 | }
|
1274 | 1275 |
|
| 1276 | + |
| 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"); |
| 1312 | + } |
| 1313 | + |
1275 | 1314 | }
|
0 commit comments