01: package com.opensymphony.module.sitemesh.html.tokenizer;
02:
03: import com.opensymphony.module.sitemesh.html.Tag;
04: import com.opensymphony.module.sitemesh.html.Text;
05: import junit.framework.Assert;
06:
07: class MockTokenHandler implements TokenHandler {
08:
09: private StringBuffer expected = new StringBuffer();
10: private StringBuffer actual = new StringBuffer();
11:
12: public void expectText(String tag) {
13: expected.append(tag);
14: }
15:
16: public void expectTag(int type, String tag) {
17: expectTag(type, tag, new String[0]);
18: }
19:
20: public void expectTag(int type, String tag, String[] attributes) {
21: expected.append("{{TAG : ").append(tag);
22: for (int i = 0; i < attributes.length; i += 2) {
23: expected.append(' ').append(attributes[i]).append("=\"")
24: .append(attributes[i + 1]).append('"');
25: }
26: expected.append(' ').append(typeAsString(type)).append("}}");
27: }
28:
29: public boolean shouldProcessTag(String name) {
30: Assert.assertNotNull("Name should not be null", name);
31: return true;
32: }
33:
34: public void tag(Tag tag) {
35: actual.append("{{TAG : ").append(tag.getName());
36: for (int i = 0; i < tag.getAttributeCount(); i++) {
37: actual.append(' ').append(tag.getAttributeName(i)).append(
38: "=\"").append(tag.getAttributeValue(i)).append('"');
39: }
40: actual.append(' ').append(typeAsString(tag.getType())).append(
41: "}}");
42: }
43:
44: public void text(Text text) {
45: actual.append(text.getContents());
46: }
47:
48: public void warning(String message, int line, int column) {
49: Assert.fail("Encountered error: " + message);
50: }
51:
52: public void verify() {
53: Assert.assertEquals(expected.toString(), actual.toString());
54: }
55:
56: private String typeAsString(int type) {
57: switch (type) {
58: case Tag.OPEN:
59: return "*open*";
60: case Tag.CLOSE:
61: return "*close*";
62: case Tag.EMPTY:
63: return "*empty*";
64: default:
65: return "*unknown*";
66: }
67: }
68:
69: }
|