01: package com.opensymphony.module.sitemesh.html;
02:
03: import junit.framework.TestCase;
04:
05: public class StateTest extends TestCase {
06:
07: class DummyRule extends BasicRule {
08: public DummyRule(String acceptableTagName) {
09: super (acceptableTagName);
10: }
11:
12: public void process(Tag tag) {
13: throw new UnsupportedOperationException();
14: }
15: }
16:
17: public void testMapsTagNameToRule() {
18: TagRule mouseRule = new DummyRule("mouse");
19: TagRule donkeyRule = new DummyRule("donkey");
20: TagRule lemonRule = new DummyRule("lemon");
21:
22: State state = new State();
23: state.addRule(mouseRule);
24: state.addRule(donkeyRule);
25: state.addRule(lemonRule);
26:
27: assertSame(donkeyRule, state.getRule("donkey"));
28: assertSame(lemonRule, state.getRule("lemon"));
29: assertSame(mouseRule, state.getRule("mouse"));
30: }
31:
32: public void testExposesWhetherItShouldProcessATagBasedOnAvailableRules() {
33: TagRule mouseRule = new DummyRule("mouse");
34: TagRule donkeyRule = new DummyRule("donkey");
35: TagRule lemonRule = new DummyRule("lemon");
36:
37: State state = new State();
38: state.addRule(mouseRule);
39: state.addRule(donkeyRule);
40: state.addRule(lemonRule);
41:
42: assertTrue(state.shouldProcessTag("donkey"));
43: assertTrue(state.shouldProcessTag("lemon"));
44: assertFalse(state.shouldProcessTag("yeeeehaa"));
45: }
46:
47: public void testReturnsMostRecentlyAddedRuleIfMultipleMatchesFound() {
48: TagRule oldRule = new DummyRule("something");
49: TagRule newRule = new DummyRule("something");
50:
51: State state = new State();
52: state.addRule(oldRule);
53: state.addRule(newRule);
54:
55: assertSame(newRule, state.getRule("something"));
56: }
57: }
|