package com.fsck.k9.helper; import junit.framework.Assert; import org.junit.Test; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; public class HtmlConverterTest { // Useful if you want to write stuff to a file for debugging in a browser. private static final boolean WRITE_TO_FILE = false; private static final String OUTPUT_FILE = "C:/temp/parse.html"; @Test public void testTextQuoteToHtmlBlockquote() { String message = "Panama!\n" + "\n" + "Bob Barker wrote:\n" + "> a canal\n" + ">\n" + "> Dorothy Jo Gideon espoused:\n" + "> >A man, a plan...\n" + "> Too easy!\n" + "\n" + "Nice job :)\n" + ">> Guess!"; String result = HtmlConverter.textToHtml(message, false); writeToFile(result); Assert.assertEquals("
Panama!

Bob Barker <bob@aol.com> wrote:
a canal

Dorothy Jo Gideon <dorothy@aol.com> espoused:
A man, a plan...
Too easy!

Nice job :)
Guess!
", result); } @Test public void testTextQuoteToHtmlBlockquoteIndented() { String message = "*facepalm*\n" + "\n" + "Bob Barker wrote:\n" + "> A wise man once said...\n" + ">\n" + "> LOL F1RST!!!!!\n" + ">\n" + "> :)"; String result = HtmlConverter.textToHtml(message, false); writeToFile(result); Assert.assertEquals("
*facepalm*

Bob Barker <bob@aol.com> wrote:
A wise man once said...

LOL F1RST!!!!!

:)
", result); } private void writeToFile(final String content) { if(!WRITE_TO_FILE) { return; } try { System.err.println(content); File f = new File(OUTPUT_FILE); f.delete(); FileWriter fstream = new FileWriter(OUTPUT_FILE); BufferedWriter out = new BufferedWriter(fstream); out.write(content); out.close(); } catch (Exception e) { e.printStackTrace(); } } }