X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=b8d2fb4f0bfc1b7784fceaf5142b532d6805e4fd;hb=f4dd3d176c5732a7e2111f37cdbb4ea6c83aaf46;hp=1161b8da0569eef8d64969a3301f4a2a10a6e3bb;hpb=72413a87b9ac2eb1ea7ec8cfa37cd3ca5d3e5f8b;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 1161b8d..b8d2fb4 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -40,88 +40,80 @@ import org.junit.Test; */ public class SoneTextParserTest { + private final SoneTextParser soneTextParser = new SoneTextParser(null, null); + @SuppressWarnings("static-method") @Test public void testPlainText() throws IOException { - SoneTextParser soneTextParser = new SoneTextParser(null, null); - Iterable parts; - /* check basic operation. */ - parts = soneTextParser.parse("Test.", null); + Iterable parts = soneTextParser.parse("Test.", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Test.", is(convertText(parts, PlainTextPart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Test.")); /* check empty lines at start and end. */ parts = soneTextParser.parse("\nTest.\n\n", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Test.", is(convertText(parts, PlainTextPart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Test.")); /* check duplicate empty lines in the text. */ parts = soneTextParser.parse("\nTest.\n\n\nTest.", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Test.\n\nTest.", is(convertText(parts, PlainTextPart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Test.\n\nTest.")); } @SuppressWarnings("static-method") @Test public void testKSKLinks() throws IOException { - SoneTextParser soneTextParser = new SoneTextParser(null, null); - Iterable parts; - /* check basic links. */ - parts = soneTextParser.parse("KSK@gpl.txt", null); + Iterable parts = soneTextParser.parse("KSK@gpl.txt", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "[KSK@gpl.txt|gpl.txt|gpl.txt]", is(convertText(parts, FreenetLinkPart.class))); + assertThat("Part Text", convertText(parts, FreenetLinkPart.class), is("[KSK@gpl.txt|gpl.txt|gpl.txt]")); /* check embedded links. */ parts = soneTextParser.parse("Link is KSK@gpl.txt\u200b.", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\u200b.", is(convertText(parts, PlainTextPart.class, FreenetLinkPart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class, FreenetLinkPart.class), is("Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\u200b.")); /* check embedded links and line breaks. */ parts = soneTextParser.parse("Link is KSK@gpl.txt\nKSK@test.dat\n", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\n[KSK@test.dat|test.dat|test.dat]", is(convertText(parts, PlainTextPart.class, FreenetLinkPart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class, FreenetLinkPart.class), is("Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\n[KSK@test.dat|test.dat|test.dat]")); } @SuppressWarnings({ "synthetic-access", "static-method" }) @Test public void testEmptyLinesAndSoneLinks() throws IOException { SoneTextParser soneTextParser = new SoneTextParser(new TestSoneProvider(), null); - Iterable parts; /* check basic links. */ - parts = soneTextParser.parse("Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff.", null); + Iterable parts = soneTextParser.parse("Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff.", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Some text.\n\nLink to [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] and stuff.", is(convertText(parts, PlainTextPart.class, SonePart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class, SonePart.class), is("Some text.\n\nLink to [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] and stuff.")); } @SuppressWarnings({ "synthetic-access", "static-method" }) @Test public void testEmpyHttpLinks() throws IOException { SoneTextParser soneTextParser = new SoneTextParser(new TestSoneProvider(), null); - Iterable parts; /* check empty http links. */ - parts = soneTextParser.parse("Some text. Empty link: http:// – nice!", null); + Iterable parts = soneTextParser.parse("Some text. Empty link: http:// – nice!", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Some text. Empty link: http:// – nice!", is(convertText(parts, PlainTextPart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Some text. Empty link: http:// – nice!")); } @Test public void httpLinkWithoutParensEndsAtNextClosingParen() { - SoneTextParser soneTextParser = new SoneTextParser(null, null); Iterable parts = soneTextParser.parse("Some text (and a link: http://example.sone/abc) – nice!", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Some text (and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]) – nice!", is(convertText(parts, PlainTextPart.class, LinkPart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text (and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]) – nice!")); } @Test public void httpLinkWithOpenedAndClosedParensEndsAtNextClosingParen() { - SoneTextParser soneTextParser = new SoneTextParser(null, null); Iterable parts = soneTextParser.parse("Some text (and a link: http://example.sone/abc_(def)) – nice!", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Some text (and a link: [http://example.sone/abc_(def)|example.sone/abc_(def)|example.sone/abc_(def)]) – nice!", is(convertText(parts, PlainTextPart.class, LinkPart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text (and a link: [http://example.sone/abc_(def)|example.sone/abc_(def)|example.sone/abc_(def)]) – nice!")); } @Test @@ -129,15 +121,14 @@ public class SoneTextParserTest { SoneTextParser soneTextParser = new SoneTextParser(null, null); Iterable parts = soneTextParser.parse("Some text and a link: http://example.sone/abc. Nice!", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]. Nice!", is(convertText(parts, PlainTextPart.class, LinkPart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]. Nice!")); } @Test public void multiplePunctuationCharactersAreIgnoredAtEndOfLinkBeforeWhitespace() { - SoneTextParser soneTextParser = new SoneTextParser(null, null); Iterable parts = soneTextParser.parse("Some text and a link: http://example.sone/abc... Nice!", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]... Nice!", is(convertText(parts, PlainTextPart.class, LinkPart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]... Nice!")); } @Test @@ -145,7 +136,7 @@ public class SoneTextParserTest { SoneTextParser soneTextParser = new SoneTextParser(null, null); Iterable parts = soneTextParser.parse("Some text and a link: http://example.sone/abc, nice!", null); assertThat("Parts", parts, notNullValue()); - assertThat("Part Text", "Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc], nice!", is(convertText(parts, PlainTextPart.class, LinkPart.class))); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc], nice!")); } /**