1 17 18 package org.apache.commons.digester; 19 20 import java.util.List ; 21 22 import junit.framework.TestCase; 23 24 30 31 public class WDRulesWrapperTestCase extends TestCase { 32 33 34 public WDRulesWrapperTestCase(String name) { 35 super(name); 36 } 37 38 public void testClear() { 39 WithDefaultsRulesWrapper rules = new WithDefaultsRulesWrapper(new RulesBase()); 41 rules.add("alpha", new TestRule("Tom")); 42 rules.add("alpha", new TestRule("Dick")); 43 rules.add("alpha", new TestRule("Harry")); 44 45 assertNotNull("Rules should not be null", rules.rules()); 46 assertEquals("Wrong number of rules registered (1)", 3 , rules.rules().size()); 47 rules.clear(); 48 assertEquals("Clear Failed (1)", 0 , rules.rules().size()); 49 50 rules.add("alpha", new TestRule("Tom")); 52 rules.add("alpha", new TestRule("Dick")); 53 rules.add("alpha", new TestRule("Harry")); 54 rules.addDefault(new TestRule("Roger")); 55 assertEquals("Wrong number of rules registered (2)", 4 , rules.rules().size()); 56 rules.clear(); 57 assertEquals("Clear Failed (2)", 0 , rules.rules().size()); 58 59 rules.addDefault(new TestRule("Roger")); 60 assertEquals("Wrong number of rules registered (3)", 1 , rules.rules().size()); 61 rules.clear(); 62 assertEquals("Clear Failed (3)", 0 , rules.rules().size()); 63 } 64 65 public void testRules() { 66 WithDefaultsRulesWrapper rules = new WithDefaultsRulesWrapper(new RulesBase()); 68 rules.add("alpha", new TestRule("Tom")); 69 rules.add("alpha", new TestRule("Dick")); 70 rules.addDefault(new TestRule("Roger")); 71 rules.add("alpha", new TestRule("Harry")); 72 73 assertNotNull("Rules should not be null", rules.rules()); 74 assertEquals("Wrong order (1)", "Tom" , ((TestRule) rules.rules().get(0)).getIdentifier()); 75 assertEquals("Wrong order (2)", "Dick" , ((TestRule) rules.rules().get(1)).getIdentifier()); 76 assertEquals("Wrong order (3)", "Roger" , ((TestRule) rules.rules().get(2)).getIdentifier()); 77 assertEquals("Wrong order (4)", "Harry" , ((TestRule) rules.rules().get(3)).getIdentifier()); 78 } 79 80 public void testMatch() { 81 WithDefaultsRulesWrapper rules = new WithDefaultsRulesWrapper(new RulesBase()); 83 rules.add("alpha", new TestRule("Tom")); 84 rules.add("alpha", new TestRule("Dick")); 85 rules.add("alpha", new TestRule("Harry")); 86 rules.addDefault(new TestRule("Roger")); 87 rules.addDefault(new TestRule("Rabbit")); 88 89 List matches = rules.match("", "alpha"); 90 assertEquals("Wrong size (1)", 3 , matches.size()); 91 assertEquals("Wrong order (1)", "Tom" , ((TestRule) matches.get(0)).getIdentifier()); 92 assertEquals("Wrong order (2)", "Dick" , ((TestRule) matches.get(1)).getIdentifier()); 93 assertEquals("Wrong order (3)", "Harry" , ((TestRule) matches.get(2)).getIdentifier()); 94 95 matches = rules.match("", "not-alpha"); 96 assertEquals("Wrong size (2)", 2 , matches.size()); 97 assertEquals("Wrong order (4)", "Roger" , ((TestRule) matches.get(0)).getIdentifier()); 98 assertEquals("Wrong order (5)", "Rabbit" , ((TestRule) matches.get(1)).getIdentifier()); 99 } 100 } 101 | Popular Tags |