mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(test): stop XmlParserTest matching a localized parser message (#3458)
* fix(test): stop XmlParserTest matching a localized parser message Both DTD tests asserted on "not declared", a sentence the JDK's XML parser translates, so the suite fails on any JVM whose default locale is not English. On macOS that locale comes from system preferences, so neither LANG nor -Duser.language on the Maven command line avoids it. Match the entity name the parser quotes instead, which no translation touches, and assert the external-entity case on what it actually means: the message must not name the file, which proves the parser never reached it. * test(core): read the parser message once and quote the entity name plainly getMessage() is allowed to be null, so calling contains() on it directly would throw an NPE in place of a readable assertion failure. Take the message through String.valueOf once and use it for both the predicate and the failure text. The expected substring was built from char literals, which reads like arithmetic at a glance; spell the quotes as string literals instead.
This commit is contained in:
1 parent
a2285072c9
commit
c12779416d
1 file changed
+17
-4
@@ -49,8 +49,7 @@ class XmlParserTest {
|
||||
r2.next();
|
||||
}
|
||||
}, "an entity from the skipped DTD must not expand");
|
||||
assertTrue(e.getMessage().contains("not declared"),
|
||||
"should fail because the DTD never took effect, was: " + e.getMessage());
|
||||
assertFailedOnUndeclaredEntity(e, "x");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,8 +67,10 @@ class XmlParserTest {
|
||||
r.next();
|
||||
}
|
||||
}, "an external entity must never be resolved");
|
||||
assertTrue(e.getMessage().contains("not declared"),
|
||||
"must fail without reading the file at all, was: " + e.getMessage());
|
||||
assertFailedOnUndeclaredEntity(e, "secret");
|
||||
String message = String.valueOf(e.getMessage());
|
||||
assertFalse(message.contains("nonexistent"),
|
||||
"must fail without reading the file at all, was: " + message);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -397,4 +398,16 @@ class XmlParserTest {
|
||||
assertNull(XmlParser.rootElementName("<AccelerateConfiguration><Status>Enabled"));
|
||||
assertNull(XmlParser.rootElementName("<AccelerateConfiguration/>trailing"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the parse stopped at an entity reference the document never declared. The parser
|
||||
* translates the sentence it reports, so a JVM with a non-English default locale spells this
|
||||
* failure differently, and on macOS that locale comes from system preferences rather than from
|
||||
* LANG. The entity name it quotes is the part no translation touches.
|
||||
*/
|
||||
private static void assertFailedOnUndeclaredEntity(XMLStreamException e, String entityName) {
|
||||
String message = String.valueOf(e.getMessage());
|
||||
assertTrue(message.contains("\"" + entityName + "\""),
|
||||
"should fail on the undeclared entity " + entityName + ", was: " + message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user