Added
Link Here
|
1 |
/* |
2 |
* Sun Public License Notice |
3 |
* |
4 |
* The contents of this file are subject to the Sun Public License |
5 |
* Version 1.0 (the "License"). You may not use this file except in |
6 |
* compliance with the License. A copy of the License is available at |
7 |
* http://www.sun.com/ |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
13 |
|
14 |
package org.openide.explorer; |
15 |
|
16 |
import junit.textui.TestRunner; |
17 |
|
18 |
import org.netbeans.junit.*; |
19 |
import org.openide.nodes.*; |
20 |
import org.openide.util.HelpCtx; |
21 |
|
22 |
/** |
23 |
* Check the behaviour of the ExplorerUtils |
24 |
* |
25 |
* @author Petr Nejedly |
26 |
*/ |
27 |
public class ExplorerUtilsTest extends NbTestCase { |
28 |
public ExplorerUtilsTest(String testName) { |
29 |
super(testName); |
30 |
} |
31 |
|
32 |
public static void main(String[] args) { |
33 |
TestRunner.run(new NbTestSuite(ExplorerUtilsTest.class)); |
34 |
System.exit(0); |
35 |
} |
36 |
|
37 |
public void testGetHelpCtx () throws Exception { |
38 |
HelpCtx DEF = new HelpCtx("default"); |
39 |
|
40 |
assertEquals("Use default help for no nodes", |
41 |
DEF, |
42 |
ExplorerUtils.getHelpCtx(new Node[0], DEF)); |
43 |
|
44 |
assertEquals("Use default help for single node w/o help", |
45 |
DEF, |
46 |
ExplorerUtils.getHelpCtx(new Node[] {new NoHelpNode()}, DEF)); |
47 |
|
48 |
assertEquals("Use provided help for single node with help", |
49 |
new HelpCtx("foo"), |
50 |
ExplorerUtils.getHelpCtx(new Node[] {new WithHelpNode("foo")}, DEF)); |
51 |
|
52 |
assertEquals("Use default help for more nodes w/o help", |
53 |
DEF, |
54 |
ExplorerUtils.getHelpCtx(new Node[] {new NoHelpNode(), new NoHelpNode()}, DEF)); |
55 |
|
56 |
assertEquals("Use provided help if only one node has help", |
57 |
new HelpCtx("foo"), |
58 |
ExplorerUtils.getHelpCtx(new Node[] {new NoHelpNode(), new WithHelpNode("foo")}, DEF)); |
59 |
|
60 |
assertEquals("Use provided help if more nodes have the same help", |
61 |
new HelpCtx("foo"), |
62 |
ExplorerUtils.getHelpCtx(new Node[] {new WithHelpNode("foo"), new WithHelpNode("foo")}, DEF)); |
63 |
|
64 |
assertEquals("Use default help if nodes have different helps", |
65 |
DEF, |
66 |
ExplorerUtils.getHelpCtx(new Node[] {new WithHelpNode("foo"), new WithHelpNode("bar")}, DEF)); |
67 |
} |
68 |
|
69 |
|
70 |
private static final class NoHelpNode extends AbstractNode { |
71 |
public NoHelpNode() { |
72 |
super(Children.LEAF); |
73 |
} |
74 |
} |
75 |
|
76 |
private static final class WithHelpNode extends AbstractNode { |
77 |
private final String id; |
78 |
public WithHelpNode(String id) { |
79 |
super(Children.LEAF); |
80 |
this.id = id; |
81 |
} |
82 |
public HelpCtx getHelpCtx() { |
83 |
return new HelpCtx(id); |
84 |
} |
85 |
} |
86 |
|
87 |
} |