1 19 20 package org.openide.nodes; 21 22 import junit.framework.*; 23 import junit.textui.TestRunner; 24 import java.util.*; 25 import org.openide.nodes.*; 26 27 import org.netbeans.junit.*; 28 29 33 public class NodeListenerTest extends NbTestCase { 34 public NodeListenerTest(String name) { 35 super(name); 36 } 37 38 public static void main(String [] args) { 39 TestRunner.run(new NbTestSuite(NodeListenerTest.class)); 40 } 41 42 45 public void testCorrectMutexUsage () throws Exception { 46 Children.Array ch = new Children.Array (); 47 AbstractNode n = new AbstractNode (ch); 48 49 class L extends Object implements NodeListener, Runnable { 50 private boolean run; 51 52 public void childrenAdded (NodeMemberEvent ev) { 53 runNows (); 54 } 55 public void childrenRemoved (NodeMemberEvent ev) { 56 runNows (); 57 } 58 public void childrenReordered(NodeReorderEvent ev) { 59 } 60 public void nodeDestroyed (NodeEvent ev) { 61 } 62 63 public void propertyChange (java.beans.PropertyChangeEvent ev) { 64 } 65 66 public void run () { 67 run = true; 68 } 69 70 private void runNows () { 71 L read = new L (); 72 Children.MUTEX.postReadRequest (read); 73 if (read.run) { 74 fail ("It is possible to run read access request"); 75 } 76 77 L write = new L (); 78 Children.MUTEX.postWriteRequest (write); 79 if (!write.run) { 80 fail ("It is not possible to run write access request"); 81 } 82 } 83 } 84 85 86 L l = new L (); 87 88 n.addNodeListener (l); 89 Node t = new AbstractNode (Children.LEAF); 90 ch.add (new Node[] { t }); 91 92 ch.remove (new Node[] { t }); 93 } 94 } 95 | Popular Tags |