X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=e763a20959bad2c271e46c2a5e31149cde8d24d2;hp=940c1577e58bf3c39aa3b2ced5b45dae0915ff87;hb=179e7da4d8d8a474d0b622d60b5f5d32d6ab4052;hpb=a21cf1224cebf99f3210883efbf4afb9bd8da87c diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index 940c157..e763a20 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -1,5 +1,5 @@ /* - * Sone - SoneTextParserTest.java - Copyright © 2011–2016 David Roden + * Sone - SoneTextParserTest.java - Copyright © 2011–2019 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 @@ -26,20 +26,21 @@ import static org.hamcrest.Matchers.notNullValue; import java.io.IOException; import java.util.Collection; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.impl.IdOnlySone; import net.pterodactylus.sone.database.PostProvider; import net.pterodactylus.sone.database.SoneProvider; -import com.google.common.base.Function; import com.google.common.base.Optional; +import kotlin.jvm.functions.Function1; import org.junit.Test; /** * JUnit test case for {@link SoneTextParser}. - * - * @author David ‘Bombe’ Roden */ public class SoneTextParserTest { @@ -210,6 +211,17 @@ public class SoneTextParserTest { } @Test + public void sskWithoutDocumentNameIsParsedCorrectly() { + Iterable parts = soneTextParser.parse( + "SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8", + null); + assertThat("Part Text", convertText(parts), + is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8|" + + "SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8|" + + "SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU]")); + } + + @Test public void sskLinkWithoutContextIsNotTrusted() { Iterable parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", null); assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test]")); @@ -405,27 +417,24 @@ public class SoneTextParserTest { /** * Mock Sone provider. - * - * @author David ‘Bombe’ Roden */ private static class TestSoneProvider implements SoneProvider { + @Nonnull @Override - public Function> soneLoader() { - return new Function>() { + public Function1 getSoneLoader() { + return new Function1() { @Override - public Optional apply(String soneId) { + public Sone invoke(String soneId) { return getSone(soneId); } }; } - /** - * {@inheritDoc} - */ + @Nullable @Override - public Optional getSone(final String soneId) { - return Optional.of(new IdOnlySone(soneId)); + public Sone getSone(final String soneId) { + return new IdOnlySone(soneId); } /** @@ -457,17 +466,18 @@ public class SoneTextParserTest { private static class AbsentSoneProvider extends TestSoneProvider { @Override - public Optional getSone(String soneId) { - return Optional.absent(); + public Sone getSone(String soneId) { + return null; } } private static class TestPostProvider implements PostProvider { + @Nullable @Override - public Optional getPost(final String postId) { - return Optional.of(new Post() { + public Post getPost(@Nonnull final String postId) { + return new Post() { @Override public String getId() { return postId; @@ -512,7 +522,7 @@ public class SoneTextParserTest { public Post setKnown(boolean known) { return null; } - }); + }; } @Override @@ -529,9 +539,10 @@ public class SoneTextParserTest { private static class AbsentPostProvider extends TestPostProvider { + @Nullable @Override - public Optional getPost(String postId) { - return Optional.absent(); + public Post getPost(@Nonnull String postId) { + return null; } }