1 19 20 package org.netbeans.modules.uihandler; 21 22 import java.util.Collections ; 23 import java.util.List ; 24 import java.util.Locale ; 25 import java.util.Set ; 26 import java.util.logging.LogRecord ; 27 import java.util.logging.Logger ; 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 35 public class EnabledModulesCollectorTest extends NbTestCase { 36 private Installer installer; 37 38 public EnabledModulesCollectorTest(String testName) { 39 super(testName); 40 } 41 42 protected void setUp() throws Exception { 43 Locale.setDefault(new Locale ("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 { 50 } 51 52 public void testSetOfEnabledModulesIsListed() { 53 Logger.getLogger("org.netbeans.ui.empty").warning("say anything"); 55 56 assertTrue("ok", installer.closing()); 57 58 List <LogRecord > 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 getCodeNameBase() { 86 return "my.module"; 87 } 88 89 public int getCodeNameRelease() { 90 return -1; 91 } 92 93 public String 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 getAttribute(String attr) { 106 return null; 107 } 108 109 public Object getLocalizedAttribute(String attr) { 110 return null; 111 } 112 113 public Set <org.openide.modules.Dependency> getDependencies() { 114 return Collections.emptySet(); 115 } 116 117 public boolean owns(Class clazz) { 118 return false; 119 } 120 } 122 public static final class MyModule2 extends MyModule { 123 static MyModule2 INSTANCE2; 124 125 public MyModule2() { 126 INSTANCE2 = this; 127 } 128 public String getCodeNameBase() { 129 return "my.module2"; 130 } 131 132 public boolean isEnabled() { 133 return false; 134 } 135 } 136 } 137 | Popular Tags |