Merge branch 'release-0.9.6'
[Sone.git] / src / test / java / net / pterodactylus / sone / Matchers.java
index c1052d5..823cdf9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - Matchers.java - Copyright © 2013 David Roden
+ * Sone - Matchers.java - Copyright © 2013–2016 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -98,6 +98,10 @@ public class Matchers {
                return new PostMatcher(postId, time, text, recipient);
        }
 
+       public static Matcher<Post> isPostWithId(String postId) {
+               return new PostIdMatcher(postId);
+       }
+
        public static Matcher<PostReply> isPostReply(String postReplyId,
                        String postId, long time, String text) {
                return new PostReplyMatcher(postReplyId, postId, time, text);
@@ -105,8 +109,7 @@ public class Matchers {
 
        public static Matcher<Album> isAlbum(final String albumId,
                        final String parentAlbumId,
-                       final String title, final String albumDescription,
-                       final String imageId) {
+                       final String title, final String albumDescription) {
                return new TypeSafeDiagnosingMatcher<Album>() {
                        @Override
                        protected boolean matchesSafely(Album album,
@@ -142,22 +145,6 @@ public class Matchers {
                                                        .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;
                        }
 
@@ -173,12 +160,6 @@ public class Matchers {
                                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);
-                               }
                        }
                };
        }
@@ -312,6 +293,31 @@ public class Matchers {
 
        }
 
+       private static class PostIdMatcher extends TypeSafeDiagnosingMatcher<Post> {
+
+               private final String id;
+
+               private PostIdMatcher(String id) {
+                       this.id = id;
+               }
+
+               @Override
+               protected boolean matchesSafely(Post item,
+                               Description mismatchDescription) {
+                       if (!item.getId().equals(id)) {
+                               mismatchDescription.appendText("post has ID ").appendValue(item.getId());
+                               return false;
+                       }
+                       return true;
+               }
+
+               @Override
+               public void describeTo(Description description) {
+                       description.appendText("post with ID ").appendValue(id);
+               }
+
+       }
+
        private static class PostReplyMatcher
                        extends TypeSafeDiagnosingMatcher<PostReply> {