KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > appfuse > buildtools > EscapeHtmlEntitiesTest


1 package org.appfuse.buildtools;
2
3 import java.io.StringReader JavaDoc;
4
5 import junit.framework.TestCase;
6
7 import org.apache.tools.ant.util.FileUtils;
8
9 /**
10  * Testcase to verify EscapeHtmlEntities filter.
11  * @author <a HREF="mailto:mikagoeckel@codehaus.org">Mika Göckel</a>
12  */

13 public class EscapeHtmlEntitiesTest extends TestCase {
14
15     /**
16      * Test Unicode->Entity escaping.
17      * @throws Exception
18      */

19     public void testEscape() throws Exception JavaDoc {
20         StringReader JavaDoc str = new StringReader JavaDoc("\u00E4\u00FC\u00F6\u00DF-\u00D6\u00F3");
21         EscapeHtmlEntities boot = new EscapeHtmlEntities();
22         EscapeHtmlEntities filter = (EscapeHtmlEntities) boot.chain(str);
23         filter.setMode(EscapeHtmlEntities.ESCAPE);
24         String JavaDoc result = FileUtils.readFully(filter, 200);
25         assertEquals("&auml;&uuml;&ouml;&szlig;-&Ouml;&oacute;",result);
26     }
27     
28     /**
29      * Test Entity->Unicode unescaping.
30      * @throws Exception
31      */

32     public void testUnescape() throws Exception JavaDoc {
33         StringReader JavaDoc str = new StringReader JavaDoc("&auml;&uuml;&ouml;&szlig;-&Ouml;&oacute;&noentity;");
34         EscapeHtmlEntities boot = new EscapeHtmlEntities();
35         EscapeHtmlEntities filter = (EscapeHtmlEntities) boot.chain(str);
36         filter.setMode(EscapeHtmlEntities.UNESCAPE);
37         String JavaDoc result = FileUtils.readFully(filter, 200);
38         assertEquals("\u00E4\u00FC\u00F6\u00DF-\u00D6\u00F3&noentity;",result);
39     }
40 }
41
Popular Tags