From a56d9c3bc7315ce5655d71946ba38c51e8161b41 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 25 Oct 2013 06:44:50 +0200 Subject: [PATCH] Verify that an invalid parent album causes an error. --- .../net/pterodactylus/sone/core/SoneParser.java | 7 +- .../pterodactylus/sone/core/SoneParserTest.java | 6 ++ .../resources/sone-parser/invalid-parent-album.xml | 93 ++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/sone-parser/invalid-parent-album.xml diff --git a/src/main/java/net/pterodactylus/sone/core/SoneParser.java b/src/main/java/net/pterodactylus/sone/core/SoneParser.java index de11ab1..512da1b 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneParser.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneParser.java @@ -265,7 +265,7 @@ public class SoneParser { parent = albums.get(parentId); if (parent == null) { logger.log(Level.WARNING, String.format("Downloaded Sone %s has album with invalid parent!", sone)); - return null; + throw new InvalidParentAlbum(); } } Album album = parent.newAlbumBuilder().withId(id).build().modify().setTitle(title).setDescription(description).update(); @@ -363,4 +363,9 @@ public class SoneParser { public static class MalformedTime extends RuntimeException { } + + public static class InvalidParentAlbum extends RuntimeException { + + } + } diff --git a/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java b/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java index 87f6600..0e8de25 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java @@ -18,6 +18,7 @@ import java.io.InputStream; import java.util.logging.Logger; import net.pterodactylus.sone.core.SoneParser.DuplicateField; +import net.pterodactylus.sone.core.SoneParser.InvalidParentAlbum; import net.pterodactylus.sone.core.SoneParser.InvalidProtocolVersion; import net.pterodactylus.sone.core.SoneParser.InvalidXml; import net.pterodactylus.sone.core.SoneParser.MalformedTime; @@ -160,6 +161,11 @@ public class SoneParserTest { soneParser.parseSone(database, originalSone, getXml("invalid-album")); } + @Test(expected = InvalidParentAlbum.class) + public void verifyThatAnInvalidParentAlbumCausesAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-parent-album")); + } + @Test public void verifyThatAnEmptyProfileIsParsedWithoutError() { Sone sone = soneParser.parseSone(database, originalSone, getXml("empty-profile")); diff --git a/src/test/resources/sone-parser/invalid-parent-album.xml b/src/test/resources/sone-parser/invalid-parent-album.xml new file mode 100644 index 0000000..d72d880 --- /dev/null +++ b/src/test/resources/sone-parser/invalid-parent-album.xml @@ -0,0 +1,93 @@ + + + + + 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 + + + + + 1e73b52a-3add-11e3-ba45-cb0c28da9c2a + 6a73c6e6-3adc-11e3-b091-577b10a725ad + Nested Album + Nested album with stuff. + 312182ba-3add-11e3-bd76-13e7278f0161 + + + 312182ba-3add-11e3-bd76-13e7278f0161 + 1382420756000 + SSK@0rpD4gL8mszav2trndhIdKIxvKUCNAe2kjA3dLV8CVU,2KP8WDSaQvyJ16pXBHQrE1vj~fAaYPIsk35lM-ec4B0,AQACAAE/312182ba-3add-11e3-bd76-13e7278f0161.jpg + Other Stuff + Yes, it's other stuff! + 640 + 272 + + + + + + -- 2.7.4