From 3d5b967682742f354852ae4473c4e457d437eda5 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 13 Sep 2012 10:24:58 +0200 Subject: [PATCH] AbstractVcsHelperImpl.setCustomExceptionHandler for tests --- .../vcs/impl/AbstractVcsHelperImpl.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java index c02e9cfcccee..aca2fdae7b63 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java @@ -69,6 +69,7 @@ import com.intellij.openapi.wm.WindowManager; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import com.intellij.ui.content.MessageView; +import com.intellij.util.ArrayUtil; import com.intellij.util.AsynchConsumer; import com.intellij.util.BufferedListConsumer; import com.intellij.util.Consumer; @@ -78,6 +79,7 @@ import com.intellij.util.ui.MessageCategory; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; import java.awt.*; import java.io.File; @@ -90,6 +92,12 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.impl.AbstractVcsHelperImpl"); private final Project myProject; + private Consumer myCustomHandler = new Consumer() { + @Override + public void consume(VcsException e) { + throw new RuntimeException(e); + } + }; public AbstractVcsHelperImpl(Project project) { myProject = project; @@ -227,28 +235,29 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper { return CommitChangeListDialog.commitChanges(myProject, changes, initialChangeList, executor, commitMessage); } - private void addDirectMessages(VcsErrorViewPanel vcsErrorViewPanel, List abstractVcsExceptions) { + private static void addDirectMessages(VcsErrorViewPanel vcsErrorViewPanel, List abstractVcsExceptions) { for (final VcsException exception : abstractVcsExceptions) { String[] messages = getExceptionMessages(exception); vcsErrorViewPanel.addMessage(getErrorCategory(exception), messages, exception.getVirtualFile(), -1, -1, null); } } - private String[] getExceptionMessages(VcsException exception) { + private static String[] getExceptionMessages(VcsException exception) { String[] messages = exception.getMessages(); if (messages.length == 0) messages = new String[]{VcsBundle.message("exception.text.unknown.error")}; final List list = new ArrayList(); for (String message : messages) { list.addAll(StringUtil.split(StringUtil.convertLineSeparators(message), "\n")); } - return list.toArray(new String[list.size()]); + return ArrayUtil.toStringArray(list); } private void showErrorsImpl(final boolean isEmpty, final Getter firstGetter, @NotNull final String tabDisplayName, final Consumer viewFiller) { - if (ApplicationManager.getApplication().isUnitTestMode() && !isEmpty) { - throw new RuntimeException(firstGetter.get()); - } else if (ApplicationManager.getApplication().isUnitTestMode()) { + if (ApplicationManager.getApplication().isUnitTestMode()) { + if (!isEmpty) { + myCustomHandler.consume(firstGetter.get()); + } return; } ApplicationManager.getApplication().invokeLater(new Runnable() { @@ -704,4 +713,9 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper { return myRevisionsReturned; } } + + @TestOnly + public static void setCustomExceptionHandler(Project project, Consumer customHandler) { + ((AbstractVcsHelperImpl)getInstance(project)).myCustomHandler = customHandler; + } }