1   package test.atlassian.mail;
2   
3   import com.atlassian.mail.HtmlToTextConverter;
4   import junit.framework.TestCase;
5   import org.apache.commons.lang.SystemUtils;
6   
7   import java.io.IOException;
8   
9   public class TestHtmlToTextConverter extends TestCase
10  {
11      public void testParagraphsAndBreaks() throws IOException
12      {
13          assertEquals("I am a fish\nas am I\n\nand me",
14              new HtmlToTextConverter().convert("<p>I am a fish<br>as am I<p>and me"));
15      }
16  
17      /**
18       * <p>There is a bug in JDK prior to 1.6 whereby this html "Some<br/>text" would be converted
19       * to "Some\n>text" instead of "Some\ntext".</p>
20       * <p>The bug is reported as
21       * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4806463">Issue 4806463</a>.</p>
22       *
23       * This is why this test doesn't expect the same result depending on the jdk version.
24       */
25      public void testXHTMLBreaks() throws IOException
26      {
27          final String expected;
28          if (SystemUtils.isJavaVersionAtLeast(160))
29          {
30              expected = "I am a fish\nas am I\nand me";
31          }
32          else
33          {
34              expected = "I am a fish\n>as am I\nand me";
35          }
36  
37          assertEquals(expected, new HtmlToTextConverter().convert("I am a fish<br />as am I<br></br>and me"));
38      }
39  
40      /*
41       * This, believe it or not, is a perfectly valid HTML document. The <body> element is implied
42       * by the fact you can't have paragraphs in a header
43       */
44      public void testIgnoreHeader() throws IOException
45      {
46          assertEquals("I am a fish\nToo",
47              new HtmlToTextConverter().convert("<head><title>Fish</title><p>I am a fish<br>Too"));
48      }
49  }