Add class with Sone-specific matchers.
[Sone.git] / src / test / java / net / pterodactylus / sone / freenet / wot / TrustTest.java
1 /*
2  * Sone - TrustTest.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.freenet.wot;
19
20 import static net.pterodactylus.sone.Matchers.matches;
21 import static org.hamcrest.MatcherAssert.assertThat;
22 import static org.hamcrest.Matchers.is;
23 import static org.hamcrest.Matchers.not;
24 import static org.hamcrest.Matchers.nullValue;
25
26 import org.junit.Test;
27
28 /**
29  * Unit test for {@link Trust}.
30  *
31  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32  */
33 public class TrustTest {
34
35         @Test
36         public void trustCanBeCreated() {
37                 Trust trust = new Trust(5, 17, 2);
38                 assertThat(trust.getExplicit(), is(5));
39                 assertThat(trust.getImplicit(), is(17));
40                 assertThat(trust.getDistance(), is(2));
41         }
42
43         @Test
44         public void nullTrustCanBeCreated() {
45                 Trust trust = new Trust(null, null, null);
46                 assertThat(trust.getExplicit(), nullValue());
47                 assertThat(trust.getImplicit(), nullValue());
48                 assertThat(trust.getDistance(), nullValue());
49         }
50
51         @Test
52         public void equalTrustsHaveTheSameHashCode() {
53                 Trust trust1 = new Trust(5, 17, 2);
54                 Trust trust2 = new Trust(5, 17, 2);
55                 assertThat(trust1, is(trust2));
56                 assertThat(trust1.hashCode(), is(trust2.hashCode()));
57         }
58
59         @Test
60         public void nullDoesNotMatchTrust() {
61                 Trust trust = new Trust(5, 17, 2);
62                 assertThat(trust, not(is((Object) null)));
63         }
64
65         @Test
66         public void toStringContainsTheThreeValues() {
67                 String trustString = new Trust(5, 17, 2).toString();
68                 assertThat(trustString, matches("\\b5\\b"));
69                 assertThat(trustString, matches("\\b17\\b"));
70                 assertThat(trustString, matches("\\b2\\b"));
71         }
72
73 }