KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > actions > PropertiesActionTest


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.actions;
21
22 import java.lang.reflect.InvocationTargetException 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 javax.swing.Action JavaDoc;
28 import org.openide.nodes.Node.Property;
29 import org.openide.nodes.Node.PropertySet;
30
31 /** Issue 68299.
32  *
33  * @author Jiri Rechtacek
34  */

35 public class PropertiesActionTest extends NbTestCase {
36     public PropertiesActionTest (String JavaDoc testName) {
37         super (testName);
38     }
39
40     protected void setUp () throws Exception JavaDoc {
41     }
42
43     protected void tearDown () throws Exception JavaDoc {
44     }
45
46     public void testEnableOnEmptyProperties () throws Exception JavaDoc {
47         testEnable (new PropertySet [0]);
48     }
49
50     public void testEnableOnNullProperties () throws Exception JavaDoc {
51         testEnable (null);
52     }
53     
54     public void testEnableOnNotNullProperties () throws Exception JavaDoc {
55         PropertySet [] s = new PropertySet [] { new PropertySet () {
56                         public Property[] getProperties () {
57                             Property p = new Property (String JavaDoc.class) {
58                                 public boolean canRead () {
59                                     return true;
60                                 }
61                                 public boolean canWrite () {
62                                     return true;
63                                 }
64                                 public Object JavaDoc getValue () throws IllegalAccessException JavaDoc,InvocationTargetException JavaDoc {
65                                     return null;
66                                 }
67                                 public void setValue (Object JavaDoc val) throws IllegalAccessException JavaDoc,IllegalArgumentException JavaDoc,InvocationTargetException JavaDoc {
68                                 }
69                             };
70                             return new Property [] { p };
71                         }
72                     } };
73
74         testEnable (s);
75     }
76     
77     private void testEnable (final PropertySet [] pros) throws Exception JavaDoc {
78         Node n = new AbstractNode (Children.LEAF) {
79             public PropertySet [] getPropertySets () {
80                 return pros;
81             }
82         };
83         
84         
85         assertEquals ("Node has the given properties.", pros, n.getPropertySets ());
86         
87         Node[] activatedNodes = new Node [] { n };
88         
89         PropertiesAction pa = (PropertiesAction) PropertiesAction.get (PropertiesAction.class);
90         Action JavaDoc a = pa.createContextAwareInstance (n.getLookup ());
91         
92         assertTrue ("PropertiesAction is enabled.", a.isEnabled ());
93     }
94     
95 }
96
Popular Tags