From: David ‘Bombe’ Roden Date: Fri, 25 Oct 2013 04:47:09 +0000 (+0200) Subject: Verify that an invalid image causes an error. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=45f452c0098821ba37b28888ffc75bccae80216d;p=Sone.git Verify that an invalid image causes an error. --- diff --git a/src/main/java/net/pterodactylus/sone/core/SoneParser.java b/src/main/java/net/pterodactylus/sone/core/SoneParser.java index 512da1b..2056c32 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneParser.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneParser.java @@ -282,7 +282,7 @@ public class SoneParser { String imageHeightString = imageXml.getValue("height", null); if ((imageId == null) || (imageCreationTimeString == null) || (imageKey == null) || (imageTitle == null) || (imageWidthString == null) || (imageHeightString == null)) { logger.log(Level.WARNING, String.format("Downloaded Sone %s contains invalid images!", sone)); - return null; + throw new MalformedXml(); } long creationTime = Numbers.safeParseLong(imageCreationTimeString, 0L); int imageWidth = Numbers.safeParseInteger(imageWidthString, 0); diff --git a/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java b/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java index 0e8de25..9ae54a2 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java @@ -166,6 +166,11 @@ public class SoneParserTest { soneParser.parseSone(database, originalSone, getXml("invalid-parent-album")); } + @Test(expected = MalformedXml.class) + public void verifyThatAnInvalidImageCausesAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-image")); + } + @Test public void verifyThatAnEmptyProfileIsParsedWithoutError() { Sone sone = soneParser.parseSone(database, originalSone, getXml("empty-profile")); diff --git a/src/test/resources/sone-parser/invalid-image.xml b/src/test/resources/sone-parser/invalid-image.xml new file mode 100644 index 0000000..8725d81 --- /dev/null +++ b/src/test/resources/sone-parser/invalid-image.xml @@ -0,0 +1,86 @@ + + + + + 0 + + + Sone + 0.8.7 + + + + First + M. + Last + 22 + 10 + 2013 + 96431abe-3add-11e3-8a46-67047503bf6d + + + Field1 + Value1 + + + Field2 + Value2 + + + + + + + bbb7ebf0-3adb-11e3-8a0b-630cd8f21cf3 + + + Hello, World! + + + d8c9586e-3adb-11e3-bb31-171fc040e645 + 0rpD4gL8mszav2trndhIdKIxvKUCNAe2kjA3dLV8CVU + + Hello, User! + + + + + + f09fa448-3adb-11e3-a783-ab54a11aacc4 + bbb7ebf0-3adb-11e3-8a0b-630cd8f21cf3 + + Talking to myself. + + + 0a376440-3adc-11e3-8f45-c7cc157436a5 + 11ebe86e-3adc-11e3-b7b9-7f2c88018a33 + + Talking to somebody I can't see. + + + + + bbb7ebf0-3adb-11e3-8a0b-630cd8f21cf3 + 305d85e6-3adc-11e3-be45-8b53dd91f0af + + + + f09fa448-3adb-11e3-a783-ab54a11aacc4 + 3ba28960-3adc-11e3-93c7-6713d170f44c + + + + + 6a73c6e6-3adc-11e3-b091-577b10a725ad + Album1 + First album with stuff. + e3707102-3adc-11e3-b828-9f4de99f0bc4 + + + bar + + + + + +