Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(test): stop XmlParserTest matching a localized parser message (#3458)

Kenshin Okinakac12779416d2e
diff --git a/src/test/java/io/github/hectorvent/floci/core/common/XmlParserTest.java b/src/test/java/io/github/hectorvent/floci/core/common/XmlParserTest.java
index cdeae3fa0b..99b5ce2ab9 100644
--- a/src/test/java/io/github/hectorvent/floci/core/common/XmlParserTest.java
+++ b/src/test/java/io/github/hectorvent/floci/core/common/XmlParserTest.java
@@ -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);
+ }
}