Skip to content

Commit

Permalink
Additional unit tests for operations on empty UriTemplate
Browse files Browse the repository at this point in the history
See gh-32432

(cherry picked from commit 54a6d89)
  • Loading branch information
jhoeller committed Mar 13, 2024
1 parent 08e7f7e commit 072ebb6
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,27 @@ void getVariableNames() {
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}");
URI result = template.expand("1", "42");
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}");
Expand Down Expand Up @@ -135,6 +149,15 @@ void matches() {
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+}");
Expand All @@ -153,6 +176,13 @@ void match() {
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);
Expand Down

0 comments on commit 072ebb6

Please sign in to comment.