KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > ExplorerUtilsTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.explorer;
21
22 import javax.swing.KeyStroke JavaDoc;
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 /**
30  * Check the behaviour of the ExplorerUtils
31  *
32  * @author Petr Nejedly
33  */

34 public class ExplorerUtilsTest extends NbTestCase {
35     public ExplorerUtilsTest(String JavaDoc testName) {
36         super(testName);
37     }
38
39     public void testGetHelpCtx() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc id;
85         public WithHelpNode(String JavaDoc 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