X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2FMatchers.java;h=c73866eb6be239cdcd52b52ad8f06b61ee07c777;hp=41eb0dddbc925631f1773b9e8d99b5c44783fab9;hb=ffb2ea1773cf7e3d1b7fc41ab0e9c3c1eed514e0;hpb=ec06ae64c86f0b06bb0cf9f8b289e7907e81dffa diff --git a/src/test/java/net/pterodactylus/sone/Matchers.java b/src/test/java/net/pterodactylus/sone/Matchers.java index 41eb0dd..c73866e 100644 --- a/src/test/java/net/pterodactylus/sone/Matchers.java +++ b/src/test/java/net/pterodactylus/sone/Matchers.java @@ -22,6 +22,7 @@ import static java.util.regex.Pattern.compile; import java.io.IOException; import java.io.InputStream; +import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.PostReply; @@ -101,6 +102,86 @@ public class Matchers { return new PostReplyMatcher(postReplyId, postId, time, text); } + public static Matcher isAlbum(final String albumId, + final String parentAlbumId, + final String title, final String albumDescription, + final String imageId) { + return new TypeSafeDiagnosingMatcher() { + @Override + protected boolean matchesSafely(Album album, + Description mismatchDescription) { + if (!album.getId().equals(albumId)) { + mismatchDescription.appendText("ID is ") + .appendValue(album.getId()); + return false; + } + if (parentAlbumId == null) { + if (album.getParent() != null) { + mismatchDescription.appendText("has parent album"); + return false; + } + } else { + if (album.getParent() == null) { + mismatchDescription.appendText("has no parent album"); + return false; + } + if (!album.getParent().getId().equals(parentAlbumId)) { + mismatchDescription.appendText("parent album is ") + .appendValue(album.getParent().getId()); + return false; + } + } + if (!title.equals(album.getTitle())) { + mismatchDescription.appendText("has title ") + .appendValue(album.getTitle()); + return false; + } + if (!albumDescription.equals(album.getDescription())) { + mismatchDescription.appendText("has description ") + .appendValue(album.getDescription()); + return false; + } + if (imageId == null) { + if (album.getAlbumImage() != null) { + mismatchDescription.appendText("has album image"); + return false; + } + } else { + if (album.getAlbumImage() == null) { + mismatchDescription.appendText("has no album image"); + return false; + } + if (!album.getAlbumImage().getId().equals(imageId)) { + mismatchDescription.appendText("has album image ") + .appendValue(album.getAlbumImage().getId()); + return false; + } + } + return true; + } + + @Override + public void describeTo(Description description) { + description.appendText("is album ").appendValue(albumId); + if (parentAlbumId == null) { + description.appendText(", has no parent"); + } else { + description.appendText(", has parent ") + .appendValue(parentAlbumId); + } + description.appendText(", has title ").appendValue(title); + description.appendText(", has description ") + .appendValue(albumDescription); + if (imageId == null) { + description.appendText(", has no album image"); + } else { + description.appendText(", has album image ") + .appendValue(imageId); + } + } + }; + } + private static class PostMatcher extends TypeSafeDiagnosingMatcher { private final String postId;