X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=cf8cdd2059f304141ece85f0f1daa38e683c68f7;hp=b763cd1ebf8ec54b4209aaac15229fc0fd5b42d8;hb=560bb333bdaf95bdf6cc557f2cf01494555f8631;hpb=8e313509a42a8c638fcac018dd73dd975bf9cb68
diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java
index b763cd1..cf8cdd2 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;
@@ -36,13 +38,12 @@ import net.pterodactylus.sone.database.PostProvider;
import net.pterodactylus.sone.database.SoneProvider;
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 {
@@ -213,6 +214,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]"));
@@ -406,10 +418,17 @@ 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 {
@@ -467,9 +486,10 @@ public class SoneTextParserTest {
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;
@@ -514,7 +534,7 @@ public class SoneTextParserTest {
public Post setKnown(boolean known) {
return null;
}
- });
+ };
}
@Override
@@ -531,9 +551,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;
}
}