KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Collections JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Locale JavaDoc;
25 import java.util.Set JavaDoc;
26 import java.util.logging.LogRecord JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import org.netbeans.junit.MockServices;
29 import org.netbeans.junit.NbTestCase;
30 import org.openide.modules.ModuleInfo;
31 import org.openide.modules.SpecificationVersion;
32
33 /**
34  */

35 public class EnabledModulesCollectorTest extends NbTestCase {
36     private Installer installer;
37     
38     public EnabledModulesCollectorTest(String JavaDoc testName) {
39         super(testName);
40     }
41
42     protected void setUp() throws Exception JavaDoc {
43         Locale.setDefault(new Locale JavaDoc("te", "ST"));
44         MockServices.setServices(EnabledModulesCollector.class, MyModule.class, MyModule2.class, ActivatedDeativatedTest.DD.class);
45         installer = Installer.findObject(Installer.class, true);
46         installer.restored();
47     }
48
49     protected void tearDown() throws Exception JavaDoc {
50     }
51     
52     public void testSetOfEnabledModulesIsListed() {
53         // just log something
54
Logger.getLogger("org.netbeans.ui.empty").warning("say anything");
55         
56         assertTrue("ok", installer.closing());
57         
58         List JavaDoc<LogRecord JavaDoc> rec = Installer.getLogs();
59         if (rec.get(0).getMessage().equals("say anything")) {
60             rec.remove(0);
61         }
62         
63         assertEquals("One record for disabled and one for enabled: " + rec, 2, rec.size());
64         
65         assertEquals("UI_ENABLED_MODULES", rec.get(0).getMessage());
66         assertEquals("UI_DISABLED_MODULES", rec.get(1).getMessage());
67         assertEquals("one enabled", 1, rec.get(0).getParameters().length);
68         assertEquals("one disabled", 1, rec.get(1).getParameters().length);
69         assertEquals("the one enabled", MyModule.INSTANCE.getCodeNameBase(), rec.get(0).getParameters()[0]);
70         assertEquals("the one disabled", MyModule2.INSTANCE2.getCodeNameBase(), rec.get(1).getParameters()[0]);
71
72         assertNotNull("Localized msg0", rec.get(0).getResourceBundle().getString(rec.get(0).getMessage()));
73         assertNotNull("Localized msg1", rec.get(1).getResourceBundle().getString(rec.get(1).getMessage()));
74     }
75     
76     public static class MyModule extends ModuleInfo {
77         static MyModule INSTANCE;
78         
79         public MyModule() {
80             if (MyModule.class == getClass()) {
81                 INSTANCE = this;
82             }
83         }
84         
85         public String JavaDoc getCodeNameBase() {
86             return "my.module";
87         }
88
89         public int getCodeNameRelease() {
90             return -1;
91         }
92
93         public String JavaDoc getCodeName() {
94             return getCodeNameBase();
95         }
96
97         public SpecificationVersion getSpecificationVersion() {
98             return new SpecificationVersion("1.2");
99         }
100
101         public boolean isEnabled() {
102             return true;
103         }
104
105         public Object JavaDoc getAttribute(String JavaDoc attr) {
106             return null;
107         }
108
109         public Object JavaDoc getLocalizedAttribute(String JavaDoc attr) {
110             return null;
111         }
112
113         public Set JavaDoc<org.openide.modules.Dependency> getDependencies() {
114             return Collections.emptySet();
115         }
116
117         public boolean owns(Class JavaDoc clazz) {
118             return false;
119         }
120     } // end of MyModule
121

122     public static final class MyModule2 extends MyModule {
123         static MyModule2 INSTANCE2;
124         
125         public MyModule2() {
126             INSTANCE2 = this;
127         }
128         public String JavaDoc getCodeNameBase() {
129             return "my.module2";
130         }
131         
132         public boolean isEnabled() {
133             return false;
134         }
135     }
136 }
137
Popular Tags