X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneParserTest.java;h=19e5ae2fd4899584ffe161fcce9f4c677b4c7663;hb=0a4b6fc252003c71f4bdef09560e87982838d9c8;hp=a950c77732e748201afdbf4dd4191b294eff7c88;hpb=d5a701bed7f1db1b3524ccb244593054755e47d6;p=Sone.git diff --git a/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java b/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java index a950c77..19e5ae2 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java @@ -17,9 +17,15 @@ import static org.mockito.Mockito.when; import java.io.InputStream; import java.util.logging.Logger; +import net.pterodactylus.sone.core.SoneParser.DuplicateField; +import net.pterodactylus.sone.core.SoneParser.InvalidAvatarId; +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.MalformedDimension; +import net.pterodactylus.sone.core.SoneParser.MalformedTime; import net.pterodactylus.sone.core.SoneParser.MalformedXml; +import net.pterodactylus.sone.core.SoneParser.SoneTooNew; import net.pterodactylus.sone.data.Client; import net.pterodactylus.sone.data.Image; import net.pterodactylus.sone.data.Post; @@ -62,12 +68,17 @@ public class SoneParserTest { soneParser.parseSone(database, originalSone, getXml("invalid-xml")); } + @Test + public void verifyThatAMissingProtocolVersionDoesNotCauseAnError() { + soneParser.parseSone(database, originalSone, getXml("missing-protocol-version")); + } + @Test(expected = InvalidProtocolVersion.class) public void verifyThatANegativeProtocolVersionCausesAnError() { soneParser.parseSone(database, originalSone, getXml("negative-protocol-version")); } - @Test(expected = InvalidProtocolVersion.class) + @Test(expected = SoneTooNew.class) public void verifyThatATooLargeProtocolVersionCausesAnError() { soneParser.parseSone(database, originalSone, getXml("too-large-protocol-version")); } @@ -77,6 +88,11 @@ public class SoneParserTest { soneParser.parseSone(database, originalSone, getXml("missing-time")); } + @Test(expected = MalformedTime.class) + public void verifyThatAnInvalidTimeCausesAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-time")); + } + @Test public void verifyThatAMissingClientCausesTheOriginalClientToBeUsed() { Sone sone = soneParser.parseSone(database, originalSone, getXml("missing-client")); @@ -93,6 +109,104 @@ public class SoneParserTest { assertThat(sone.getClient(), is(originalSone.getClient())); } + @Test(expected = MalformedXml.class) + public void verifyThatAMissingProfileCausesAnError() { + soneParser.parseSone(database, originalSone, getXml("missing-profile")); + } + + @Test(expected = MalformedXml.class) + public void verifyThatInvalidFieldsCauseAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-field")); + } + + @Test(expected = DuplicateField.class) + public void verifyThatDuplicateFieldsCauseAnError() { + soneParser.parseSone(database, originalSone, getXml("duplicate-field")); + } + + @Test(expected = InvalidAvatarId.class) + public void verifyThatAnInvalidAvatarIdCausesAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-avatar")); + } + + @Test + public void verifyThatMissingPostsDoNotCauseAnError() { + soneParser.parseSone(database, originalSone, getXml("missing-posts")); + } + + @Test(expected = MalformedXml.class) + public void verifyThatInvalidPostsCauseAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-posts")); + } + + @Test(expected = MalformedTime.class) + public void verifyThatAMalformedTimeCausesAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-post-time")); + } + + @Test + public void verifyThatMissingRepliesDoNotCauseAnError() { + soneParser.parseSone(database, originalSone, getXml("missing-replies")); + } + + @Test(expected = MalformedXml.class) + public void verifyThatInvalidRepliesCauseAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-replies")); + } + + @Test(expected = MalformedTime.class) + public void verifyThatAMalformedReplyTimeCausesAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-reply-time")); + } + + @Test + public void verifyThatAMissingPostLikesSectionDoesNotCauseAnError() { + soneParser.parseSone(database, originalSone, getXml("missing-post-likes")); + } + + @Test + public void verifyThatAMissingReplyLikesSectionDoesNotCauseAnError() { + soneParser.parseSone(database, originalSone, getXml("missing-reply-likes")); + } + + @Test + public void verifyThatMissingAlbumsSectionDoNotCauseAnError() { + soneParser.parseSone(database, originalSone, getXml("missing-albums")); + } + + @Test(expected = MalformedXml.class) + public void verifyThatAnInvalidAlbumCausesAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-album")); + } + + @Test(expected = InvalidParentAlbum.class) + public void verifyThatAnInvalidParentAlbumCausesAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-parent-album")); + } + + @Test(expected = MalformedXml.class) + public void verifyThatAnInvalidImageCausesAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-image")); + } + + @Test(expected = MalformedDimension.class) + public void verifyThatInvalidImageDimensionsCauseAnError() { + soneParser.parseSone(database, originalSone, getXml("invalid-image-dimensions")); + } + + @Test + public void verifyThatAnEmptyProfileIsParsedWithoutError() { + Sone sone = soneParser.parseSone(database, originalSone, getXml("empty-profile")); + assertThat(sone.getProfile().getFirstName(), nullValue()); + assertThat(sone.getProfile().getMiddleName(), nullValue()); + assertThat(sone.getProfile().getLastName(), nullValue()); + assertThat(sone.getProfile().getBirthYear(), nullValue()); + assertThat(sone.getProfile().getBirthMonth(), nullValue()); + assertThat(sone.getProfile().getBirthDay(), nullValue()); + assertThat(sone.getProfile().getAvatar(), nullValue()); + assertThat(sone.getProfile().getFields(), empty()); + } + @Test public void verifyThatTheCreatedSoneMeetsAllExpectations() { Sone sone = soneParser.parseSone(database, originalSone, getXml("complete"));