e26f52478eb6c55beac0e5a475a22ef5bd431f23
[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 postPartCanStoreAndReturnPost() {
44                 assertThat(postPart.getPost(), is(post));
45         }
46
47         @Test
48         public void postPartReturnsTextOfPost() {
49                 assertThat(postPart.getText(), is(post.getText()));
50         }
51
52         @Test
53         public void postPartsAreEqualIfTheyContainTheSamePost() {
54                 PostPart secondPostPart = new PostPart(post);
55                 assertThat(secondPostPart, is(postPart));
56         }
57
58         @Test
59         public void postPartsWithDifferentPostsButSameTextAreNotEqual() {
60                 Post secondPost = mocks.mockPost(sone, "Post2").withText(post.getText()).create();
61                 PostPart secondPostPart = new PostPart(secondPost);
62                 assertThat(secondPostPart, not(is(postPart)));
63         }
64
65         @Test
66         public void postPartsThatAreEqualHaveTheSameHashCode() {
67                 PostPart secondPostPart = new PostPart(post);
68                 assertThat(secondPostPart, is(postPart));
69                 assertThat(secondPostPart.hashCode(), is(postPart.hashCode()));
70         }
71
72         @Test
73         public void nullDoesNotMatchPostPart() {
74                 assertThat(postPart, not(is((Object) null)));
75         }
76
77 }