Use a real XML file for testing.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 22 Oct 2013 06:11:07 +0000 (08:11 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:33 +0000 (22:25 +0100)
src/test/java/net/pterodactylus/sone/core/SoneParserTest.java
src/test/resources/sone-parser/invalid-xml.xml [new file with mode: 0644]

index 7029048..8acb2fa 100644 (file)
@@ -52,7 +52,7 @@ public class SoneParserTest {
 
        @Test
        public void verifyThatAnInvalidXmlDocumentIsNotParsed() throws UnsupportedEncodingException {
-               Optional<Sone> sone = soneParser.parseSone(database, originalSone, getInputStream("<xml>This is not valid XML.</invalid>"));
+               Optional<Sone> sone = soneParser.parseSone(database, originalSone, getXml("invalid-xml"));
                assertThat(sone, notNullValue());
                assertThat(sone.isPresent(), is(false));
        }
@@ -110,6 +110,10 @@ public class SoneParserTest {
                return new ByteArrayInputStream(content.getBytes("UTF-8"));
        }
 
+       private InputStream getXml(String name) {
+               return getClass().getResourceAsStream(format("/sone-parser/%s.xml", name));
+       }
+
        private static class SoneXmlBuilder {
 
                private Optional<Long> time = of(1000L);
diff --git a/src/test/resources/sone-parser/invalid-xml.xml b/src/test/resources/sone-parser/invalid-xml.xml
new file mode 100644 (file)
index 0000000..805f3b7
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<sone>
+
+</sone2>