KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > component > FormSupportTest


1 package com.tonbeller.wcf.component;
2
3 import junit.framework.TestCase;
4
5 import com.tonbeller.wcf.controller.RequestContext;
6 public class FormSupportTest extends TestCase {
7     Form f1, f2;
8     MyFormListener l1, l2;
9
10   class MyFormListener implements FormListener {
11     int validateCount = 0;
12     int revertCount = 0;
13     public boolean validate(RequestContext context) {
14       validateCount++;
15       return true;
16     }
17     public void revert(RequestContext context) {
18       revertCount++;
19     }
20   };
21   
22   public FormSupportTest(String JavaDoc name) {
23     super(name);
24   }
25   
26   public void testSingle() {
27     // add twice, must be ignored
28
f1.addFormListener(l1);
29     f1.addFormListener(l1);
30     f1.validate(null);
31     assertEquals(1, l1.validateCount);
32     f1.removeFormListener(l1);
33     f1.validate(null);
34     assertEquals(1, l1.validateCount);
35   }
36
37   public void testValidate1() {
38     // f2 listens to f1
39
f1.addFormListener(f2);
40     f1.validate(null);
41     assertEquals(1, l1.validateCount);
42         assertEquals(1, l2.validateCount);
43         f2.validate(null);
44         assertEquals(1, l1.validateCount);
45         assertEquals(2, l2.validateCount);
46   }
47     public void testValidate2() {
48         // f1 listens to f2
49
f1.addFormListener(f2);
50         f2.addFormListener(f1);
51         f1.validate(null);
52         assertEquals(1, l1.validateCount);
53         assertEquals(1, l2.validateCount);
54         f2.validate(null);
55         assertEquals(2, l1.validateCount);
56         assertEquals(2, l2.validateCount);
57   }
58
59     public void testRevert1() {
60         // f2 listens to f1
61
f1.addFormListener(f2);
62         f1.revert(null);
63         assertEquals(1, l1.revertCount);
64         assertEquals(1, l2.revertCount);
65         f2.revert(null);
66         assertEquals(1, l1.revertCount);
67         assertEquals(2, l2.revertCount);
68     }
69     
70     public void testRevert2() {
71         // f1 listens to f2
72
f1.addFormListener(f2);
73         f2.addFormListener(f1);
74         f1.revert(null);
75         assertEquals(1, l1.revertCount);
76         assertEquals(1, l2.revertCount);
77         f2.revert(null);
78         assertEquals(2, l1.revertCount);
79         assertEquals(2, l2.revertCount);
80     }
81
82  
83   /* (non-Javadoc)
84    * @see junit.framework.TestCase#setUp()
85    */

86   protected void setUp() throws Exception JavaDoc {
87         f1 = new FormSupport();
88         l1 = new MyFormListener();
89         f1.addFormListener(l1);
90
91         f2 = new FormSupport();
92         l2 = new MyFormListener();
93         f2.addFormListener(l2);
94   }
95
96 }
97
Popular Tags