From de6d73a2f0718ff65832859a3ef7ba4f32299327 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 11 Nov 2016 14:21:29 +0100 Subject: [PATCH] Replace most parts with Kotlin equivalents --- .../pterodactylus/sone/text/FreenetLinkPart.java | 46 --------------- .../java/net/pterodactylus/sone/text/LinkPart.java | 63 -------------------- .../java/net/pterodactylus/sone/text/Part.java | 37 ------------ .../net/pterodactylus/sone/text/PlainTextPart.java | 43 -------------- .../java/net/pterodactylus/sone/text/SonePart.java | 50 ---------------- .../pterodactylus/sone/template/RenderFilter.kt | 2 +- .../net/pterodactylus/sone/text/FreenetLinkPart.kt | 12 ++++ .../kotlin/net/pterodactylus/sone/text/LinkPart.kt | 12 ++++ .../kotlin/net/pterodactylus/sone/text/Part.kt | 11 ++++ .../net/pterodactylus/sone/text/PlainTextPart.kt | 8 +++ .../kotlin/net/pterodactylus/sone/text/SonePart.kt | 13 +++++ .../sone/text/FreenetLinkPartTest.java | 67 ---------------------- .../net/pterodactylus/sone/text/LinkPartTest.java | 62 -------------------- .../pterodactylus/sone/text/PlainTextPartTest.java | 27 --------- .../net/pterodactylus/sone/text/SonePartTest.java | 42 -------------- .../sone/text/SoneTextParserTest.java | 2 +- .../pterodactylus/sone/text/FreenetLinkPartTest.kt | 17 ++++++ .../net/pterodactylus/sone/text/LinkPartTest.kt | 17 ++++++ .../net/pterodactylus/sone/text/SonePartTest.kt | 30 ++++++++++ 19 files changed, 122 insertions(+), 439 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/sone/text/FreenetLinkPart.java delete mode 100644 src/main/java/net/pterodactylus/sone/text/LinkPart.java delete mode 100644 src/main/java/net/pterodactylus/sone/text/Part.java delete mode 100644 src/main/java/net/pterodactylus/sone/text/PlainTextPart.java delete mode 100644 src/main/java/net/pterodactylus/sone/text/SonePart.java create mode 100644 src/main/kotlin/net/pterodactylus/sone/text/FreenetLinkPart.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/text/LinkPart.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/text/Part.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/text/PlainTextPart.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/text/SonePart.kt delete mode 100644 src/test/java/net/pterodactylus/sone/text/FreenetLinkPartTest.java delete mode 100644 src/test/java/net/pterodactylus/sone/text/LinkPartTest.java delete mode 100644 src/test/java/net/pterodactylus/sone/text/PlainTextPartTest.java delete mode 100644 src/test/java/net/pterodactylus/sone/text/SonePartTest.java create mode 100644 src/test/kotlin/net/pterodactylus/sone/text/FreenetLinkPartTest.kt create mode 100644 src/test/kotlin/net/pterodactylus/sone/text/LinkPartTest.kt create mode 100644 src/test/kotlin/net/pterodactylus/sone/text/SonePartTest.kt diff --git a/src/main/java/net/pterodactylus/sone/text/FreenetLinkPart.java b/src/main/java/net/pterodactylus/sone/text/FreenetLinkPart.java deleted file mode 100644 index 7a3636c..0000000 --- a/src/main/java/net/pterodactylus/sone/text/FreenetLinkPart.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 . - */ - -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 David ‘Bombe’ Roden - */ -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; - } - -} diff --git a/src/main/java/net/pterodactylus/sone/text/LinkPart.java b/src/main/java/net/pterodactylus/sone/text/LinkPart.java deleted file mode 100644 index bbcaf8b..0000000 --- a/src/main/java/net/pterodactylus/sone/text/LinkPart.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 . - */ - -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 David ‘Bombe’ Roden - */ -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; - } - -} diff --git a/src/main/java/net/pterodactylus/sone/text/Part.java b/src/main/java/net/pterodactylus/sone/text/Part.java deleted file mode 100644 index e516f0a..0000000 --- a/src/main/java/net/pterodactylus/sone/text/Part.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 . - */ - -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 David ‘Bombe’ Roden - */ -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(); - -} diff --git a/src/main/java/net/pterodactylus/sone/text/PlainTextPart.java b/src/main/java/net/pterodactylus/sone/text/PlainTextPart.java deleted file mode 100644 index 7bdbee9..0000000 --- a/src/main/java/net/pterodactylus/sone/text/PlainTextPart.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 . - */ - -package net.pterodactylus.sone.text; - -import java.util.Objects; - -import javax.annotation.Nonnull; - -/** - * {@link Part} implementation that holds a single piece of text. - * - * @author David ‘Bombe’ Roden - */ -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; - } - -} diff --git a/src/main/java/net/pterodactylus/sone/text/SonePart.java b/src/main/java/net/pterodactylus/sone/text/SonePart.java deleted file mode 100644 index 576eb7b..0000000 --- a/src/main/java/net/pterodactylus/sone/text/SonePart.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 . - */ - -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 David ‘Bombe’ Roden - */ -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); - } - -} diff --git a/src/main/kotlin/net/pterodactylus/sone/template/RenderFilter.kt b/src/main/kotlin/net/pterodactylus/sone/template/RenderFilter.kt index 2c38e58..e9992e9 100644 --- a/src/main/kotlin/net/pterodactylus/sone/template/RenderFilter.kt +++ b/src/main/kotlin/net/pterodactylus/sone/template/RenderFilter.kt @@ -101,7 +101,7 @@ class RenderFilter(private val core: Core, private val templateContextFactory: T } 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) { diff --git a/src/main/kotlin/net/pterodactylus/sone/text/FreenetLinkPart.kt b/src/main/kotlin/net/pterodactylus/sone/text/FreenetLinkPart.kt new file mode 100644 index 0000000..3744fd7 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/text/FreenetLinkPart.kt @@ -0,0 +1,12 @@ +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) + +} diff --git a/src/main/kotlin/net/pterodactylus/sone/text/LinkPart.kt b/src/main/kotlin/net/pterodactylus/sone/text/LinkPart.kt new file mode 100644 index 0000000..7099b93 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/text/LinkPart.kt @@ -0,0 +1,12 @@ +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) + +} diff --git a/src/main/kotlin/net/pterodactylus/sone/text/Part.kt b/src/main/kotlin/net/pterodactylus/sone/text/Part.kt new file mode 100644 index 0000000..8633ec1 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/text/Part.kt @@ -0,0 +1,11 @@ +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 + +} diff --git a/src/main/kotlin/net/pterodactylus/sone/text/PlainTextPart.kt b/src/main/kotlin/net/pterodactylus/sone/text/PlainTextPart.kt new file mode 100644 index 0000000..4a495b4 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/text/PlainTextPart.kt @@ -0,0 +1,8 @@ +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 diff --git a/src/main/kotlin/net/pterodactylus/sone/text/SonePart.kt b/src/main/kotlin/net/pterodactylus/sone/text/SonePart.kt new file mode 100644 index 0000000..fd22474 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/text/SonePart.kt @@ -0,0 +1,13 @@ +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) + +} diff --git a/src/test/java/net/pterodactylus/sone/text/FreenetLinkPartTest.java b/src/test/java/net/pterodactylus/sone/text/FreenetLinkPartTest.java deleted file mode 100644 index 1aff605..0000000 --- a/src/test/java/net/pterodactylus/sone/text/FreenetLinkPartTest.java +++ /dev/null @@ -1,67 +0,0 @@ -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 David ‘Bombe’ Roden - */ -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); - } - -} diff --git a/src/test/java/net/pterodactylus/sone/text/LinkPartTest.java b/src/test/java/net/pterodactylus/sone/text/LinkPartTest.java deleted file mode 100644 index 62648a1..0000000 --- a/src/test/java/net/pterodactylus/sone/text/LinkPartTest.java +++ /dev/null @@ -1,62 +0,0 @@ -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 David ‘Bombe’ Roden - */ -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); - } - -} diff --git a/src/test/java/net/pterodactylus/sone/text/PlainTextPartTest.java b/src/test/java/net/pterodactylus/sone/text/PlainTextPartTest.java deleted file mode 100644 index 72161ab..0000000 --- a/src/test/java/net/pterodactylus/sone/text/PlainTextPartTest.java +++ /dev/null @@ -1,27 +0,0 @@ -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 David ‘Bombe’ Roden - */ -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); - } - -} diff --git a/src/test/java/net/pterodactylus/sone/text/SonePartTest.java b/src/test/java/net/pterodactylus/sone/text/SonePartTest.java deleted file mode 100644 index 589acf7..0000000 --- a/src/test/java/net/pterodactylus/sone/text/SonePartTest.java +++ /dev/null @@ -1,42 +0,0 @@ -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 David ‘Bombe’ Roden - */ -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); - } - -} diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index cec779a..e640c7d 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -372,7 +372,7 @@ public class SoneTextParserTest { 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())); diff --git a/src/test/kotlin/net/pterodactylus/sone/text/FreenetLinkPartTest.kt b/src/test/kotlin/net/pterodactylus/sone/text/FreenetLinkPartTest.kt new file mode 100644 index 0000000..fcf6e67 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/text/FreenetLinkPartTest.kt @@ -0,0 +1,17 @@ +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")) + } + +} diff --git a/src/test/kotlin/net/pterodactylus/sone/text/LinkPartTest.kt b/src/test/kotlin/net/pterodactylus/sone/text/LinkPartTest.kt new file mode 100644 index 0000000..373a848 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/text/LinkPartTest.kt @@ -0,0 +1,17 @@ +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")) + } + +} diff --git a/src/test/kotlin/net/pterodactylus/sone/text/SonePartTest.kt b/src/test/kotlin/net/pterodactylus/sone/text/SonePartTest.kt new file mode 100644 index 0000000..361bd19 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/text/SonePartTest.kt @@ -0,0 +1,30 @@ +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() + + init { + `when`(sone.profile).thenReturn(mock()) + `when`(sone.name).thenReturn("sone") + } + + private val part = SonePart(sone) + + @Test + fun textIsConstructedFromSonesNiceName() { + assertThat(part.text, `is`("sone")) + } + +} -- 2.7.4