KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > util > actions > BooleanStateActionTest


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.util.actions;
21
22 import org.netbeans.junit.NbTestCase;
23 import org.openide.util.HelpCtx;
24
25 /** Test that boolean actions are in fact toggled.
26  * @author Jesse Glick
27  */

28 public class BooleanStateActionTest extends NbTestCase {
29
30     public BooleanStateActionTest(String JavaDoc name) {
31         super(name);
32     }
33
34     /** Self-explanatory, hopefully. */
35     public void testToggle() throws Exception JavaDoc {
36         BooleanStateAction a1 = (BooleanStateAction)SystemAction.get(SimpleBooleanAction1.class);
37         assertTrue(a1.isEnabled());
38         BooleanStateAction a2 = (BooleanStateAction)SystemAction.get(SimpleBooleanAction2.class);
39         assertTrue(a1.getBooleanState());
40         assertFalse(a2.getBooleanState());
41         ActionsInfraHid.WaitPCL l = new ActionsInfraHid.WaitPCL(BooleanStateAction.PROP_BOOLEAN_STATE);
42         a1.addPropertyChangeListener(l);
43         a1.actionPerformed(null);
44         assertTrue(l.changed());
45         assertFalse(a1.getBooleanState());
46         a1.removePropertyChangeListener(l);
47         l.gotit = 0;
48         a2.addPropertyChangeListener(l);
49         a2.actionPerformed(null);
50         assertTrue(l.changed());
51         assertTrue(a2.getBooleanState());
52         a2.removePropertyChangeListener(l);
53     }
54     
55     public static final class SimpleBooleanAction1 extends BooleanStateAction {
56         public String JavaDoc getName() {
57             return "SimpleBooleanAction1";
58         }
59         public HelpCtx getHelpCtx() {
60             return null;
61         }
62         protected boolean asynchronous() {
63             return false;
64         }
65     }
66     
67     public static final class SimpleBooleanAction2 extends BooleanStateAction {
68         protected void initialize() {
69             super.initialize();
70             setBooleanState(false);
71         }
72         public String JavaDoc getName() {
73             return "SimpleBooleanAction2";
74         }
75         public HelpCtx getHelpCtx() {
76             return null;
77         }
78         protected boolean asynchronous() {
79             return false;
80         }
81     }
82     
83 }
84
Popular Tags