From 2140c64851bce0abf6d54eec08c75152ae2372e8 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 10 Sep 2012 18:43:51 +0400 Subject: [PATCH] junit: notify when tests were interrupted with toolwindow close (IDEA-91113) --- .../execution/testframework/TestsUIUtil.java | 17 +++++++++++++---- .../intellij/execution/junit/TestObject.java | 12 +++++++++--- .../intellij/execution/junit/TestPackage.java | 4 ++-- .../configuration/TestNGRunnableState.java | 11 ++++++++++- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java b/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java index 4cd26f4f73d4..92a779cda874 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java @@ -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{ diff --git a/plugins/junit/src/com/intellij/execution/junit/TestObject.java b/plugins/junit/src/com/intellij/execution/junit/TestObject.java index c3a1058f0df6..e59369b8b5e3 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestObject.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestObject.java @@ -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 { diff --git a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java index 12adb15c78da..dbd83ba50b60 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java @@ -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(); diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java index e941dc21f7ad..c35b3c3ff0ea 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java +++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java @@ -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); }