+ assertEquals("Part Text", "Test.\n\nTest.", convertText(parts, PlainTextPart.class));
+ }
+
+ /**
+ * Tests parsing of KSK links.
+ *
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ @SuppressWarnings("static-method")
+ public void testKSKLinks() throws IOException {
+ SoneTextParser soneTextParser = new SoneTextParser(null, null);
+ Iterable<Part> parts;
+
+ /* check basic links. */
+ parts = soneTextParser.parse(null, new StringReader("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."));
+ 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"));
+ 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));
+ }
+
+ /**
+ * Test case for a bug that was discovered in 0.6.7.
+ *
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ @SuppressWarnings({ "synthetic-access", "static-method" })
+ public void testEmptyLinesAndSoneLinks() throws IOException {
+ SoneTextParser soneTextParser = new SoneTextParser(new TestSoneProvider(), null);
+ Iterable<Part> parts;
+
+ /* check basic links. */
+ parts = soneTextParser.parse(null, new StringReader("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));
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Converts all given {@link Part}s into a string, validating that the
+ * part’s classes match only the expected classes.
+ *
+ * @param parts
+ * The parts to convert to text
+ * @param validClasses
+ * The valid classes; if no classes are given, all classes are
+ * valid
+ * @return The converted text
+ */
+ private static String convertText(Iterable<Part> parts, Class<?>... validClasses) {
+ StringBuilder text = new StringBuilder();