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();
55 msg
= "Tests skipped";
56 type
= MessageType
.WARNING
;
60 msg
= "Tests were not started";
61 type
= MessageType
.WARNING
;
67 type
= MessageType
.ERROR
;
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
;
75 // else same as: PASSED_INDEX
78 type
= MessageType
.INFO
;
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) {
101 // myFirstDefectWasFound = true;
102 // notify("Tests will fail", MessageType.WARNING);
111 private void notify(final String msg
, final MessageType type
) {
112 SwingUtilities
.invokeLater(new Runnable() {
114 final Project project
= myConsoleProperties
.getProject();
115 if ( project
.isDisposed()) {
119 if (myConsoleProperties
== null) {
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);