+++ /dev/null
-/*
- * Sone - FreenetLinkPart.java - Copyright © 2011–2016 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.text;
-
-import javax.annotation.Nonnull;
-
-/**
- * {@link LinkPart} implementation that stores an additional attribute: if the
- * link is an SSK or USK link and the post was created by an identity that owns
- * the keyspace in question.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class FreenetLinkPart extends LinkPart {
-
- private final boolean trusted;
-
- public FreenetLinkPart(@Nonnull String link, @Nonnull String text, boolean trusted) {
- this(link, text, link, trusted);
- }
-
- public FreenetLinkPart(@Nonnull String link, @Nonnull String text, @Nonnull String title, boolean trusted) {
- super(link, text, title);
- this.trusted = trusted;
- }
-
- public boolean isTrusted() {
- return trusted;
- }
-
-}
+++ /dev/null
-/*
- * Sone - LinkPart.java - Copyright © 2011–2016 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.text;
-
-import java.util.Objects;
-
-import javax.annotation.Nonnull;
-
-/**
- * {@link Part} implementation that can hold a link. A link contains of three
- * attributes: the link itself, the text that is shown instead of the link, and
- * an explanatory text that can be displayed e.g. as a tooltip.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class LinkPart implements Part {
-
- private final String link;
- private final String text;
- private final String title;
-
- public LinkPart(@Nonnull String link, @Nonnull String text) {
- this(link, text, link);
- }
-
- public LinkPart(@Nonnull String link, @Nonnull String text, @Nonnull String title) {
- this.link = Objects.requireNonNull(link);
- this.text = Objects.requireNonNull(text);
- this.title = Objects.requireNonNull(title);
- }
-
- @Nonnull
- public String getLink() {
- return link;
- }
-
- @Nonnull
- public String getTitle() {
- return title;
- }
-
- @Override
- @Nonnull
- public String getText() {
- return text;
- }
-
-}
+++ /dev/null
-/*
- * Sone - Part.java - Copyright © 2010–2016 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.text;
-
-/**
- * A part is a single piece of information that can be displayed as a single
- * element. How the part is displayed is not part of the {@code Part}
- * specification.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public interface Part {
-
- /**
- * Returns the text contained in this part. This should return plain text
- * without any format information.
- *
- * @return The plain text of this part
- */
- public String getText();
-
-}
+++ /dev/null
-/*
- * Sone - PlainTextPart.java - Copyright © 2011–2016 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.text;
-
-import java.util.Objects;
-
-import javax.annotation.Nonnull;
-
-/**
- * {@link Part} implementation that holds a single piece of text.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class PlainTextPart implements Part {
-
- private final String text;
-
- public PlainTextPart(@Nonnull String text) {
- this.text = Objects.requireNonNull(text);
- }
-
- @Override
- @Nonnull
- public String getText() {
- return text;
- }
-
-}
+++ /dev/null
-/*
- * Sone - SonePart.java - Copyright © 2011–2016 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.text;
-
-import java.util.Objects;
-
-import javax.annotation.Nonnull;
-
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.template.SoneAccessor;
-
-/**
- * {@link Part} implementation that stores a reference to a {@link Sone}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class SonePart implements Part {
-
- private final Sone sone;
-
- public SonePart(@Nonnull Sone sone) {
- this.sone = Objects.requireNonNull(sone);
- }
-
- @Nonnull
- public Sone getSone() {
- return sone;
- }
-
- @Override
- public String getText() {
- return SoneAccessor.getNiceName(sone);
- }
-
-}
}
private fun render(writer: Writer, freenetLinkPart: FreenetLinkPart) {
- renderLink(writer, "/${freenetLinkPart.link}", freenetLinkPart.text, freenetLinkPart.title, if (freenetLinkPart.isTrusted) "freenet-trusted" else "freenet")
+ renderLink(writer, "/${freenetLinkPart.link}", freenetLinkPart.text, freenetLinkPart.title, if (freenetLinkPart.trusted) "freenet-trusted" else "freenet")
}
private fun render(writer: Writer, linkPart: LinkPart) {
--- /dev/null
+package net.pterodactylus.sone.text
+
+/**
+ * [LinkPart] implementation that stores an additional attribute: if the
+ * link is an SSK or USK link and the post was created by an identity that owns
+ * the keyspace in question.
+ */
+data class FreenetLinkPart(val link: String, override val text: String, val title: String, val trusted: Boolean) : Part {
+
+ constructor(link: String, text: String, trusted: Boolean) : this(link, text, link, trusted)
+
+}
--- /dev/null
+package net.pterodactylus.sone.text
+
+/**
+ * {@link Part} implementation that can hold a link. A link contains of three
+ * attributes: the link itself, the text that is shown instead of the link, and
+ * an explanatory text that can be displayed e.g. as a tooltip.
+ */
+data class LinkPart(val link: String, override val text: String, val title: String) : Part {
+
+ constructor(link: String, text: String) : this(link, text, link)
+
+}
--- /dev/null
+package net.pterodactylus.sone.text
+
+/**
+ * A part is a single piece of information that can be displayed as a single
+ * element. How the part is displayed is not part of the [Part] specification.
+ */
+interface Part {
+
+ val text: String
+
+}
--- /dev/null
+package net.pterodactylus.sone.text
+
+/**
+ * [Part] implementation that holds a single piece of text.
+ *
+ * @author [David Roden](mailto:d.roden@emetriq.com)
+ */
+data class PlainTextPart(override val text: String) : Part
--- /dev/null
+package net.pterodactylus.sone.text
+
+import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.template.SoneAccessor
+
+/**
+ * [Part] implementation that stores a reference to a [Sone].
+ */
+data class SonePart(val sone: Sone) : Part {
+
+ override val text: String = SoneAccessor.getNiceName(sone)
+
+}
+++ /dev/null
-package net.pterodactylus.sone.text;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
-import org.junit.Test;
-
-/**
- * Unit test for {@link FreenetLinkPart}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class FreenetLinkPartTest {
-
- private final FreenetLinkPart part = new FreenetLinkPart("link", "text", "title", true);
-
- @Test
- public void linkIsRetainedCorrectly() {
- assertThat(part.getLink(), is("link"));
- }
-
- @Test
- public void textIsRetainedCorrectly() {
- assertThat(part.getText(), is("text"));
- }
-
- @Test
- public void titleIsRetainedCorrectly() {
- assertThat(part.getTitle(), is("title"));
- }
-
- @Test
- public void trustedIsRetainedCorrectly() {
- assertThat(part.isTrusted(), is(true));
- }
-
- @Test
- public void linkIsUsedAsTitleIfNoTextIsGiven() {
- assertThat(new FreenetLinkPart("link", "text", true).getTitle(), is("link"));
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForLink() {
- new FreenetLinkPart(null, "text", "title", true);
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForText() {
- new FreenetLinkPart("link", null, "title", true);
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForLinkInSecondaryConstructor() {
- new FreenetLinkPart(null, "text", true);
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForTextInSecondaryConstructor() {
- new FreenetLinkPart("link", null, true);
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForTitle() {
- new FreenetLinkPart("link", "text", null, true);
- }
-
-}
+++ /dev/null
-package net.pterodactylus.sone.text;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
-import org.junit.Test;
-
-/**
- * Unit test for {@link LinkPart}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class LinkPartTest {
-
- private final LinkPart part = new LinkPart("link", "text", "title");
-
- @Test
- public void linkIsRetainedCorrectly() {
- assertThat(part.getLink(), is("link"));
- }
-
- @Test
- public void textIsRetainedCorrectly() {
- assertThat(part.getText(), is("text"));
- }
-
- @Test
- public void titleIsRetainedCorrectly() {
- assertThat(part.getTitle(), is("title"));
- }
-
- @Test
- public void linkIsUsedAsTitleIfNoTitleIsGiven() {
- assertThat(new LinkPart("link", "text").getTitle(), is("link"));
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForLink() {
- new LinkPart(null, "text", "title");
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForText() {
- new LinkPart("link", null, "title");
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForLinkInSecondaryConstructor() {
- new LinkPart(null, "text");
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForTextInSecondaryConstructor() {
- new LinkPart("link", null);
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForTitle() {
- new LinkPart("link", "text", null);
- }
-
-}
+++ /dev/null
-package net.pterodactylus.sone.text;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
-import org.junit.Test;
-
-/**
- * Unit test for {@link PlainTextPart}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class PlainTextPartTest {
-
- private final PlainTextPart part = new PlainTextPart("text");
-
- @Test
- public void textIsRetainedCorrectly() {
- assertThat(part.getText(), is("text"));
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForText() {
- new PlainTextPart(null);
- }
-
-}
+++ /dev/null
-package net.pterodactylus.sone.text;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import net.pterodactylus.sone.data.Profile;
-import net.pterodactylus.sone.data.Sone;
-
-import org.hamcrest.MatcherAssert;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-/**
- * Unit test for {@link SonePart}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class SonePartTest {
-
- private final Sone sone = mock(Sone.class);
- private final SonePart part = new SonePart(sone);
-
- @Test
- public void soneIsRetainedCorrectly() {
- assertThat(part.getSone(), is(sone));
- }
-
- @Test
- public void textIsConstructedFromSonesNiceName() {
- when(sone.getProfile()).thenReturn(mock(Profile.class));
- when(sone.getName()).thenReturn("sone");
- assertThat(part.getText(), is("sone"));
- }
-
- @Test(expected = NullPointerException.class)
- public void nullIsNotAllowedForSone() {
- new SonePart(null);
- }
-
-}
text.append(((PlainTextPart) part).getText());
} else if (part instanceof FreenetLinkPart) {
FreenetLinkPart freenetLinkPart = (FreenetLinkPart) part;
- text.append('[').append(freenetLinkPart.getLink()).append('|').append(freenetLinkPart.isTrusted() ? "trusted|" : "").append(freenetLinkPart.getTitle()).append('|').append(freenetLinkPart.getText()).append(']');
+ text.append('[').append(freenetLinkPart.getLink()).append('|').append(freenetLinkPart.getTrusted() ? "trusted|" : "").append(freenetLinkPart.getTitle()).append('|').append(freenetLinkPart.getText()).append(']');
} else if (part instanceof FreemailPart) {
FreemailPart freemailPart = (FreemailPart) part;
text.append(format("[Freemail|%s|%s|%s]", freemailPart.getEmailLocalPart(), freemailPart.getFreemailId(), freemailPart.getIdentityId()));
--- /dev/null
+package net.pterodactylus.sone.text
+
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.`is`
+import org.junit.Test
+
+/**
+ * Unit test for [FreenetLinkPart].
+ */
+class FreenetLinkPartTest {
+
+ @Test
+ fun linkIsUsedAsTitleIfNoTextIsGiven() {
+ assertThat(FreenetLinkPart("link", "text", true).title, `is`("link"))
+ }
+
+}
--- /dev/null
+package net.pterodactylus.sone.text
+
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.`is`
+import org.junit.Test
+
+/**
+ * Unit test for [LinkPart].
+ */
+class LinkPartTest {
+
+ @Test
+ fun linkIsUsedAsTitleIfNoTitleIsGiven() {
+ assertThat(LinkPart("link", "text").title, `is`("link"))
+ }
+
+}
--- /dev/null
+package net.pterodactylus.sone.text
+
+import net.pterodactylus.sone.data.Profile
+import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.test.mock
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.`is`
+import org.junit.Test
+import org.mockito.Mockito.`when`
+
+/**
+ * Unit test for [SonePart].
+ */
+class SonePartTest {
+
+ private val sone = mock<Sone>()
+
+ init {
+ `when`(sone.profile).thenReturn(mock<Profile>())
+ `when`(sone.name).thenReturn("sone")
+ }
+
+ private val part = SonePart(sone)
+
+ @Test
+ fun textIsConstructedFromSonesNiceName() {
+ assertThat<String>(part.text, `is`<String>("sone"))
+ }
+
+}