junit: notify when tests were interrupted with toolwindow close (IDEA-91113)

This commit is contained in:
Anna Kozlova
2012-09-10 18:47:52 +04:00
parent 18794d8e3e
commit 2140c64851
4 changed files with 34 additions and 10 deletions
@@ -96,7 +96,10 @@ public class TestsUIUtil {
return null;
}
public static void notifyByBalloon(@NotNull final Project project, final AbstractTestProxy root, final TestConsoleProperties properties) {
public static void notifyByBalloon(@NotNull final Project project,
boolean started,
final AbstractTestProxy root,
final TestConsoleProperties properties) {
if (project.isDisposed()) return;
if (properties == null) return;
@@ -107,7 +110,7 @@ public class TestsUIUtil {
String text;
String balloonText;
MessageType type;
TestResultPresentation testResultPresentation = new TestResultPresentation(root).getPresentation();
TestResultPresentation testResultPresentation = new TestResultPresentation(root, started).getPresentation();
type = testResultPresentation.getType();
balloonText = testResultPresentation.getBalloonText();
title = testResultPresentation.getTitle();
@@ -157,13 +160,19 @@ public class TestsUIUtil {
private static class TestResultPresentation {
private AbstractTestProxy myRoot;
private boolean myStarted;
private String myTitle;
private String myText;
private String myBalloonText;
private MessageType myType;
public TestResultPresentation(AbstractTestProxy root) {
public TestResultPresentation(AbstractTestProxy root, boolean started) {
myRoot = root;
myStarted = started;
}
public TestResultPresentation(AbstractTestProxy root) {
this(root, true);
}
public String getTitle() {
@@ -184,7 +193,7 @@ public class TestsUIUtil {
public TestResultPresentation getPresentation() {
if (myRoot == null) {
myBalloonText = myTitle = ExecutionBundle.message("test.not.started.progress.text");
myBalloonText = myTitle = myStarted ? "Tests were interrupted" : ExecutionBundle.message("test.not.started.progress.text");
myText = "";
myType = MessageType.WARNING;
} else{
@@ -288,6 +288,12 @@ public abstract class TestObject implements JavaCommandLine {
handler.getErr().setPacketDispatcher(packetsReceiver, queue);
handler.addProcessListener(new ProcessAdapter() {
private boolean myStarted = false;
@Override
public void startNotified(ProcessEvent event) {
myStarted = true;
}
@Override
public void processTerminated(ProcessEvent event) {
handler.removeProcessListener(this);
@@ -304,7 +310,7 @@ public abstract class TestObject implements JavaCommandLine {
unboundOutputRoot.flush();
packetsReceiver.checkTerminated();
final JUnitRunningModel model = packetsReceiver.getModel();
notifyByBalloon(model, consoleProperties);
notifyByBalloon(model, myStarted, consoleProperties);
}
finally {
if (ApplicationManager.getApplication().isUnitTestMode()) {
@@ -355,8 +361,8 @@ public abstract class TestObject implements JavaCommandLine {
return result;
}
protected void notifyByBalloon(JUnitRunningModel model, JUnitConsoleProperties consoleProperties) {
TestsUIUtil.notifyByBalloon(myProject, model != null ? model.getRoot() : null, consoleProperties);
protected void notifyByBalloon(JUnitRunningModel model, boolean started, JUnitConsoleProperties consoleProperties) {
TestsUIUtil.notifyByBalloon(myProject, started, model != null ? model.getRoot() : null, consoleProperties);
}
protected JUnitProcessHandler createHandler(Executor executor) throws ExecutionException {
@@ -272,9 +272,9 @@ public class TestPackage extends TestObject {
}
@Override
protected void notifyByBalloon(JUnitRunningModel model, final JUnitConsoleProperties consoleProperties) {
protected void notifyByBalloon(JUnitRunningModel model, boolean started, final JUnitConsoleProperties consoleProperties) {
if (myFoundTests) {
super.notifyByBalloon(model, consoleProperties);
super.notifyByBalloon(model, started, consoleProperties);
}
else {
final String packageName = myConfiguration.getPackage();
@@ -133,6 +133,8 @@ public class TestNGRunnableState extends JavaCommandLineState {
JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(config, processHandler, runnerSettings);
final SearchingForTestsTask task = createSearchingForTestsTask(myServerSocket, config, myTempFile);
processHandler.addProcessListener(new ProcessAdapter() {
private boolean myStarted = false;
@Override
public void processTerminated(final ProcessEvent event) {
unboundOutputRoot.flush();
@@ -157,7 +159,13 @@ public class TestNGRunnableState extends JavaCommandLineState {
: (resultsView.getStatus() == MessageHelper.FAILED_TEST
? MessageType.ERROR
: MessageType.INFO);
final String message = resultsView == null ? "Tests were not started" : resultsView.getStatusLine();
final String message;
if (resultsView == null) {
message = myStarted ? "Tests were interrupted" : "Tests were not started";
}
else {
message = resultsView.getStatusLine();
}
toolWindowManager.notifyByBalloon(testRunDebugId, type, message, null, null);
TestsUIUtil.NOTIFICATION_GROUP.createNotification(message, type).notify(project);
}
@@ -173,6 +181,7 @@ public class TestNGRunnableState extends JavaCommandLineState {
unboundOutputRoot.setOutputFilePath(config.getOutputFilePath());
}
client.prepareListening(listener, port);
myStarted = true;
mySearchForTestIndicator = new BackgroundableProcessIndicator(task);
ProgressManagerImpl.runProcessWithProgressAsynchronously(task, mySearchForTestIndicator);
}