1 19 package org.openide.actions; 20 21 import java.io.PrintWriter ; 22 import java.io.StringWriter ; 23 import javax.swing.Action ; 24 import javax.swing.JMenuItem ; 25 import junit.framework.*; 26 import org.openide.nodes.AbstractNode; 27 import org.openide.nodes.Children; 28 import org.openide.util.actions.Presenter; 29 30 public class NewActionTest extends TestCase { 31 32 public NewActionTest(String testName) { 33 super(testName); 34 } 35 36 protected void setUp() throws Exception { 37 } 38 39 protected void tearDown() throws Exception { 40 } 41 42 public void testTheNewTypesMethodIsCalledJustOnceIssue65534() throws Exception { 43 class N extends AbstractNode { 44 int cnt; 45 StringWriter w = new StringWriter (); 46 PrintWriter p = new PrintWriter (w); 47 48 public N() { 49 super(Children.LEAF); 50 } 51 52 public org.openide.util.datatransfer.NewType[] getNewTypes() { 53 cnt++; 54 org.openide.util.datatransfer.NewType[] retValue; 55 56 new Exception ("Call " + cnt).printStackTrace(p); 57 58 retValue = super.getNewTypes(); 59 return retValue; 60 } 61 } 62 63 64 N node = new N(); 65 66 NewAction a = (NewAction)NewAction.get(NewAction.class); 67 68 Action clone = a.createContextAwareInstance(node.getLookup()); 69 70 if (!(clone instanceof Presenter.Popup)) { 71 fail("Does not implement popup: " + clone); 72 } 73 74 Presenter.Popup p = (Presenter.Popup)clone; 75 76 JMenuItem m = p.getPopupPresenter(); 77 String name = m.getName(); 78 assertEquals("Just one call to getNewTypes\n" + node.w, 1, node.cnt); 79 } 80 } 81 82 83 | Popular Tags |