2 * Sone - TrustTest.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.freenet.wot;
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;
26 import org.junit.Test;
29 * Unit test for {@link Trust}.
31 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33 public class TrustTest {
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));
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());
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()));
60 public void nullDoesNotMatchTrust() {
61 Trust trust = new Trust(5, 17, 2);
62 assertThat(trust, not(is((Object) null)));
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"));