notifications about tests passed/finished in SM runner. Balloon will be shown only...
[fedora-idea.git] / platform / smRunner / src / com / intellij / execution / testframework / sm / runner / ui / SMTRunnerNotificationsHandler.java
blob6583254514bb65da304fbc6ba795a98997a6b58d
1 package com.intellij.execution.testframework.sm.runner.ui;
3 import com.intellij.execution.testframework.TestConsoleProperties;
4 import com.intellij.execution.testframework.sm.runner.SMTRunnerEventsAdapter;
5 import com.intellij.execution.testframework.sm.runner.SMTestProxy;
6 import com.intellij.execution.testframework.sm.runner.states.TestStateInfo;
7 import com.intellij.openapi.project.Project;
8 import com.intellij.openapi.ui.MessageType;
9 import com.intellij.openapi.util.Comparing;
10 import com.intellij.openapi.wm.ToolWindowId;
11 import com.intellij.openapi.wm.ToolWindowManager;
12 import org.jetbrains.annotations.NotNull;
14 import javax.swing.*;
16 /**
17 * @author Roman Chernyatchik
19 public class SMTRunnerNotificationsHandler extends SMTRunnerEventsAdapter {
20 private final TestConsoleProperties myConsoleProperties;
21 //private boolean myFirstDefectWasFound;
23 public SMTRunnerNotificationsHandler(@NotNull final TestConsoleProperties consoleProperties) {
24 myConsoleProperties = consoleProperties;
27 public void onTestingStarted(@NotNull SMTestProxy testsRoot) {
28 //myFirstDefectWasFound = false;
31 public void onTestingFinished(@NotNull SMTestProxy testsRoot) {
32 final String msg;
33 final MessageType type;
35 final TestStateInfo.Magnitude magnitude = testsRoot.getMagnitudeInfo();
36 switch (magnitude) {
37 case SKIPPED_INDEX:
38 case IGNORED_INDEX:
39 msg = "Tests skipped";
40 type = MessageType.WARNING;
41 break;
43 case NOT_RUN_INDEX:
44 msg = "Tests were not started";
45 type = MessageType.WARNING;
46 break;
48 case FAILED_INDEX:
49 case ERROR_INDEX:
50 msg = "Tests failed";
51 type = MessageType.ERROR;
52 break;
53 case COMPLETE_INDEX:
54 case PASSED_INDEX:
55 msg = "Tests passed";
56 type = MessageType.INFO;
57 break;
59 default:
60 msg = null;
61 type = null;
64 if (msg != null) {
65 notify(msg, type);
69 public void onTestFailed(@NotNull SMTestProxy test) {
70 // TODO : if user doesn't close this balloon then user will not see 'tests failed' balloon
71 //if (!myFirstDefectWasFound) {
72 // // notify about defect on the fly
73 // if (test.isDefect()) {
74 // final TestStateInfo.Magnitude magnitude = test.getMagnitudeInfo();
75 // //noinspection EnumSwitchStatementWhichMissesCases
76 // switch (magnitude) {
77 // case FAILED_INDEX:
78 // case ERROR_INDEX:
79 // myFirstDefectWasFound = true;
80 // notify("Tests will fail", MessageType.WARNING);
81 // break;
82 // default:
83 // // Do nothing
84 // }
85 // }
86 //}
89 private void notify(final String msg, final MessageType type) {
90 SwingUtilities.invokeLater(new Runnable() {
91 public void run() {
92 final Project project = myConsoleProperties.getProject();
93 if ( project.isDisposed()) {
94 return;
97 if (myConsoleProperties == null) {
98 return;
100 final String testRunDebugId = myConsoleProperties.isDebug() ? ToolWindowId.DEBUG : ToolWindowId.RUN;
101 final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
102 if (!Comparing.strEqual(toolWindowManager.getActiveToolWindowId(), testRunDebugId)) {
103 toolWindowManager.notifyByBalloon(testRunDebugId, type, msg, null, null);