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
;
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
) {
49 final MessageType type
;
51 final TestStateInfo
.Magnitude magnitude
= testsRoot
.getMagnitudeInfo();
52 //noinspection EnumSwitchStatementWhichMissesCases
56 msg
= SMTestsRunnerBundle
.message("sm.test.runner.notifications.tests.skipped");
57 type
= MessageType
.WARNING
;
61 msg
= SMTestsRunnerBundle
.message("sm.test.runner.notifications.tests.not.run");
62 type
= MessageType
.WARNING
;
67 msg
= SMTestsRunnerBundle
.message("sm.test.runner.notifications.tests.failed");
68 type
= MessageType
.ERROR
;
71 if (testsRoot
.getChildren().size() == 0) {
72 msg
= SMTestsRunnerBundle
.message("sm.test.runner.ui.tests.tree.presentation.labels.no.tests.were.found");
73 type
= MessageType
.ERROR
;
76 // else same as: PASSED_INDEX
78 msg
= SMTestsRunnerBundle
.message("sm.test.runner.notifications.tests.passed");
79 type
= MessageType
.INFO
;
92 public void onTestFailed(@NotNull SMTestProxy test
) {
93 // TODO : if user doesn't close this balloon then user will not see 'tests failed' balloon
94 //if (!myFirstDefectWasFound) {
95 // // notify about defect on the fly
96 // if (test.isDefect()) {
97 // final TestStateInfo.Magnitude magnitude = test.getMagnitudeInfo();
98 // //noinspection EnumSwitchStatementWhichMissesCases
99 // switch (magnitude) {
100 // case FAILED_INDEX:
102 // myFirstDefectWasFound = true;
103 // notify("Tests will fail", MessageType.WARNING);
112 private void notify(final String msg
, final MessageType type
) {
113 SwingUtilities
.invokeLater(new Runnable() {
115 final Project project
= myConsoleProperties
.getProject();
116 if ( project
.isDisposed()) {
120 if (myConsoleProperties
== null) {
123 final String testRunDebugId
= myConsoleProperties
.isDebug() ? ToolWindowId
.DEBUG
: ToolWindowId
.RUN
;
124 final ToolWindowManager toolWindowManager
= ToolWindowManager
.getInstance(project
);
125 if (!Comparing
.strEqual(toolWindowManager
.getActiveToolWindowId(), testRunDebugId
)) {
126 toolWindowManager
.notifyByBalloon(testRunDebugId
, type
, msg
, null, null);