Additional unit tests for operations on empty UriTemplate

See gh-32432
This commit is contained in:
Juergen Hoeller 2024-03-13 18:06:17 +01:00
parent 2922a82275
commit 54a6d89da7
1 changed files with 30 additions and 0 deletions

View File

@ -53,6 +53,13 @@ class UriTemplateTests {
assertThat(variableNames).as("Invalid variable names").isEqualTo(Arrays.asList("hotel", "booking"));
}
@Test
void getVariableNamesFromEmpty() {
UriTemplate template = new UriTemplate("");
List<String> variableNames = template.getVariableNames();
assertThat(variableNames).isEmpty();
}
@Test
void expandVarArgs() {
UriTemplate template = new UriTemplate("/hotels/{hotel}/bookings/{booking}");
@ -60,6 +67,13 @@ class UriTemplateTests {
assertThat(result).as("Invalid expanded template").isEqualTo(URI.create("/hotels/1/bookings/42"));
}
@Test
void expandVarArgsFromEmpty() {
UriTemplate template = new UriTemplate("");
URI result = template.expand();
assertThat(result).as("Invalid expanded template").isEqualTo(URI.create(""));
}
@Test // SPR-9712
void expandVarArgsWithArrayValue() {
UriTemplate template = new UriTemplate("/sum?numbers={numbers}");
@ -135,6 +149,15 @@ class UriTemplateTests {
assertThat(template.matches(null)).as("UriTemplate matches").isFalse();
}
@Test
void matchesAgainstEmpty() {
UriTemplate template = new UriTemplate("");
assertThat(template.matches("/hotels/1/bookings/42")).as("UriTemplate matches").isFalse();
assertThat(template.matches("/hotels/bookings")).as("UriTemplate matches").isFalse();
assertThat(template.matches("")).as("UriTemplate does not match").isTrue();
assertThat(template.matches(null)).as("UriTemplate matches").isFalse();
}
@Test
void matchesCustomRegex() {
UriTemplate template = new UriTemplate("/hotels/{hotel:\\d+}");
@ -153,6 +176,13 @@ class UriTemplateTests {
assertThat(result).as("Invalid match").isEqualTo(expected);
}
@Test
void matchAgainstEmpty() {
UriTemplate template = new UriTemplate("");
Map<String, String> result = template.match("/hotels/1/bookings/42");
assertThat(result).as("Invalid match").isEmpty();
}
@Test
void matchCustomRegex() {
Map<String, String> expected = new HashMap<>(2);