Additional unit tests for operations on empty UriTemplate
See gh-32432
This commit is contained in:
parent
2922a82275
commit
54a6d89da7
|
@ -53,6 +53,13 @@ class UriTemplateTests {
|
||||||
assertThat(variableNames).as("Invalid variable names").isEqualTo(Arrays.asList("hotel", "booking"));
|
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
|
@Test
|
||||||
void expandVarArgs() {
|
void expandVarArgs() {
|
||||||
UriTemplate template = new UriTemplate("/hotels/{hotel}/bookings/{booking}");
|
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"));
|
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
|
@Test // SPR-9712
|
||||||
void expandVarArgsWithArrayValue() {
|
void expandVarArgsWithArrayValue() {
|
||||||
UriTemplate template = new UriTemplate("/sum?numbers={numbers}");
|
UriTemplate template = new UriTemplate("/sum?numbers={numbers}");
|
||||||
|
@ -135,6 +149,15 @@ class UriTemplateTests {
|
||||||
assertThat(template.matches(null)).as("UriTemplate matches").isFalse();
|
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
|
@Test
|
||||||
void matchesCustomRegex() {
|
void matchesCustomRegex() {
|
||||||
UriTemplate template = new UriTemplate("/hotels/{hotel:\\d+}");
|
UriTemplate template = new UriTemplate("/hotels/{hotel:\\d+}");
|
||||||
|
@ -153,6 +176,13 @@ class UriTemplateTests {
|
||||||
assertThat(result).as("Invalid match").isEqualTo(expected);
|
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
|
@Test
|
||||||
void matchCustomRegex() {
|
void matchCustomRegex() {
|
||||||
Map<String, String> expected = new HashMap<>(2);
|
Map<String, String> expected = new HashMap<>(2);
|
||||||
|
|
Loading…
Reference in New Issue