1 package jodd.servlet; 2 3 import junit.framework.*; 4 5 public class TestHtmlEncoder extends TestCase { 6 7 public void testEncode() { 8 String html = "< & \" ' > \r\n \n \t"; 9 10 assertEquals("< & " ' > 
 
 	", HtmlEncoder.encode(html)); 11 12 html = ""; 13 assertEquals("", HtmlEncoder.encode(html)); 14 15 html = null; 16 assertEquals("", HtmlEncoder.encode(html)); 17 18 html = new String(new char[] {128, 257}); 19 assertEquals("€ā", HtmlEncoder.encode(html)); 20 } 21 22 public void testEncodeText() { 23 String html = "< & \" ' > \r\n \n \t"; 24 25 assertEquals("< & " ' > <br> <br> 	", HtmlEncoder.encodeText(html)); 26 27 html = ""; 28 assertEquals("", HtmlEncoder.encodeText(html)); 29 30 html = null; 31 assertEquals("", HtmlEncoder.encodeText(html)); 32 33 html = new String(new char[] {128, 257}); 34 assertEquals("€ā", HtmlEncoder.encodeText(html)); 35 36 html = "\r\n\n\r"; 37 assertEquals("<br><br><br>", HtmlEncoder.encodeText(html)); 38 39 html = "\r\n\r\n"; 40 assertEquals("<br><br>", HtmlEncoder.encodeText(html)); 41 42 html = "\n\r"; 43 assertEquals("<br><br>", HtmlEncoder.encodeText(html)); 44 } 45 46 47 public void testEncodeTextStrict() { 48 String html = "< & \" ' > \r\n \n \t"; 49 50 assertEquals("< & " ' > <br> <br> 	", HtmlEncoder.encodeTextStrict(html)); 51 52 html = ""; 53 assertEquals("", HtmlEncoder.encodeTextStrict(html)); 54 55 html = null; 56 assertEquals("", HtmlEncoder.encodeTextStrict(html)); 57 58 html = new String(new char[] {128, 257}); 59 assertEquals("€ā", HtmlEncoder.encodeTextStrict(html)); 60 61 html = "\r\n\n\r"; 62 assertEquals("<br><br><br>", HtmlEncoder.encodeTextStrict(html)); 63 64 html = "\r\n\r\n"; 65 assertEquals("<br><br>", HtmlEncoder.encodeTextStrict(html)); 66 67 html = "\n\r"; 68 assertEquals("<br><br>", HtmlEncoder.encodeTextStrict(html)); 69 } 70 71 72 public void testEncodeTextSmart() { 73 String html = "< & \" ' > \r\n \n \t"; 74 75 assertEquals("< & " ' > <br> <br> 	", HtmlEncoder.encodeTextSmart(html)); 76 77 html = ""; 78 assertEquals("", HtmlEncoder.encodeTextSmart(html)); 79 80 html = null; 81 assertEquals("", HtmlEncoder.encodeTextSmart(html)); 82 83 html = new String(new char[] {128, 257}); 84 assertEquals("€ā", HtmlEncoder.encodeTextSmart(html)); 85 86 html = "\r\n\n\r"; 87 assertEquals("<br><br><br>", HtmlEncoder.encodeTextSmart(html)); 88 89 html = "\r\n\r\n"; 90 assertEquals("<br><br>", HtmlEncoder.encodeTextSmart(html)); 91 92 html = "\n\r"; 93 assertEquals("<br><br>", HtmlEncoder.encodeTextSmart(html)); 94 95 html = " "; 96 assertEquals(" ", HtmlEncoder.encodeTextSmart(html)); 97 html = " "; 98 assertEquals(" ", HtmlEncoder.encodeTextSmart(html)); 99 html = " "; 100 assertEquals(" ", HtmlEncoder.encodeTextSmart(html)); 101 html = " "; 102 assertEquals(" ", HtmlEncoder.encodeTextSmart(html)); 103 html = " "; 104 assertEquals(" ", HtmlEncoder.encodeTextSmart(html)); 105 106 html = " a"; 107 assertEquals(" a", HtmlEncoder.encodeTextSmart(html)); 108 html = " a"; 109 assertEquals(" a", HtmlEncoder.encodeTextSmart(html)); 110 html = " a"; 111 assertEquals(" a", HtmlEncoder.encodeTextSmart(html)); 112 html = " a"; 113 assertEquals(" a", HtmlEncoder.encodeTextSmart(html)); 114 html = " a"; 115 assertEquals(" a", HtmlEncoder.encodeTextSmart(html)); 116 117 html = "a "; 118 assertEquals("a ", HtmlEncoder.encodeTextSmart(html)); 119 html = "a "; 120 assertEquals("a ", HtmlEncoder.encodeTextSmart(html)); 121 html = "a "; 122 assertEquals("a ", HtmlEncoder.encodeTextSmart(html)); 123 html = "a "; 124 assertEquals("a ", HtmlEncoder.encodeTextSmart(html)); 125 html = "a "; 126 assertEquals("a ", HtmlEncoder.encodeTextSmart(html)); 127 128 html = " a "; 129 assertEquals(" a ", HtmlEncoder.encodeTextSmart(html)); 130 html = " a "; 131 assertEquals(" a ", HtmlEncoder.encodeTextSmart(html)); 132 html = " a "; 133 assertEquals(" a ", HtmlEncoder.encodeTextSmart(html)); 134 html = " a "; 135 assertEquals(" a ", HtmlEncoder.encodeTextSmart(html)); 136 html = " a b c d e"; 137 assertEquals(" a b c d e", HtmlEncoder.encodeTextSmart(html)); 138 } 139 140 141 } 142 | Popular Tags |