private static void assertExceptionOccurred( boolean shouldOccur, AbstractExceptionCase exceptionCase, String expectedErrorMsg) throws Throwable { boolean wasThrown = false; try { exceptionCase.tryClosure(); } catch (Throwable e) { if (shouldOccur) { wasThrown = true; final String errorMessage = exceptionCase.getAssertionErrorMessage(); assertEquals(errorMessage, exceptionCase.getExpectedExceptionClass(), e.getClass()); if (expectedErrorMsg != null) { assertEquals("Compare error messages", expectedErrorMsg, e.getMessage()); } } else if (exceptionCase.getExpectedExceptionClass().equals(e.getClass())) { wasThrown = true; System.out.println(""); e.printStackTrace(System.out); fail("Exception isn't expected here. Exception message: " + e.getMessage()); } else { throw e; } } finally { if (shouldOccur && !wasThrown) { fail(exceptionCase.getAssertionErrorMessage()); } } }
public static <T> void assertUnorderedCollection( Collection<? extends T> collection, Consumer<T>... checkers) { Assert.assertNotNull(collection); if (collection.size() != checkers.length) { Assert.fail(toString(collection)); } Set<Consumer<T>> checkerSet = new HashSet<Consumer<T>>(Arrays.asList(checkers)); int i = 0; Throwable lastError = null; for (final T actual : collection) { boolean flag = true; for (final Consumer<T> condition : checkerSet) { Throwable error = accepts(condition, actual); if (error == null) { checkerSet.remove(condition); flag = false; break; } else { lastError = error; } } if (flag) { lastError.printStackTrace(); Assert.fail("Incorrect element(" + i + "): " + actual); } i++; } }
public void _saveSettings() { // public for testing purposes if (mySaveSettingsIsInProgress.compareAndSet(false, true)) { try { doSave(); } catch (final Throwable ex) { if (isUnitTestMode()) { System.out.println("Saving application settings failed"); ex.printStackTrace(); } else { LOG.info("Saving application settings failed", ex); invokeLater( new Runnable() { public void run() { if (ex instanceof PluginException) { final PluginException pluginException = (PluginException) ex; PluginManager.disablePlugin(pluginException.getPluginId().getIdString()); Messages.showMessageDialog( "The plugin " + pluginException.getPluginId() + " failed to save settings and has been disabled. Please restart " + ApplicationNamesInfo.getInstance().getFullProductName(), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); } else { Messages.showMessageDialog( ApplicationBundle.message( "application.save.settings.error", ex.getLocalizedMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); } } }); } } finally { mySaveSettingsIsInProgress.set(false); } } }
@TestOnly public List<HighlightInfo> runPasses( @NotNull PsiFile file, @NotNull Document document, @NotNull TextEditor textEditor, @NotNull int[] toIgnore, boolean canChangeDocument, @Nullable Runnable callbackWhileWaiting) { assert myInitialized; assert !myDisposed; Application application = ApplicationManager.getApplication(); application.assertIsDispatchThread(); assert !application.isWriteAccessAllowed(); // pump first so that queued event do not interfere UIUtil.dispatchAllInvocationEvents(); UIUtil.dispatchAllInvocationEvents(); Project project = file.getProject(); setUpdateByTimerEnabled(false); FileStatusMap fileStatusMap = getFileStatusMap(); for (int ignoreId : toIgnore) { fileStatusMap.markFileUpToDate(document, ignoreId); } fileStatusMap.allowDirt(canChangeDocument); TextEditorBackgroundHighlighter highlighter = (TextEditorBackgroundHighlighter) textEditor.getBackgroundHighlighter(); final List<TextEditorHighlightingPass> passes = highlighter.getPasses(toIgnore); HighlightingPass[] array = passes.toArray(new HighlightingPass[passes.size()]); final DaemonProgressIndicator progress = createUpdateProgress(); progress.setDebug(LOG.isDebugEnabled()); myPassExecutorService.submitPasses( Collections.singletonMap((FileEditor) textEditor, array), progress, Job.DEFAULT_PRIORITY); try { while (progress.isRunning()) { try { if (progress.isCanceled() && progress.isRunning()) { // write action sneaked in the AWT. restart waitForTermination(); Throwable savedException = PassExecutorService.getSavedException(progress); if (savedException != null) throw savedException; return runPasses( file, document, textEditor, toIgnore, canChangeDocument, callbackWhileWaiting); } if (callbackWhileWaiting != null) { callbackWhileWaiting.run(); } progress.waitFor(100); UIUtil.dispatchAllInvocationEvents(); Throwable savedException = PassExecutorService.getSavedException(progress); if (savedException != null) throw savedException; } catch (RuntimeException e) { throw e; } catch (Error e) { e.printStackTrace(); throw e; } catch (Throwable e) { e.printStackTrace(); throw new RuntimeException(e); } } UIUtil.dispatchAllInvocationEvents(); UIUtil.dispatchAllInvocationEvents(); return getHighlights(document, null, project); } finally { fileStatusMap.allowDirt(true); waitForTermination(); } }