1 19 20 package org.openide.explorer; 21 22 import javax.swing.KeyStroke ; 23 import org.netbeans.junit.NbTestCase; 24 import org.openide.nodes.AbstractNode; 25 import org.openide.nodes.Children; 26 import org.openide.nodes.Node; 27 import org.openide.util.HelpCtx; 28 29 34 public class ExplorerUtilsTest extends NbTestCase { 35 public ExplorerUtilsTest(String testName) { 36 super(testName); 37 } 38 39 public void testGetHelpCtx() throws Exception { 40 HelpCtx DEF = new HelpCtx("default"); 41 42 assertEquals("Use default help for no nodes", 43 DEF, 44 ExplorerUtils.getHelpCtx(new Node[0], DEF)); 45 46 assertEquals("Use default help for single node w/o help", 47 DEF, 48 ExplorerUtils.getHelpCtx(new Node[] {new NoHelpNode()}, DEF)); 49 50 assertEquals("Use provided help for single node with help", 51 new HelpCtx("foo"), 52 ExplorerUtils.getHelpCtx(new Node[] {new WithHelpNode("foo")}, DEF)); 53 54 assertEquals("Use default help for more nodes w/o help", 55 DEF, 56 ExplorerUtils.getHelpCtx(new Node[] {new NoHelpNode(), new NoHelpNode()}, DEF)); 57 58 assertEquals("Use provided help if only one node has help", 59 new HelpCtx("foo"), 60 ExplorerUtils.getHelpCtx(new Node[] {new NoHelpNode(), new WithHelpNode("foo")}, DEF)); 61 62 assertEquals("Use provided help if more nodes have the same help", 63 new HelpCtx("foo"), 64 ExplorerUtils.getHelpCtx(new Node[] {new WithHelpNode("foo"), new WithHelpNode("foo")}, DEF)); 65 66 assertEquals("Use default help if nodes have different helps", 67 DEF, 68 ExplorerUtils.getHelpCtx(new Node[] {new WithHelpNode("foo"), new WithHelpNode("bar")}, DEF)); 69 } 70 71 public void testUseBigLettersInJavaDocIssue46615() throws Exception { 72 assertNotNull(KeyStroke.getKeyStroke("control C")); 73 assertNotNull(KeyStroke.getKeyStroke("control X")); 74 assertNotNull(KeyStroke.getKeyStroke("control V")); 75 } 76 77 private static final class NoHelpNode extends AbstractNode { 78 public NoHelpNode() { 79 super(Children.LEAF); 80 } 81 } 82 83 private static final class WithHelpNode extends AbstractNode { 84 private final String id; 85 public WithHelpNode(String id) { 86 super(Children.LEAF); 87 this.id = id; 88 } 89 public HelpCtx getHelpCtx() { 90 return new HelpCtx(id); 91 } 92 } 93 94 } 95 | Popular Tags |