2 * Sone - PostPartTest.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.text;
20 import static org.hamcrest.MatcherAssert.assertThat;
21 import static org.hamcrest.Matchers.is;
22 import static org.hamcrest.Matchers.not;
24 import net.pterodactylus.sone.data.Mocks;
25 import net.pterodactylus.sone.data.Post;
26 import net.pterodactylus.sone.data.Sone;
28 import org.junit.Test;
31 * Unit test for {@link PostPart}.
33 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
35 public class PostPartTest {
37 private final Mocks mocks = new Mocks();
38 private final Sone sone = mocks.mockSone("Sone").create();
39 private final Post post = mocks.mockPost(sone, "Post").withText("Text").create();
40 private final PostPart postPart = new PostPart(post);
43 public void postPartIsNotAPlainTextPart() {
44 assertThat(postPart.isPlainText(), is(false));
48 public void postPartIsNotAFreenetLink() {
49 assertThat(postPart.isFreenetLink(), is(false));
53 public void postPartCanStoreAndReturnPost() {
54 assertThat(postPart.getPost(), is(post));
58 public void postPartReturnsTextOfPost() {
59 assertThat(postPart.getText(), is(post.getText()));
63 public void postPartsAreEqualIfTheyContainTheSamePost() {
64 PostPart secondPostPart = new PostPart(post);
65 assertThat(secondPostPart, is(postPart));
69 public void postPartsWithDifferentPostsButSameTextAreNotEqual() {
70 Post secondPost = mocks.mockPost(sone, "Post2").withText(post.getText()).create();
71 PostPart secondPostPart = new PostPart(secondPost);
72 assertThat(secondPostPart, not(is(postPart)));
76 public void postPartsThatAreEqualHaveTheSameHashCode() {
77 PostPart secondPostPart = new PostPart(post);
78 assertThat(secondPostPart, is(postPart));
79 assertThat(secondPostPart.hashCode(), is(postPart.hashCode()));
83 public void nullDoesNotMatchPostPart() {
84 assertThat(postPart, not(is((Object) null)));