api-common-java/src/test/java/com/google/api/pathtemplate/PathTemplateTest.complexResourceIdInvalidDelimiter test erroneously succeeding #2776
Labels
priority: p3
Desirable enhancement or fix. May not be included in next release.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
https://github.com/googleapis/sdk-platform-java/blob/v2.40.0/api-common-java/src/test/java/com/google/api/pathtemplate/PathTemplateTest.java#L356
@test
public void complexResourceIdInvalidDelimiter() {
thrown.expect(ValidationException.class);
// Not a comprehensive set of invalid delimiters, please check the class's defined pattern.
List someInvalidDelimiters =
new ArrayList<>(Arrays.asList("|", "!", "@", "a", "1", ",", "{", ")"));
for (String invalidDelimiter : someInvalidDelimiters) {
PathTemplate.create(
String.format("projects/{project=*}/zones/{zone_a}%s{zone_b}", invalidDelimiter));
thrown.expectMessage(
String.format(
"parse error: invalid complex resource ID delimiter character in '%s'",
String.format("{zone_a}%s{zone_b}", invalidDelimiter)));
}
}
This test passes even though when the delimiter is
{
, the exception thrown actually contains the message:parse error: missing or 2+ consecutive delimiter characters in '{zone_a}{{zone_b}'
.This is because of the way Junit4 handles exceptions and statefulness - it checks for an initial
thrown.expect(ValidationException.class)
and initialthrown.expectMessage()
, which once passed, it considers it passed for the entire test.We will need to either rewrite this test to account for "{" delimiter, or potentially refactor the way
template
works such that the exception message matches the initial test.The text was updated successfully, but these errors were encountered: