From fef7f1e207b7fd219ce9d97dbbb3c0bbd708f74a Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Mon, 31 Aug 2015 17:00:10 +0300 Subject: [PATCH] showing test state on run marks --- .../TestRunLineMarkerProvider.java | 18 ++++- .../testframework/PoolOfTestIcons.java | 0 .../testframework/TestIconMapper.java | 66 +++++++++++++++++++ .../sm/runner/states/TestStateInfo.java | 24 ++++--- .../src/messages/ExecutionBundle.properties | 10 +++ .../messages/SMTestsRunnerBundle.properties | 10 --- platform/smRunner/smRunner.iml | 1 + 7 files changed, 104 insertions(+), 25 deletions(-) rename platform/{testRunner => lang-api}/src/com/intellij/execution/testframework/PoolOfTestIcons.java (100%) create mode 100644 platform/lang-api/src/com/intellij/execution/testframework/TestIconMapper.java rename platform/{smRunner => lang-api}/src/com/intellij/execution/testframework/sm/runner/states/TestStateInfo.java (67%) diff --git a/java/java-impl/src/com/intellij/testIntegration/TestRunLineMarkerProvider.java b/java/java-impl/src/com/intellij/testIntegration/TestRunLineMarkerProvider.java index 1a400d50282a..850fc356fc42 100644 --- a/java/java-impl/src/com/intellij/testIntegration/TestRunLineMarkerProvider.java +++ b/java/java-impl/src/com/intellij/testIntegration/TestRunLineMarkerProvider.java @@ -16,8 +16,12 @@ package com.intellij.testIntegration; import com.intellij.codeInsight.TestFrameworks; +import com.intellij.execution.TestStateStorage; import com.intellij.execution.lineMarker.ExecutorAction; import com.intellij.execution.lineMarker.RunLineMarkerContributor; +import com.intellij.execution.testframework.TestIconMapper; +import com.intellij.execution.testframework.sm.runner.states.TestStateInfo; +import com.intellij.openapi.project.Project; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiIdentifier; @@ -26,6 +30,8 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.Function; import org.jetbrains.annotations.Nullable; +import javax.swing.*; + /** * @author Dmitry Avdeev */ @@ -54,8 +60,9 @@ public class TestRunLineMarkerProvider extends RunLineMarkerContributor { if (psiClass != null) { TestFramework framework = TestFrameworks.detectFramework(psiClass); if (framework != null && framework.isTestMethod(element)) { - // String url = "java:test://" + psiClass.getQualifiedName() + "." + ((PsiMethod)element).getName(); - return new Info(framework.getIcon(), TOOLTIP_PROVIDER, ExecutorAction.getActions(1)); + String url = "java:test://" + psiClass.getQualifiedName() + "." + ((PsiMethod)element).getName(); + Icon icon = getTestStateIcon(url, e.getProject()); + return new Info(icon == null ? framework.getIcon() : icon, TOOLTIP_PROVIDER, ExecutorAction.getActions(1)); } } } @@ -66,4 +73,11 @@ public class TestRunLineMarkerProvider extends RunLineMarkerContributor { protected boolean isIdentifier(PsiElement e) { return e instanceof PsiIdentifier; } + + private static Icon getTestStateIcon(String url, Project project) { + TestStateStorage.Record state = TestStateStorage.getInstance(project).getState(url); + if (state == null) return null; + TestStateInfo.Magnitude magnitude = TestIconMapper.getMagnitude(state.magnitude); + return TestIconMapper.getIcon(magnitude); + } } diff --git a/platform/testRunner/src/com/intellij/execution/testframework/PoolOfTestIcons.java b/platform/lang-api/src/com/intellij/execution/testframework/PoolOfTestIcons.java similarity index 100% rename from platform/testRunner/src/com/intellij/execution/testframework/PoolOfTestIcons.java rename to platform/lang-api/src/com/intellij/execution/testframework/PoolOfTestIcons.java diff --git a/platform/lang-api/src/com/intellij/execution/testframework/TestIconMapper.java b/platform/lang-api/src/com/intellij/execution/testframework/TestIconMapper.java new file mode 100644 index 000000000000..f7573aae0e36 --- /dev/null +++ b/platform/lang-api/src/com/intellij/execution/testframework/TestIconMapper.java @@ -0,0 +1,66 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.execution.testframework; + +import com.intellij.execution.testframework.sm.runner.states.TestStateInfo; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Dmitry Avdeev + */ +public class TestIconMapper implements PoolOfTestIcons { + + private final static Map magnitudes = new HashMap(); + + static { + for (TestStateInfo.Magnitude value : TestStateInfo.Magnitude.values()) { + magnitudes.put(value.getValue(), value); + } + } + + public static TestStateInfo.Magnitude getMagnitude(int value) { + return magnitudes.get(value); + } + + @Nullable + public static Icon getIcon(TestStateInfo.Magnitude magnitude) { + switch (magnitude) { + case SKIPPED_INDEX: + return SKIPPED_ICON; + case COMPLETE_INDEX: + return PASSED_ICON; + case NOT_RUN_INDEX: + return NOT_RAN; + case RUNNING_INDEX: + return null; + case TERMINATED_INDEX: + return TERMINATED_ICON; + case IGNORED_INDEX: + return IGNORED_ICON; + case FAILED_INDEX: + return FAILED_ICON; + case ERROR_INDEX: + return ERROR_ICON; + case PASSED_INDEX: + return PASSED_ICON; + } + return null; + } +} diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/states/TestStateInfo.java b/platform/lang-api/src/com/intellij/execution/testframework/sm/runner/states/TestStateInfo.java similarity index 67% rename from platform/smRunner/src/com/intellij/execution/testframework/sm/runner/states/TestStateInfo.java rename to platform/lang-api/src/com/intellij/execution/testframework/sm/runner/states/TestStateInfo.java index e3c58ff1bcfe..f476ea2e5f61 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/states/TestStateInfo.java +++ b/platform/lang-api/src/com/intellij/execution/testframework/sm/runner/states/TestStateInfo.java @@ -15,7 +15,7 @@ */ package com.intellij.execution.testframework.sm.runner.states; -import com.intellij.execution.testframework.sm.SMTestsRunnerBundle; +import com.intellij.execution.ExecutionBundle; /** * @author Roman Chernyatchik @@ -32,7 +32,6 @@ public interface TestStateInfo { * Some magic definition from AbstractTestProxy class. * If state is defect something wrong is with it and should be shown * properly in UI. - * @return */ boolean isDefect(); @@ -54,22 +53,21 @@ public interface TestStateInfo { boolean wasTerminated(); /** - * It's some magic parameter than describe state type. - * @return + * It's some magic parameter that describes state type. */ Magnitude getMagnitude(); //WARN: It is Hack, see PoolOfTestStates, API is necessary enum Magnitude { - SKIPPED_INDEX(0, 1, SMTestsRunnerBundle.message("sm.test.runner.magnitude.skipped.failed.title")), - COMPLETE_INDEX(1, 3, SMTestsRunnerBundle.message("sm.test.runner.magnitude.completed.failed.title")), - NOT_RUN_INDEX(2, 0, SMTestsRunnerBundle.message("sm.test.runner.magnitude.not.run.failed.title")), - RUNNING_INDEX(3, 7, SMTestsRunnerBundle.message("sm.test.runner.magnitude.running.failed.title")), - TERMINATED_INDEX(4, 6, SMTestsRunnerBundle.message("sm.test.runner.magnitude.terminated.failed.title")), - IGNORED_INDEX(5, 2, SMTestsRunnerBundle.message("sm.test.runner.magnitude.ignored.failed.title")), - FAILED_INDEX(6, 4, SMTestsRunnerBundle.message("sm.test.runner.magnitude.assertion.failed.title")), - ERROR_INDEX(8, 5, SMTestsRunnerBundle.message("sm.test.runner.magnitude.testerror.title")), - PASSED_INDEX(COMPLETE_INDEX.getValue(), COMPLETE_INDEX.getSortWeight(), SMTestsRunnerBundle.message("sm.test.runner.magnitude.passed.title")); + SKIPPED_INDEX(0, 1, ExecutionBundle.message("sm.test.runner.magnitude.skipped.failed.title")), + COMPLETE_INDEX(1, 3, ExecutionBundle.message("sm.test.runner.magnitude.completed.failed.title")), + NOT_RUN_INDEX(2, 0, ExecutionBundle.message("sm.test.runner.magnitude.not.run.failed.title")), + RUNNING_INDEX(3, 7, ExecutionBundle.message("sm.test.runner.magnitude.running.failed.title")), + TERMINATED_INDEX(4, 6, ExecutionBundle.message("sm.test.runner.magnitude.terminated.failed.title")), + IGNORED_INDEX(5, 2, ExecutionBundle.message("sm.test.runner.magnitude.ignored.failed.title")), + FAILED_INDEX(6, 4, ExecutionBundle.message("sm.test.runner.magnitude.assertion.failed.title")), + ERROR_INDEX(8, 5, ExecutionBundle.message("sm.test.runner.magnitude.testerror.title")), + PASSED_INDEX(COMPLETE_INDEX.getValue(), COMPLETE_INDEX.getSortWeight(), ExecutionBundle.message("sm.test.runner.magnitude.passed.title")); private final int myValue; private final int mySortWeight; diff --git a/platform/platform-resources-en/src/messages/ExecutionBundle.properties b/platform/platform-resources-en/src/messages/ExecutionBundle.properties index 5d56fd033d71..cad5070ce93e 100644 --- a/platform/platform-resources-en/src/messages/ExecutionBundle.properties +++ b/platform/platform-resources-en/src/messages/ExecutionBundle.properties @@ -362,3 +362,13 @@ failed.to.create.output.file=Failed to create output file ''{0}'' script.execution.timeout=Script execution took more than {0} seconds. junit.configuration.configure.junit.test.kind.label=&Test kind: + +sm.test.runner.magnitude.completed.failed.title=Completed +sm.test.runner.magnitude.passed.title=Passed +sm.test.runner.magnitude.skipped.failed.title=Skipped +sm.test.runner.magnitude.not.run.failed.title=Not run +sm.test.runner.magnitude.running.failed.title=Running... +sm.test.runner.magnitude.terminated.failed.title=Terminated +sm.test.runner.magnitude.ignored.failed.title=Ignored +sm.test.runner.magnitude.assertion.failed.title=Assertion failed +sm.test.runner.magnitude.testerror.title=Error diff --git a/platform/platform-resources-en/src/messages/SMTestsRunnerBundle.properties b/platform/platform-resources-en/src/messages/SMTestsRunnerBundle.properties index 43a78f4263a2..d5c4bd3b0a28 100644 --- a/platform/platform-resources-en/src/messages/SMTestsRunnerBundle.properties +++ b/platform/platform-resources-en/src/messages/SMTestsRunnerBundle.properties @@ -35,15 +35,5 @@ sm.test.runner.ui.tabs.statistics.columns.results.count.msg.passed=P:{0} sm.test.runner.ui.tabs.statistics.columns.results.count.msg.ignored=I:{0} sm.test.runner.ui.tabs.statistics.columns.results.no.tests= -sm.test.runner.magnitude.completed.failed.title=Completed -sm.test.runner.magnitude.passed.title=Passed -sm.test.runner.magnitude.skipped.failed.title=Skipped -sm.test.runner.magnitude.not.run.failed.title=Not run -sm.test.runner.magnitude.running.failed.title=Running... -sm.test.runner.magnitude.terminated.failed.title=Terminated -sm.test.runner.magnitude.ignored.failed.title=Ignored -sm.test.runner.magnitude.assertion.failed.title=Assertion failed -sm.test.runner.magnitude.testerror.title=Error - sm.test.runner.states.suite.is.empty=Empty test suite. sm.test.runner.states.test.is.ignored=Test ignored. \ No newline at end of file diff --git a/platform/smRunner/smRunner.iml b/platform/smRunner/smRunner.iml index c36eec744bd7..d57738b3bf26 100644 --- a/platform/smRunner/smRunner.iml +++ b/platform/smRunner/smRunner.iml @@ -16,5 +16,6 @@ + \ No newline at end of file