b227625fc7bf1239a4dc6ffa397d6531b31b7c3b
[Sone.git] / src / test / java / net / pterodactylus / sone / text / FreenetLinkPartTest.java
1 /*
2  * Sone - FreenetLinkPartTest.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.containsString;
22 import static org.hamcrest.Matchers.is;
23 import static org.hamcrest.Matchers.not;
24
25 import org.junit.Test;
26
27 /**
28  * Unit test for {@link FreenetLinkPart}.
29  *
30  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31  */
32 public class FreenetLinkPartTest {
33
34         @Test
35         public void trustedAttributeIsStoredAndReturnedWhenSet() {
36                 FreenetLinkPart freenetLinkPart = new FreenetLinkPart("link", "text", true);
37                 assertThat(freenetLinkPart.isTrusted(), is(true));
38         }
39
40         @Test
41         public void trustedAttributeIsStoredAndReturnedWhenNotSet() {
42                 FreenetLinkPart freenetLinkPart = new FreenetLinkPart("link", "text", "title", false);
43                 assertThat(freenetLinkPart.isTrusted(), is(false));
44         }
45
46         @Test
47         public void hashCodeMatchesForEqualParts() {
48                 FreenetLinkPart freenetLinkPart1 = new FreenetLinkPart("link", "text", "title", false);
49                 FreenetLinkPart freenetLinkPart2 = new FreenetLinkPart("link", "text", "title", false);
50                 assertThat(freenetLinkPart1, is(freenetLinkPart2));
51                 assertThat(freenetLinkPart1.hashCode(), is(freenetLinkPart2.hashCode()));
52         }
53
54         @Test
55         public void nullDoesNotMatchAFreenetLinkPart() {
56                 FreenetLinkPart freenetLinkPart = new FreenetLinkPart("link", "text", true);
57                 assertThat(freenetLinkPart, not(is((Object) null)));
58         }
59
60         @Test
61         public void toStringContainsLinkTextAndTitle() {
62                 FreenetLinkPart freenetLinkPart = new FreenetLinkPart("<some-link>", "<some-text>", "<some-title>", true);
63                 assertThat(freenetLinkPart.toString(), containsString("<some-link>"));
64                 assertThat(freenetLinkPart.toString(), containsString("<some-text>"));
65                 assertThat(freenetLinkPart.toString(), containsString("<some-title>"));
66         }
67
68 }