1 19 20 package org.openide.windows; 21 22 import java.awt.event.ActionEvent ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.util.Collections ; 26 import javax.swing.AbstractAction ; 27 import javax.swing.ActionMap ; 28 import org.netbeans.junit.NbTestCase; 29 import org.openide.nodes.Node; 30 import org.openide.util.Lookup; 31 import org.openide.util.lookup.AbstractLookup; 32 import org.openide.util.lookup.InstanceContent; 33 34 41 public final class TopComponentLookupToNodesBridge extends NbTestCase { 42 43 protected ActionMap map; 44 45 protected TopComponent top; 46 47 protected InstanceContent ic; 48 49 protected Lookup lookup; 50 51 public TopComponentLookupToNodesBridge(String testName) { 52 super(testName); 53 } 54 55 protected boolean runInEQ() { 56 return true; 57 } 58 59 61 protected void setUp() { 62 System.setProperty("org.openide.util.Lookup", "-"); 63 64 map = new ActionMap (); 65 ic = new InstanceContent(); 66 ic.add(map); 67 68 lookup = new AbstractLookup(ic); 69 top = new TopComponent(lookup); 70 } 71 72 73 public void testTheLookupIsReturned() { 74 assertEquals("Lookup provided to TC in constructor is returned", lookup, top.getLookup()); 75 } 76 77 public void testActionMapIsTakenFromTheLookupIfProvided() { 78 Action a1 = new Action (); 79 map.put("key", a1); 80 81 assertEquals("Action map is set", a1, top.getActionMap().get("key")); 82 83 ActionMap another = new ActionMap (); 84 85 ic.set(Collections.singleton(another), null); 86 assertEquals("And is not changed (right now) if modified in list", a1, top.getActionMap().get("key")); 87 } 88 89 public void testEmptyLookupGeneratesZeroLengthArray() { 90 assertNotNull("Array is there", top.getActivatedNodes()); 91 assertEquals("No nodes", 0, top.getActivatedNodes().length); 92 } 93 94 public void testNodeIsThereIfInLookup() { 95 class Listener implements PropertyChangeListener { 96 public int cnt; 97 public String name; 98 99 public void propertyChange(PropertyChangeEvent ev) { 100 cnt++; 101 name = ev.getPropertyName(); 102 } 103 } 104 105 Listener l = new Listener (); 106 top.addPropertyChangeListener(l); 107 108 ic.add(Node.EMPTY); 109 110 assertNotNull("Array exists", top.getActivatedNodes()); 111 assertEquals("One node", 1, top.getActivatedNodes().length); 112 assertEquals("The node", Node.EMPTY, top.getActivatedNodes()[0]); 113 assertEquals("One PCE", 1, l.cnt); 114 assertEquals("Name of property", "activatedNodes", l.name); 115 116 117 ic.set(Collections.nCopies(2, Node.EMPTY), null); 118 119 assertEquals("Two nodes", 2, top.getActivatedNodes().length); 120 assertEquals("The same", Node.EMPTY, top.getActivatedNodes()[0]); 121 assertEquals("The same", Node.EMPTY, top.getActivatedNodes()[1]); 122 assertEquals("second PCE change", 2, l.cnt); 123 assertEquals("Name of property", "activatedNodes", l.name); 124 125 } 126 127 private static final class Action extends AbstractAction { 128 public void actionPerformed(ActionEvent e) { 129 } 130 } 131 } 132 | Popular Tags |