Add tests for isFreenetLink() and isPlainText().
[Sone.git] / src / test / java / net / pterodactylus / sone / text / PostPartTest.java
1 /*
2  * Sone - PostPartTest.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.text;
19
20 import static org.hamcrest.MatcherAssert.assertThat;
21 import static org.hamcrest.Matchers.is;
22 import static org.hamcrest.Matchers.not;
23
24 import net.pterodactylus.sone.data.Mocks;
25 import net.pterodactylus.sone.data.Post;
26 import net.pterodactylus.sone.data.Sone;
27
28 import org.junit.Test;
29
30 /**
31  * Unit test for {@link PostPart}.
32  *
33  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34  */
35 public class PostPartTest {
36
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);
41
42         @Test
43         public void postPartIsNotAPlainTextPart() {
44                 assertThat(postPart.isPlainText(), is(false));
45         }
46
47         @Test
48         public void postPartIsNotAFreenetLink() {
49                 assertThat(postPart.isFreenetLink(), is(false));
50         }
51
52         @Test
53         public void postPartCanStoreAndReturnPost() {
54                 assertThat(postPart.getPost(), is(post));
55         }
56
57         @Test
58         public void postPartReturnsTextOfPost() {
59                 assertThat(postPart.getText(), is(post.getText()));
60         }
61
62         @Test
63         public void postPartsAreEqualIfTheyContainTheSamePost() {
64                 PostPart secondPostPart = new PostPart(post);
65                 assertThat(secondPostPart, is(postPart));
66         }
67
68         @Test
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)));
73         }
74
75         @Test
76         public void postPartsThatAreEqualHaveTheSameHashCode() {
77                 PostPart secondPostPart = new PostPart(post);
78                 assertThat(secondPostPart, is(postPart));
79                 assertThat(secondPostPart.hashCode(), is(postPart.hashCode()));
80         }
81
82         @Test
83         public void nullDoesNotMatchPostPart() {
84                 assertThat(postPart, not(is((Object) null)));
85         }
86
87 }