Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r18570 r18598 1123 1123 } 1124 1124 1125 /** 1126 * Set up the UI manager 1127 */ 1128 // We want to catch all exceptions here to reset LaF to defaults and report it. 1129 @SuppressWarnings("squid:S2221") 1125 1130 static void setupUIManager() { 1126 1131 String defaultlaf = PlatformManager.getPlatform().getDefaultStyle(); … … 1149 1154 LafPreference.LAF.put(defaultlaf); 1150 1155 Logging.trace(ex); 1156 } catch (Exception ex) { 1157 // We do not want to silently exit if there is an exception. 1158 // Put the default laf in place so that the user can use JOSM. 1159 LafPreference.LAF.put(defaultlaf); 1160 BugReportExceptionHandler.handleException(ex); 1151 1161 } 1152 1162 } else { … … 1160 1170 } catch (InstantiationException | IllegalAccessException e) { 1161 1171 Logging.error(e); 1172 } catch (Exception e) { 1173 // We do not want to silently exit if there is an exception. 1174 // Put the default laf in place. 1175 LafPreference.LAF.put(defaultlaf); 1176 BugReportExceptionHandler.handleException(e); 1162 1177 } 1163 1178 -
trunk/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java
r17687 r18598 2 2 package org.openstreetmap.josm.gui; 3 3 4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 4 5 import static org.junit.jupiter.api.Assertions.assertEquals; 5 6 import static org.junit.jupiter.api.Assertions.assertFalse; … … 15 16 import java.io.PrintStream; 16 17 import java.net.MalformedURLException; 18 import java.net.URL; 17 19 import java.nio.charset.StandardCharsets; 18 20 import java.nio.file.Paths; 19 21 import java.util.Arrays; 20 22 import java.util.Collection; 23 import java.util.Collections; 21 24 import java.util.List; 22 25 import java.util.concurrent.ExecutionException; 23 26 import java.util.concurrent.Future; 27 import java.util.concurrent.atomic.AtomicReference; 24 28 import java.util.jar.Attributes; 25 29 26 30 import javax.swing.JComponent; 27 31 import javax.swing.JPanel; 32 import javax.swing.UIDefaults; 28 33 import javax.swing.UIManager; 29 34 import javax.swing.plaf.metal.MetalLookAndFeel; 35 36 import mockit.Mock; 37 import mockit.MockUp; 30 38 import org.junit.jupiter.api.Test; 31 39 import org.junit.jupiter.api.extension.RegisterExtension; … … 38 46 import org.openstreetmap.josm.gui.layer.GpxLayer; 39 47 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 48 import org.openstreetmap.josm.gui.preferences.display.LafPreference; 49 import org.openstreetmap.josm.plugins.PluginClassLoader; 40 50 import org.openstreetmap.josm.plugins.PluginHandler; 41 51 import org.openstreetmap.josm.plugins.PluginHandlerTestIT; … … 50 60 51 61 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 62 import org.openstreetmap.josm.tools.bugreport.BugReportQueue; 52 63 53 64 /** … … 196 207 @Test 197 208 void testSetupUIManager() { 209 TestUtils.assumeWorkingJMockit(); 198 210 assumeFalse(PlatformManager.isPlatformWindows() && "True".equals(System.getenv("APPVEYOR"))); 199 MainApplication.setupUIManager();211 assertDoesNotThrow(MainApplication::setupUIManager); 200 212 assertEquals(Config.getPref().get("laf", PlatformManager.getPlatform().getDefaultStyle()), 201 213 UIManager.getLookAndFeel().getClass().getCanonicalName()); 214 try { 215 LafPreference.LAF.put(BadLaf.class.getName()); 216 new PluginHandlerMock(); 217 AtomicReference<Throwable> exceptionAtomicReference = new AtomicReference<>(); 218 BugReportQueue.getInstance().setBugReportHandler((e, index) -> { 219 exceptionAtomicReference.set(e.getCause()); 220 return BugReportQueue.SuppressionMode.NONE; 221 }); 222 assertDoesNotThrow(MainApplication::setupUIManager); 223 224 assertNotNull(exceptionAtomicReference.get()); 225 assertTrue(exceptionAtomicReference.get() instanceof UnsupportedOperationException); 226 // The LAF only resets on restart, so don't bother checking that it switched back in UIManager 227 assertEquals(LafPreference.LAF.getDefaultValue(), LafPreference.LAF.get()); 228 } finally { 229 BugReportQueue.getInstance().setBugReportHandler(BugReportQueue.FALLBACK_BUGREPORT_HANDLER); 230 // Make certain we reset the LAF 231 LafPreference.LAF.remove(); 232 assertDoesNotThrow(MainApplication::setupUIManager); 233 assertEquals(Config.getPref().get("laf", PlatformManager.getPlatform().getDefaultStyle()), 234 UIManager.getLookAndFeel().getClass().getCanonicalName()); 235 } 202 236 } 203 237 … … 317 351 TestUtils.superficialEnumCodeCoverage(DownloadParamType.class); 318 352 } 353 354 /** 355 * This class exists to test a failure in non-default UI loading 356 */ 357 public static class BadLaf extends MetalLookAndFeel { 358 @Override 359 public UIDefaults getDefaults() { 360 throw new UnsupportedOperationException("Test failure loading"); 361 } 362 } 363 364 /** 365 * A mock class for returning a fake plugin class loader for {@link #testSetupUIManager()} 366 */ 367 public static class PluginHandlerMock extends MockUp<PluginHandler> { 368 @Mock 369 public static Collection<PluginClassLoader> getPluginClassLoaders() { 370 return Collections.singleton(new PluginClassLoader(new URL[0], BadLaf.class.getClassLoader(), Collections.emptyList())); 371 } 372 } 319 373 }
Note:
See TracChangeset
for help on using the changeset viewer.