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-2005 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
13 |
|
14 |
package org.openide.actions; |
15 |
|
16 |
import java.lang.reflect.InvocationTargetException; |
17 |
import org.netbeans.junit.NbTestCase; |
18 |
import org.openide.nodes.AbstractNode; |
19 |
import org.openide.nodes.Children; |
20 |
import org.openide.nodes.Node; |
21 |
import javax.swing.Action; |
22 |
import org.openide.nodes.Node.Property; |
23 |
import org.openide.nodes.Node.PropertySet; |
24 |
|
25 |
/** Issue 68299. |
26 |
* |
27 |
* @author Jiri Rechtacek |
28 |
*/ |
29 |
public class PropertiesActionTest extends NbTestCase { |
30 |
public PropertiesActionTest (String testName) { |
31 |
super (testName); |
32 |
} |
33 |
|
34 |
protected void setUp () throws Exception { |
35 |
} |
36 |
|
37 |
protected void tearDown () throws Exception { |
38 |
} |
39 |
|
40 |
public void testEnableOnEmptyProperties () throws Exception { |
41 |
testEnable (new PropertySet [0]); |
42 |
} |
43 |
|
44 |
public void testEnableOnNullProperties () throws Exception { |
45 |
testEnable (null); |
46 |
} |
47 |
|
48 |
public void testEnableOnNotNullProperties () throws Exception { |
49 |
PropertySet [] s = new PropertySet [] { new PropertySet () { |
50 |
public Property[] getProperties () { |
51 |
Property p = new Property (String.class) { |
52 |
public boolean canRead () { |
53 |
return true; |
54 |
} |
55 |
public boolean canWrite () { |
56 |
return true; |
57 |
} |
58 |
public Object getValue () throws IllegalAccessException,InvocationTargetException { |
59 |
return null; |
60 |
} |
61 |
public void setValue (Object val) throws IllegalAccessException,IllegalArgumentException,InvocationTargetException { |
62 |
} |
63 |
}; |
64 |
return new Property [] { p }; |
65 |
} |
66 |
} }; |
67 |
|
68 |
testEnable (s); |
69 |
} |
70 |
|
71 |
private void testEnable (final PropertySet [] pros) throws Exception { |
72 |
Node n = new AbstractNode (Children.LEAF) { |
73 |
public PropertySet [] getPropertySets () { |
74 |
return pros; |
75 |
} |
76 |
}; |
77 |
|
78 |
|
79 |
assertEquals ("Node has the given properties.", pros, n.getPropertySets ()); |
80 |
|
81 |
Node[] activatedNodes = new Node [] { n }; |
82 |
|
83 |
PropertiesAction pa = (PropertiesAction) PropertiesAction.get (PropertiesAction.class); |
84 |
Action a = pa.createContextAwareInstance (n.getLookup ()); |
85 |
|
86 |
assertTrue ("PropertiesAction is enabled.", a.isEnabled ()); |
87 |
} |
88 |
|
89 |
} |