01: package com.opensymphony.module.sitemesh.html;
02:
03: import junit.framework.TestCase;
04:
05: public class CustomTagTest extends TestCase {
06:
07: public void testWritesOutUserDefinedTag() {
08: assertEquals("<hello/>", new CustomTag("hello", Tag.EMPTY)
09: .getContents());
10: assertEquals("<hello>", new CustomTag("hello", Tag.OPEN)
11: .getContents());
12: assertEquals("</hello>", new CustomTag("hello", Tag.CLOSE)
13: .getContents());
14: }
15:
16: public void testWritesAttributes() {
17: CustomTag tag = new CustomTag("hello", Tag.EMPTY);
18: tag.addAttribute("color", "green");
19: tag.addAttribute("stuff", null);
20: assertEquals("<hello color=\"green\" stuff/>", tag
21: .getContents());
22: }
23:
24: public void testAllowsAttributesToBeManipulated() {
25: CustomTag tag = new CustomTag("hello", Tag.OPEN);
26: assertEquals("<hello>", tag.getContents());
27:
28: tag.addAttribute("a", "aaa");
29: tag.addAttribute("b", "bbb");
30: assertEquals("<hello a=\"aaa\" b=\"bbb\">", tag.getContents());
31:
32: tag.removeAttribute("b", false);
33: assertEquals("<hello a=\"aaa\">", tag.getContents());
34:
35: tag.setAttributeValue("a", false, "zzz");
36: assertEquals("<hello a=\"zzz\">", tag.getContents());
37:
38: tag.addAttribute("c", "ccc");
39: int index = tag.getAttributeIndex("c", true);
40: assertEquals(1, index);
41: assertEquals("ccc", tag.getAttributeValue(index));
42: assertEquals("c", tag.getAttributeName(index));
43: }
44: }
|