1 19 package org.openide.windows; 20 21 import javax.swing.ActionMap ; 22 import org.netbeans.junit.NbTestCase; 23 import org.openide.nodes.AbstractNode; 24 import org.openide.nodes.Children; 25 import org.openide.nodes.Node; 26 import org.openide.util.Lookup; 27 import org.openide.util.Lookup.Result; 28 import org.openide.util.Lookup.Template; 29 import org.openide.util.LookupEvent; 30 import org.openide.util.LookupListener; 31 32 36 public class PreventNeedlessChangesOfActionMapTest extends NbTestCase 37 implements LookupListener { 38 private TopComponent tc; 39 private Lookup.Result res; 40 private int cnt; 41 42 43 public PreventNeedlessChangesOfActionMapTest(String s) { 44 super(s); 45 } 46 47 protected void setUp() throws Exception { 48 tc = new TopComponent(); 49 res = tc.getLookup().lookup(new Lookup.Template<ActionMap > (ActionMap .class)); 50 assertEquals("One instance", 1, res.allItems().size()); 51 52 res.addLookupListener(this); 53 } 54 55 public void testChangeOfNodeDoesNotFireChangeInActionMap() { 56 ActionMap am = (ActionMap )tc.getLookup().lookup(ActionMap .class); 57 assertNotNull(am); 58 59 Node m1 = new AbstractNode(Children.LEAF); 60 m1.setName("old m1"); 61 Node m2 = new AbstractNode(Children.LEAF); 62 m2.setName("new m2"); 63 64 tc.setActivatedNodes(new Node[] { m1 }); 65 assertEquals("No change in ActionMap 1", 0, cnt); 66 tc.setActivatedNodes(new Node[] { m2 }); 67 assertEquals("No change in ActionMap 2", 0, cnt); 68 tc.setActivatedNodes(new Node[0]); 69 assertEquals("No change in ActionMap 3", 0, cnt); 70 tc.setActivatedNodes(null); 71 assertEquals("No change in ActionMap 4", 0, cnt); 72 73 ActionMap am2 = (ActionMap )tc.getLookup().lookup(ActionMap .class); 74 assertEquals("Still the same action map", am, am2); 75 } 76 77 public void resultChanged(LookupEvent ev) { 78 cnt++; 79 } 80 81 } 82 | Popular Tags |