X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=b630ac5f257abbd1e00aa3523e0278b45cc4fad2;hp=2c04b231f7debef0039cd8e60f285a774e94fca5;hb=662bcd45433c0ab480ad0e52f3e72e9e886bdfc6;hpb=f4f5fb752ff9aff0235a907e170c6961576562f6 diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index 2c04b23..b630ac5 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–2013 David Roden + * Sone - SoneTextParserTest.java - Copyright © 2011–2015 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 @@ -22,13 +22,14 @@ import java.io.StringReader; import java.util.Arrays; import java.util.Collection; -import com.google.common.base.Optional; - -import junit.framework.TestCase; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.data.SoneImpl; +import net.pterodactylus.sone.data.impl.IdOnlySone; import net.pterodactylus.sone.database.SoneProvider; +import com.google.common.base.Function; +import com.google.common.base.Optional; +import junit.framework.TestCase; + /** * JUnit test case for {@link SoneTextParser}. * @@ -52,17 +53,17 @@ public class SoneTextParserTest extends TestCase { Iterable parts; /* check basic operation. */ - parts = soneTextParser.parse(null, new StringReader("Test.")); + parts = soneTextParser.parse(null, "Test."); assertNotNull("Parts", parts); assertEquals("Part Text", "Test.", convertText(parts, PlainTextPart.class)); /* check empty lines at start and end. */ - parts = soneTextParser.parse(null, new StringReader("\nTest.\n\n")); + parts = soneTextParser.parse(null, "\nTest.\n\n"); assertNotNull("Parts", parts); assertEquals("Part Text", "Test.", convertText(parts, PlainTextPart.class)); /* check duplicate empty lines in the text. */ - parts = soneTextParser.parse(null, new StringReader("\nTest.\n\n\nTest.")); + parts = soneTextParser.parse(null, "\nTest.\n\n\nTest."); assertNotNull("Parts", parts); assertEquals("Part Text", "Test.\n\nTest.", convertText(parts, PlainTextPart.class)); } @@ -79,17 +80,17 @@ public class SoneTextParserTest extends TestCase { Iterable parts; /* check basic links. */ - parts = soneTextParser.parse(null, new StringReader("KSK@gpl.txt")); + parts = soneTextParser.parse(null, "KSK@gpl.txt"); assertNotNull("Parts", parts); assertEquals("Part Text", "[KSK@gpl.txt|gpl.txt|gpl.txt]", convertText(parts, FreenetLinkPart.class)); /* check embedded links. */ - parts = soneTextParser.parse(null, new StringReader("Link is KSK@gpl.txt\u200b.")); + parts = soneTextParser.parse(null, "Link is KSK@gpl.txt\u200b."); assertNotNull("Parts", parts); assertEquals("Part Text", "Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\u200b.", convertText(parts, PlainTextPart.class, FreenetLinkPart.class)); /* check embedded links and line breaks. */ - parts = soneTextParser.parse(null, new StringReader("Link is KSK@gpl.txt\nKSK@test.dat\n")); + parts = soneTextParser.parse(null, "Link is KSK@gpl.txt\nKSK@test.dat\n"); assertNotNull("Parts", parts); assertEquals("Part Text", "Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\n[KSK@test.dat|test.dat|test.dat]", convertText(parts, PlainTextPart.class, FreenetLinkPart.class)); } @@ -106,7 +107,7 @@ public class SoneTextParserTest extends TestCase { Iterable parts; /* check basic links. */ - parts = soneTextParser.parse(null, new StringReader("Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff.")); + parts = soneTextParser.parse(null, "Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff."); assertNotNull("Parts", parts); assertEquals("Part Text", "Some text.\n\nLink to [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] and stuff.", convertText(parts, PlainTextPart.class, SonePart.class)); } @@ -124,7 +125,7 @@ public class SoneTextParserTest extends TestCase { Iterable parts; /* check empty http links. */ - parts = soneTextParser.parse(null, new StringReader("Some text. Empty link: http:// – nice!")); + parts = soneTextParser.parse(null, "Some text. Empty link: http:// – nice!"); assertNotNull("Parts", parts); assertEquals("Part Text", "Some text. Empty link: http:// – nice!", convertText(parts, PlainTextPart.class)); } @@ -181,21 +182,22 @@ public class SoneTextParserTest extends TestCase { */ private static class TestSoneProvider implements SoneProvider { + @Override + public Function> soneLoader() { + return new Function>() { + @Override + public Optional apply(String soneId) { + return getSone(soneId); + } + }; + } + /** * {@inheritDoc} */ @Override public Optional getSone(final String soneId) { - return Optional.of(new SoneImpl(soneId, false) { - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return soneId; - } - }); + return Optional.of(new IdOnlySone(soneId)); } /**