1 package com.generationjava.web;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6 import junit.textui.TestRunner;
7
8 public class HtmlWTest extends TestCase {
9
10 private String testHtml = "<bar thing=\"foo\" other='single'>test</bar>";
11
12 public HtmlWTest(String name) {
13 super(name);
14 }
15
16 public void testEscape() {
17 String toEscape = "4 is < 7 & 7 is > 4 but \"7\" and '4' make error. ";
18 String expected = "4 is < 7 & 7 is > 4 but "7" and '4' make error. ";
19 assertEquals( expected, HtmlW.escapeHtml( toEscape ) );
20 }
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public void testGetAttribute() {
36 assertEquals( "foo", HtmlW.getAttribute( this.testHtml, "thing" ) );
37 assertEquals( "foo", HtmlW.getAttribute( this.testHtml, "Thing" ) );
38 }
39
40 public void testGetIndexOpeningTag() {
41 assertEquals( 0, HtmlW.getIndexOpeningTag(this.testHtml, "bar") );
42 assertEquals( 0, HtmlW.getIndexOpeningTag(this.testHtml, "BAR") );
43 }
44
45 public void testGetIndexClosingTag() {
46 assertEquals( 36, HtmlW.getIndexClosingTag(this.testHtml, "bar") );
47 assertEquals( 36, HtmlW.getIndexClosingTag(this.testHtml, "bAR") );
48 }
49
50 public void testGetContent() {
51 assertEquals( "test", HtmlW.getContent(this.testHtml, "bar") );
52 assertEquals( "test", HtmlW.getContent(this.testHtml, "bAr") );
53 }
54
55 public void testSingleQuoteAttribute() {
56 assertEquals( "single", HtmlW.getAttribute(this.testHtml, "other" ) );
57 assertEquals( "single", HtmlW.getAttribute(this.testHtml, "oTHer" ) );
58 }
59
60 }