1 19 20 package org.openide.nodes; 21 22 import junit.framework.*; 23 import junit.textui.TestRunner; 24 import java.beans.*; 25 import java.beans.beancontext.*; 26 import java.util.*; 27 import org.openide.util.Mutex; 28 29 import org.netbeans.junit.*; 30 31 35 public class FilterChildrenEventsTest extends NbTestCase { 36 37 public FilterChildrenEventsTest(String name) { 38 super(name); 39 } 40 41 public static void main(String [] args) { 42 System.out.println("Running"); 43 TestRunner.run(new NbTestSuite(BeanChildrenTest.class)); 44 } 45 46 47 public void testNodesNodeDestroyed() throws Exception { 48 49 Node[] chNodes = createTestNodes(); 50 Children ch = new Children.Array(); 51 ch.add( chNodes ); 52 53 Node n = new AbstractNode( ch ); 54 FilterNode fn = new FilterNode( n ); 55 n.setName( "X" ); 56 MyListener ml = new MyListener(); 57 58 fn.addNodeListener( ml ); 59 60 n.setName( "Y" ); 61 62 List events = ml.getEvents(); 63 64 System.out.println( "Size " + events.size() ); 65 66 67 assertTrue("correct events", events.size() == 2 ); 68 } 69 70 public void testPropertyChange() throws Exception { 71 72 77 } 78 79 public void testChildrenAdded() throws Exception { 80 Node[] chNodes = createTestNodes(); 81 Children ch = new Children.Array(); 82 ch.add( chNodes ); 83 84 Node n = new AbstractNode( ch ); 85 FilterNode fn = new FilterNode( n ); 86 n.setName( "X" ); 87 MyListener ml = new MyListener(); 88 89 fn.addNodeListener( ml ); 90 Node[] hold = fn.getChildren().getNodes(); 91 92 ch.add( new Node[] { new AbstractNode( Children.LEAF) } ); 93 94 List events = ml.getEvents(); 95 96 assertEquals("correct events", 1, events.size() ); 97 } 98 99 100 private static Node[] createTestNodes() { 101 102 Node[] tNodes = new Node[] { 103 new AbstractNode( Children.LEAF ), 104 new AbstractNode( Children.LEAF ), 105 new AbstractNode( Children.LEAF ) 106 }; 107 108 tNodes[0].setName( "A" ); 109 tNodes[1].setName( "B" ); 110 tNodes[2].setName( "C" ); 111 112 return tNodes; 113 } 114 115 private static class MyListener implements NodeListener { 116 117 ArrayList events = new ArrayList(); 118 119 120 124 public void childrenAdded(NodeMemberEvent ev) { 125 events.add( ev ); 126 } 127 128 132 public void childrenRemoved(NodeMemberEvent ev) { 133 events.add( ev ); 134 } 135 136 140 public void childrenReordered(NodeReorderEvent ev) { 141 events.add( ev ); 142 } 143 144 148 public void nodeDestroyed(NodeEvent ev) { 149 events.add( ev ); 150 } 151 152 157 public void propertyChange(PropertyChangeEvent ev) { 158 events.add( ev ); 159 } 160 161 public List getEvents() { 162 return events; 163 } 164 165 } 166 } 167 | Popular Tags |