fixed [IDEADEV-41319] test runner: do not show green balloon and green progress bar...
[fedora-idea.git] / platform / smRunner / src / com / intellij / execution / testframework / sm / runner / ui / SMTRunnerNotificationsHandler.java
blob442b67fdbbc01747d87e34565c0ae045f60a6996
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.execution.testframework.sm.runner.ui;
18 import com.intellij.execution.testframework.TestConsoleProperties;
19 import com.intellij.execution.testframework.sm.SMTestsRunnerBundle;
20 import com.intellij.execution.testframework.sm.runner.SMTRunnerEventsAdapter;
21 import com.intellij.execution.testframework.sm.runner.SMTestProxy;
22 import com.intellij.execution.testframework.sm.runner.states.TestStateInfo;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.ui.MessageType;
25 import com.intellij.openapi.util.Comparing;
26 import com.intellij.openapi.wm.ToolWindowId;
27 import com.intellij.openapi.wm.ToolWindowManager;
28 import org.jetbrains.annotations.NotNull;
30 import javax.swing.*;
32 /**
33 * @author Roman Chernyatchik
35 public class SMTRunnerNotificationsHandler extends SMTRunnerEventsAdapter {
36 private final TestConsoleProperties myConsoleProperties;
37 //private boolean myFirstDefectWasFound;
39 public SMTRunnerNotificationsHandler(@NotNull final TestConsoleProperties consoleProperties) {
40 myConsoleProperties = consoleProperties;
43 public void onTestingStarted(@NotNull SMTestProxy testsRoot) {
44 //myFirstDefectWasFound = false;
47 public void onTestingFinished(@NotNull SMTestProxy testsRoot) {
48 final String msg;
49 final MessageType type;
51 final TestStateInfo.Magnitude magnitude = testsRoot.getMagnitudeInfo();
52 switch (magnitude) {
53 case SKIPPED_INDEX:
54 case IGNORED_INDEX:
55 msg = "Tests skipped";
56 type = MessageType.WARNING;
57 break;
59 case NOT_RUN_INDEX:
60 msg = "Tests were not started";
61 type = MessageType.WARNING;
62 break;
64 case FAILED_INDEX:
65 case ERROR_INDEX:
66 msg = "Tests failed";
67 type = MessageType.ERROR;
68 break;
69 case COMPLETE_INDEX:
70 if (testsRoot.getChildren().size() == 0) {
71 msg = SMTestsRunnerBundle.message("sm.test.runner.ui.tests.tree.presentation.labels.no.tests.were.found");
72 type = MessageType.ERROR;
73 break;
75 // else same as: PASSED_INDEX
76 case PASSED_INDEX:
77 msg = "Tests passed";
78 type = MessageType.INFO;
79 break;
81 default:
82 msg = null;
83 type = null;
86 if (msg != null) {
87 notify(msg, type);
91 public void onTestFailed(@NotNull SMTestProxy test) {
92 // TODO : if user doesn't close this balloon then user will not see 'tests failed' balloon
93 //if (!myFirstDefectWasFound) {
94 // // notify about defect on the fly
95 // if (test.isDefect()) {
96 // final TestStateInfo.Magnitude magnitude = test.getMagnitudeInfo();
97 // //noinspection EnumSwitchStatementWhichMissesCases
98 // switch (magnitude) {
99 // case FAILED_INDEX:
100 // case ERROR_INDEX:
101 // myFirstDefectWasFound = true;
102 // notify("Tests will fail", MessageType.WARNING);
103 // break;
104 // default:
105 // // Do nothing
106 // }
107 // }
111 private void notify(final String msg, final MessageType type) {
112 SwingUtilities.invokeLater(new Runnable() {
113 public void run() {
114 final Project project = myConsoleProperties.getProject();
115 if ( project.isDisposed()) {
116 return;
119 if (myConsoleProperties == null) {
120 return;
122 final String testRunDebugId = myConsoleProperties.isDebug() ? ToolWindowId.DEBUG : ToolWindowId.RUN;
123 final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
124 if (!Comparing.strEqual(toolWindowManager.getActiveToolWindowId(), testRunDebugId)) {
125 toolWindowManager.notifyByBalloon(testRunDebugId, type, msg, null, null);