X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2FMatchers.java;h=41eb0dddbc925631f1773b9e8d99b5c44783fab9;hp=14a8a008b07417f5c3389ad0670b34c61d472eda;hb=fdc519da8a4d5c994c3b2233fc049e3be728bb76;hpb=11f3457415c9122b5d11840d24186971af28add9 diff --git a/src/test/java/net/pterodactylus/sone/Matchers.java b/src/test/java/net/pterodactylus/sone/Matchers.java index 14a8a00..41eb0dd 100644 --- a/src/test/java/net/pterodactylus/sone/Matchers.java +++ b/src/test/java/net/pterodactylus/sone/Matchers.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStream; import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.PostReply; import com.google.common.base.Optional; import org.hamcrest.Description; @@ -95,6 +96,11 @@ public class Matchers { return new PostMatcher(postId, time, text, recipient); } + public static Matcher isPostReply(String postReplyId, + String postId, long time, String text) { + return new PostReplyMatcher(postReplyId, postId, time, text); + } + private static class PostMatcher extends TypeSafeDiagnosingMatcher { private final String postId; @@ -162,4 +168,56 @@ public class Matchers { } + private static class PostReplyMatcher + extends TypeSafeDiagnosingMatcher { + + private final String postReplyId; + private final String postId; + private final long time; + private final String text; + + private PostReplyMatcher(String postReplyId, String postId, long time, + String text) { + this.postReplyId = postReplyId; + this.postId = postId; + this.time = time; + this.text = text; + } + + @Override + protected boolean matchesSafely(PostReply postReply, + Description mismatchDescription) { + if (!postReply.getId().equals(postReplyId)) { + mismatchDescription.appendText("is post reply ") + .appendValue(postReply.getId()); + return false; + } + if (!postReply.getPostId().equals(postId)) { + mismatchDescription.appendText("is reply to ") + .appendValue(postReply.getPostId()); + return false; + } + if (postReply.getTime() != time) { + mismatchDescription.appendText("is created at @").appendValue( + postReply.getTime()); + return false; + } + if (!postReply.getText().equals(text)) { + mismatchDescription.appendText("says ") + .appendValue(postReply.getText()); + return false; + } + return true; + } + + @Override + public void describeTo(Description description) { + description.appendText("is post reply ").appendValue(postReplyId); + description.appendText(", replies to post ").appendValue(postId); + description.appendText(", is created at @").appendValue(time); + description.appendText(", says ").appendValue(text); + } + + } + }