KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > structural > ChildHelperTest


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.structural;
5
6 import junit.framework.TestCase;
7
8 /**
9  *
10  */

11 public class ChildHelperTest extends TestCase {
12
13     public void testReplaceChild() {
14         class MyL implements StructuralListener {
15             int added;
16             int removed;
17             public void childAdded(StructuralEvent event) {
18                 added = event.getIndex();
19             }
20             public void childRemoved(StructuralEvent event) {
21                 removed = event.getIndex();
22             }
23             
24         }
25
26         Object JavaDoc o1 = new Object JavaDoc();
27         Object JavaDoc o2 = new Object JavaDoc();
28         Object JavaDoc o3 = new Object JavaDoc();
29         
30         ChildHelper test = new ChildHelper(this);
31         MyL l = new MyL();
32         test.addStructuralListener(l);
33         
34         test.addChild(o1);
35         test.addChild(o2);
36         
37         test.replaceChild(o1, o3);
38         
39         assertEquals("replace and in right place.", o3, test.getChildren()[0]);
40         assertEquals("notify correct removed index.", 0, l.removed);
41         assertEquals("notify correct added index.", 0, l.added);
42     }
43 }
44
Popular Tags