1 19 20 package org.openide.nodes; 21 22 import java.awt.event.ActionEvent ; 23 import java.beans.*; 24 import java.util.*; 25 import javax.swing.AbstractAction ; 26 import javax.swing.Action ; 27 28 import junit.textui.TestRunner; 29 import org.netbeans.junit.NbTestCase; 30 import org.netbeans.junit.NbTestSuite; 31 32 import org.openide.nodes.*; 33 import org.openide.util.actions.SystemAction; 34 35 38 public class NodeOpTest extends NbTestCase { 39 40 public NodeOpTest(String name) { 41 super(name); 42 } 43 44 public static void main(String [] args) { 45 TestRunner.run(new NbTestSuite(NodeOpTest.class)); 46 } 47 48 49 private static final class A extends AbstractAction { 50 public void actionPerformed(ActionEvent ev) { 51 } 52 } 53 54 public void testFindActions () throws Exception { 55 class N extends AbstractNode { 56 private Action [] arr; 57 58 N (Action [] arr) { 59 super (org.openide.nodes.Children.LEAF); 60 this.arr = arr; 61 } 62 63 public Action [] getActions (boolean f) { 64 return arr; 65 } 66 } 67 68 Action [] arr = { new A(), new A(), new A(), new A() }; 69 70 assertArray ( 71 "Finding actions for one node is simple", 72 arr, 73 NodeOp.findActions(new Node[] { new N (arr) }) 74 ); 75 76 assertArray ( 77 "Finding actions for two nodes with same actions", 78 arr, 79 NodeOp.findActions(new Node[] { new N (arr), new N (arr) }) 80 ); 81 82 assertArray ( 83 "Finding actions for three nodes with same actions", 84 arr, 85 NodeOp.findActions(new Node[] { new N (arr), new N (arr), new N (arr) }) 86 ); 87 88 89 assertArray ( 90 "Otherwise only common actions are taken", 91 new Action [] { arr[3] }, 92 NodeOp.findActions(new Node[] { new N (arr), new N (new Action [] { arr[3], null }) }) 93 ); 94 95 } 96 97 101 public void testFindActions2() throws Exception { 102 class N extends AbstractNode { 103 private Action a1 = new A(); 104 private Action a3 = new A(); 105 N() { 106 super (org.openide.nodes.Children.LEAF); 107 } 108 public Action [] getActions(boolean f) { 109 return new Action [] { 110 a1, 111 new A(), 112 a3, 113 }; 114 } 115 } 116 Action [] actions = NodeOp.findActions(new Node[] {new N()}); 117 assertEquals("NodeOp.findActions does not gratuitously remove nonconstant actions", 3, actions.length); 118 } 119 120 private static void assertArray (String msg, Object [] a1, Object [] a2) { 121 assertEquals(msg, Arrays.asList(a1), Arrays.asList(a2)); 122 } 123 } 124 | Popular Tags |