From fe66eb7a877ef8b3093c0154c49803bc83c4b5bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 8 Nov 2013 19:03:58 +0100 Subject: [PATCH] Add unit test for FreenetLinkPart. --- .../sone/text/FreenetLinkPartTest.java | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/test/java/net/pterodactylus/sone/text/FreenetLinkPartTest.java diff --git a/src/test/java/net/pterodactylus/sone/text/FreenetLinkPartTest.java b/src/test/java/net/pterodactylus/sone/text/FreenetLinkPartTest.java new file mode 100644 index 0000000..b227625 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/text/FreenetLinkPartTest.java @@ -0,0 +1,68 @@ +/* + * Sone - FreenetLinkPartTest.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.text; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; + +import org.junit.Test; + +/** + * Unit test for {@link FreenetLinkPart}. + * + * @author David ‘Bombe’ Roden + */ +public class FreenetLinkPartTest { + + @Test + public void trustedAttributeIsStoredAndReturnedWhenSet() { + FreenetLinkPart freenetLinkPart = new FreenetLinkPart("link", "text", true); + assertThat(freenetLinkPart.isTrusted(), is(true)); + } + + @Test + public void trustedAttributeIsStoredAndReturnedWhenNotSet() { + FreenetLinkPart freenetLinkPart = new FreenetLinkPart("link", "text", "title", false); + assertThat(freenetLinkPart.isTrusted(), is(false)); + } + + @Test + public void hashCodeMatchesForEqualParts() { + FreenetLinkPart freenetLinkPart1 = new FreenetLinkPart("link", "text", "title", false); + FreenetLinkPart freenetLinkPart2 = new FreenetLinkPart("link", "text", "title", false); + assertThat(freenetLinkPart1, is(freenetLinkPart2)); + assertThat(freenetLinkPart1.hashCode(), is(freenetLinkPart2.hashCode())); + } + + @Test + public void nullDoesNotMatchAFreenetLinkPart() { + FreenetLinkPart freenetLinkPart = new FreenetLinkPart("link", "text", true); + assertThat(freenetLinkPart, not(is((Object) null))); + } + + @Test + public void toStringContainsLinkTextAndTitle() { + FreenetLinkPart freenetLinkPart = new FreenetLinkPart("", "", "", true); + assertThat(freenetLinkPart.toString(), containsString("")); + assertThat(freenetLinkPart.toString(), containsString("")); + assertThat(freenetLinkPart.toString(), containsString("")); + } + +} -- 2.7.4