From: David ‘Bombe’ Roden Date: Fri, 8 Nov 2013 18:03:58 +0000 (+0100) Subject: Add unit test for FreenetLinkPart. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=fe66eb7a877ef8b3093c0154c49803bc83c4b5bf;p=Sone.git Add unit test for FreenetLinkPart. --- 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("")); + } + +}