KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > validator > rules > ForEachTest


1 package org.sapia.validator.rules;
2
3 import junit.framework.*;
4
5 import org.sapia.validator.*;
6
7 import java.util.*;
8
9 /**
10  * @author Yanick Duchesne
11  * 28-Apr-2003
12  */

13 public class ForEachTest extends TestCase {
14   /**
15    * Constructor for ForEachTest.
16    */

17   public ForEachTest(String JavaDoc name) {
18     super(name);
19   }
20
21   public void testStop() throws Exception JavaDoc {
22     Vlad v = new Vlad();
23     RuleSet rs = new RuleSet();
24
25     rs.setId("forEach");
26
27     ForEach fe = new ForEach();
28     TestRule t1 = new TestRule(true);
29     TestRule t2 = new TestRule(false);
30
31     fe.addValidatable(t1);
32     fe.addValidatable(t2);
33     rs.addValidatable(fe);
34     v.addRuleSet(rs);
35     v.validate("forEach", makeCollection(), java.util.Locale.getDefault());
36     super.assertTrue("TestRule 1 was not called", t1.wasCalled());
37     super.assertTrue("TestRule 2 was called", !t2.wasCalled());
38   }
39
40   public void testNoStop() throws Exception JavaDoc {
41     Vlad v = new Vlad();
42     RuleSet rs = new RuleSet();
43
44     rs.setId("forEach");
45
46     ForEach fe = new ForEach();
47
48     fe.setStop(false);
49
50     TestRule t1 = new TestRule(true);
51     TestRule t2 = new TestRule(false);
52
53     fe.addValidatable(t1);
54     fe.addValidatable(t2);
55     rs.addValidatable(fe);
56     v.addRuleSet(rs);
57     v.validate("forEach", makeCollection(), java.util.Locale.getDefault());
58     super.assertTrue("TestRule 1 was not called", t1.wasCalled());
59     super.assertTrue("TestRule 2 was not called", t2.wasCalled());
60   }
61
62   public Collection makeCollection() {
63     List coll = new ArrayList();
64
65     coll.add(new Object JavaDoc());
66     coll.add(new Object JavaDoc());
67     coll.add(new Object JavaDoc());
68
69     return coll;
70   }
71 }
72
Popular Tags