KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > uihandler > ActivatedDeativatedTest


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.netbeans.modules.uihandler;
21
22 import java.awt.Dialog JavaDoc;
23 import java.util.Locale JavaDoc;
24 import java.util.logging.Level JavaDoc;
25 import java.util.logging.Logger JavaDoc;
26 import org.netbeans.junit.Log;
27 import org.netbeans.junit.MockServices;
28 import org.netbeans.junit.NbTestCase;
29 import org.netbeans.modules.uihandler.api.Activated;
30 import org.netbeans.modules.uihandler.api.Deactivated;
31 import org.openide.DialogDescriptor;
32 import org.openide.DialogDisplayer;
33 import org.openide.NotifyDescriptor;
34
35 /**
36  *
37  * @author Jaroslav Tulach
38  */

39 public class ActivatedDeativatedTest extends NbTestCase {
40     private Installer o;
41     
42     public ActivatedDeativatedTest(String JavaDoc testName) {
43         super(testName);
44     }
45     
46     protected boolean runInEQ() {
47         return true;
48     }
49
50     protected void setUp() throws Exception JavaDoc {
51         Locale.setDefault(new Locale JavaDoc("te", "ST"));
52         o = Installer.findObject(Installer.class, true);
53         assertNotNull("Installer created", o);
54         MockServices.setServices(A.class, D.class/*); //*/, DD.class);
55     }
56
57     protected void tearDown() throws Exception JavaDoc {
58     }
59     
60     public void testActivatedAndDeativated() {
61         CharSequence JavaDoc log = Log.enable("org.netbeans.ui", Level.ALL);
62         
63         o.restored();
64         if (log.toString().indexOf("A start") == -1) {
65             fail("A shall start: " + log);
66         }
67         
68         assertTrue("Allowed to close", o.closing());
69         if (log.toString().indexOf("D stop") == -1) {
70             fail("D shall stop: " + log);
71         }
72     }
73     
74     
75     public static final class A implements Activated {
76         public void activated(Logger JavaDoc uiLogger) {
77             uiLogger.config("A started");
78         }
79     }
80     public static final class D implements Deactivated {
81         public void deactivated(Logger JavaDoc uiLogger) {
82             uiLogger.config("D stopped");
83         }
84     }
85     public static final class DD extends DialogDisplayer {
86         public Object JavaDoc notify(NotifyDescriptor descriptor) {
87             // last options allows to close usually
88
return descriptor.getOptions()[descriptor.getOptions().length - 1];
89         }
90
91         public Dialog JavaDoc createDialog(DialogDescriptor descriptor) {
92             fail("Not implemented");
93             return null;
94         }
95         
96     }
97 }
98
Popular Tags