X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=69cc658b5b918b85000eeb54d3127032075410a3;hb=c84755453de2f6a59fc20114aff832b94c8ecd83;hp=0daf94444d247b8cfefa74532a5e3ab941604036;hpb=ffd92ca2374c0b2218e583d02e0bdd24b8c110ae;p=Sone.git
diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java
index 0daf944..69cc658 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
@@ -17,7 +17,9 @@
package net.pterodactylus.sone.text;
+import static com.google.inject.Guice.createInjector;
import static java.lang.String.format;
+import static net.pterodactylus.sone.test.GuiceKt.supply;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isIn;
@@ -26,20 +28,22 @@ 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 com.google.inject.Injector;
+import kotlin.jvm.functions.Function1;
import org.junit.Test;
/**
* JUnit test case for {@link SoneTextParser}.
- *
- * @author David âBombeâ Roden
*/
public class SoneTextParserTest {
@@ -204,6 +208,23 @@ public class SoneTextParserTest {
}
@Test
+ public void invalidSskAndUskLinkIsParsedAsText() {
+ Iterable parts = soneTextParser.parse("SSK@a USK@a", null);
+ assertThat("Part Text", convertText(parts), is("SSK@a USK@a"));
+ }
+
+ @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]"));
@@ -286,6 +307,12 @@ public class SoneTextParserTest {
}
@Test
+ public void uskLinkWithFilenameShowsTheFilename() {
+ Iterable parts = soneTextParser.parse("Some link (USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0/images/image.jpg). Nice", null);
+ assertThat("Part Text", convertText(parts), is("Some link ([USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0/images/image.jpg|USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0/images/image.jpg|image.jpg]). Nice"));
+ }
+
+ @Test
public void httpLinkWithOpenedAndClosedParensEndsAtNextClosingParen() {
Iterable parts = soneTextParser.parse("Some text (and a link: http://example.sone/abc_(def)) â nice!", null);
assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text (and a link: [http://example.sone/abc_(def)|http://example.sone/abc_(def)|example.sone/abc_(def)]) â nice!"));
@@ -397,29 +424,35 @@ public class SoneTextParserTest {
return text.toString();
}
+ @Test
+ public void parserCanBeCreatedByGuice() {
+ Injector injector = createInjector(
+ supply(SoneProvider.class).byMock(),
+ supply(PostProvider.class).byMock()
+ );
+ assertThat(injector.getInstance(SoneTextParser.class), notNullValue());
+ }
+
/**
* 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);
}
/**
@@ -451,17 +484,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;
@@ -506,7 +540,7 @@ public class SoneTextParserTest {
public Post setKnown(boolean known) {
return null;
}
- });
+ };
}
@Override
@@ -523,9 +557,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;
}
}