From 78decdd82c317cfed93286652f00fe00824d08e1 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 15 Apr 2015 21:27:45 +0200 Subject: [PATCH] test-runner: non-null scope guarantee for AbstractTestProxy.getLocation --- .../actions/JavaRerunFailedTestsAction.java | 14 +++++------ .../testframework/JavaAwareFilter.java | 25 +++++++++---------- .../JavaRunConfigurationModule.java | 15 ++++++----- .../sm/runner/SMTestProxyTest.java | 16 ++++++------ .../testframework/AbstractTestProxy.java | 17 ++++++------- .../testframework/TestConsoleProperties.java | 2 ++ .../AbstractRerunFailedTestsAction.java | 20 +++++++-------- .../test/runner/GradleSMTestProxy.java | 4 +-- .../intellij/execution/junit2/TestProxy.java | 7 +++--- .../ui/properties/JUnitConsoleProperties.java | 4 +-- .../testng/model/TestNGConsoleProperties.java | 4 ++- .../testng/model/TestProxy.java | 9 +++---- 12 files changed, 68 insertions(+), 69 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java b/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java index 3be2960bfcf7..6896dcdbea1f 100644 --- a/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java +++ b/java/execution/impl/src/com/intellij/execution/actions/JavaRerunFailedTestsAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -13,11 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * User: anna - * Date: 24-Dec-2008 - */ package com.intellij.execution.actions; import com.intellij.execution.testframework.Filter; @@ -29,16 +24,19 @@ import com.intellij.openapi.ui.ComponentContainer; import com.intellij.psi.search.GlobalSearchScope; import org.jetbrains.annotations.NotNull; +/** + * @author anna + * @since 24-Dec-2008 + */ public class JavaRerunFailedTestsAction extends AbstractRerunFailedTestsAction { public JavaRerunFailedTestsAction(@NotNull ComponentContainer componentContainer, @NotNull TestConsoleProperties consoleProperties) { super(componentContainer); - init(consoleProperties); } @NotNull @Override - protected Filter getFilter(Project project, GlobalSearchScope searchScope) { + protected Filter getFilter(@NotNull Project project, @NotNull GlobalSearchScope searchScope) { return super.getFilter(project, searchScope).and(JavaAwareFilter.METHOD(project, searchScope)); } } diff --git a/java/execution/impl/src/com/intellij/execution/testframework/JavaAwareFilter.java b/java/execution/impl/src/com/intellij/execution/testframework/JavaAwareFilter.java index 86463e06adff..f164f4540932 100644 --- a/java/execution/impl/src/com/intellij/execution/testframework/JavaAwareFilter.java +++ b/java/execution/impl/src/com/intellij/execution/testframework/JavaAwareFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -13,11 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * User: anna - * Date: 20-Feb-2008 - */ package com.intellij.execution.testframework; import com.intellij.execution.Location; @@ -26,18 +21,22 @@ import com.intellij.execution.junit2.info.MethodLocation; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiMethod; import com.intellij.psi.search.GlobalSearchScope; +import org.jetbrains.annotations.NotNull; +/** + * @author anna + * @since 20-Feb-2008 + */ public class JavaAwareFilter { - private JavaAwareFilter() { - } + private JavaAwareFilter() { } - public static Filter METHOD(final Project project, final GlobalSearchScope searchScope) { + public static Filter METHOD(@NotNull final Project project, @NotNull final GlobalSearchScope searchScope) { return new Filter() { + @Override public boolean shouldAccept(final AbstractTestProxy test) { - final Location location = test.getLocation(project, searchScope); - if (location instanceof MethodLocation) return true; - if (location instanceof PsiLocation && location.getPsiElement() instanceof PsiMethod) return true; - return false; + Location location = test.getLocation(project, searchScope); + return location instanceof MethodLocation || + location instanceof PsiLocation && location.getPsiElement() instanceof PsiMethod; } }; } diff --git a/java/execution/openapi/src/com/intellij/execution/configurations/JavaRunConfigurationModule.java b/java/execution/openapi/src/com/intellij/execution/configurations/JavaRunConfigurationModule.java index 20d759e4a26e..f3dcf2e6f401 100644 --- a/java/execution/openapi/src/com/intellij/execution/configurations/JavaRunConfigurationModule.java +++ b/java/execution/openapi/src/com/intellij/execution/configurations/JavaRunConfigurationModule.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -19,7 +19,7 @@ import com.intellij.execution.ExecutionBundle; import com.intellij.execution.JavaExecutionUtil; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; -import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.project.Project; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; @@ -53,12 +53,15 @@ public class JavaRunConfigurationModule extends RunConfigurationModule { return JavaExecutionUtil.findMainClass(getProject(), qualifiedName, getSearchScope()); } + @NotNull public GlobalSearchScope getSearchScope() { - final Module module = getModule(); + Module module = getModule(); if (module != null) { return myClassesInLibraries ? module.getModuleRuntimeScope(true) : GlobalSearchScope.moduleWithDependenciesScope(module); } - return myClassesInLibraries ? GlobalSearchScope.allScope(getProject()) : GlobalSearchScope.projectScope(getProject()); + else { + return myClassesInLibraries ? GlobalSearchScope.allScope(getProject()) : GlobalSearchScope.projectScope(getProject()); + } } public static Collection getModulesForClass(@NotNull final Project project, final String className) { @@ -68,7 +71,7 @@ public class JavaRunConfigurationModule extends RunConfigurationModule { final Set modules = new THashSet(); for (PsiClass aClass : possibleClasses) { - Module module = ModuleUtil.findModuleForPsiElement(aClass); + Module module = ModuleUtilCore.findModuleForPsiElement(aClass); if (module != null) { modules.add(module); } @@ -79,7 +82,7 @@ public class JavaRunConfigurationModule extends RunConfigurationModule { else { final Set result = new HashSet(); for (Module module : modules) { - ModuleUtil.collectModulesDependsOn(module, result); + ModuleUtilCore.collectModulesDependsOn(module, result); } return result; } diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/SMTestProxyTest.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/SMTestProxyTest.java index b6b66ddfc6c3..457f958d1de5 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/SMTestProxyTest.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/SMTestProxyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -16,8 +16,10 @@ package com.intellij.execution.testframework.sm.runner; import com.intellij.execution.testframework.Filter; +import com.intellij.execution.testframework.TestConsoleProperties; import com.intellij.execution.testframework.sm.runner.ui.MockPrinter; import com.intellij.psi.search.GlobalSearchScope; +import org.easymock.classextension.EasyMock; import static com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magnitude; @@ -602,15 +604,13 @@ public class SMTestProxyTest extends BaseSMTRunnerTestCase { } public void testNavigatable() { - //noinspection NullableProblems - assertNull(mySuite.getDescriptor(null, null)); + TestConsoleProperties properties = EasyMock.createMock(TestConsoleProperties.class); + + assertNull(mySuite.getDescriptor(null, properties)); mySuite.addChild(mySimpleTest); - - //noinspection NullableProblems - assertNull(mySuite.getDescriptor(null, null)); - //noinspection NullableProblems - assertNull(mySimpleTest.getDescriptor(null, null)); + assertNull(mySuite.getDescriptor(null, properties)); + assertNull(mySimpleTest.getDescriptor(null, properties)); } public void testShouldRun_Test() { diff --git a/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java b/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java index d30295951ba8..cfc363086f4f 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -13,11 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * User: anna - * Date: 23-May-2007 - */ package com.intellij.execution.testframework; import com.intellij.execution.Location; @@ -32,15 +27,19 @@ import org.jetbrains.annotations.Nullable; import java.util.List; +/** + * @author anna + * @since 23-May-2007 + */ public abstract class AbstractTestProxy extends CompositePrintable { public static final DataKey DATA_KEY = DataKey.create("testProxy"); + protected Printer myPrinter = null; public abstract boolean isInProgress(); public abstract boolean isDefect(); - //todo? public abstract boolean shouldRun(); public abstract int getMagnitude(); @@ -55,9 +54,9 @@ public abstract class AbstractTestProxy extends CompositePrintable { public abstract String getName(); - public abstract Location getLocation(final Project project, GlobalSearchScope searchScope); + public abstract Location getLocation(@NotNull Project project, @NotNull GlobalSearchScope searchScope); - public abstract Navigatable getDescriptor(final Location location, final TestConsoleProperties testConsoleProperties); + public abstract Navigatable getDescriptor(@Nullable Location location, @NotNull TestConsoleProperties properties); public abstract AbstractTestProxy getParent(); diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java b/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java index 568c52898594..b0661e1670cb 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestConsoleProperties.java @@ -80,6 +80,7 @@ public abstract class TestConsoleProperties extends StoringPropertyContainer imp return myProject; } + @NotNull public GlobalSearchScope getScope() { if (myScope == null) { myScope = initScope(); @@ -87,6 +88,7 @@ public abstract class TestConsoleProperties extends StoringPropertyContainer imp return myScope; } + @NotNull protected GlobalSearchScope initScope() { RunConfiguration configuration = getConfiguration(); if (!(configuration instanceof ModuleRunProfile)) { diff --git a/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java b/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java index a7d036b33ef7..d9f87a90cba6 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/actions/AbstractRerunFailedTestsAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -13,11 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * User: anna - * Date: 24-Dec-2008 - */ package com.intellij.execution.testframework.actions; import com.intellij.execution.ExecutionException; @@ -62,6 +57,10 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; +/** + * @author anna + * @since 24-Dec-2008 + */ public class AbstractRerunFailedTestsAction extends AnAction implements AnAction.TransparentUpdate { private static final Logger LOG = Logger.getInstance(AbstractRerunFailedTestsAction.class); @@ -112,16 +111,15 @@ public class AbstractRerunFailedTestsAction extends AnAction implements AnAction } @NotNull - protected List getFailedTests(Project project) { + protected List getFailedTests(@NotNull Project project) { TestFrameworkRunningModel model = getModel(); + if (model == null) return Collections.emptyList(); //noinspection unchecked - return getFilter(project, model != null ? model.getProperties().getScope() : GlobalSearchScope.allScope(project)).select(model != null - ? model.getRoot().getAllTests() - : Collections.emptyList()); + return getFilter(project, model.getProperties().getScope()).select(model.getRoot().getAllTests()); } @NotNull - protected Filter getFilter(Project project, GlobalSearchScope searchScope) { + protected Filter getFilter(@NotNull Project project, @NotNull GlobalSearchScope searchScope) { return getFailuresFilter(); } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/GradleSMTestProxy.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/GradleSMTestProxy.java index 4b89f3c758ee..7d814a018309 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/GradleSMTestProxy.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/GradleSMTestProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -62,7 +62,7 @@ public class GradleSMTestProxy extends SMTestProxy { @Nullable @Override - public Location getLocation(Project project, GlobalSearchScope searchScope) { + public Location getLocation(@NotNull Project project, @NotNull GlobalSearchScope searchScope) { if (getLocationUrl() != null) { if (isDefect() && myStacktrace != null) { final String[] stackTrace = new LineTokenizer(myStacktrace).execute(); diff --git a/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java b/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java index 9f7daa1deade..f7a6ab69f390 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java +++ b/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.execution.junit2; import com.intellij.execution.Location; @@ -110,7 +109,7 @@ public class TestProxy extends AbstractTestProxy { return myParent; } - public Navigatable getDescriptor(final Location location, final TestConsoleProperties testConsoleProperties) { + public Navigatable getDescriptor(@Nullable Location location, @NotNull TestConsoleProperties properties) { return getState().getDescriptor(location); } @@ -134,7 +133,7 @@ public class TestProxy extends AbstractTestProxy { return getState().getMagnitude(); } - public Location getLocation(final Project project, GlobalSearchScope searchScope) { + public Location getLocation(@NotNull final Project project, @NotNull GlobalSearchScope searchScope) { final Location location = getInfo().getLocation(project, searchScope); if (location == null) { return checkParentParameterized(project, searchScope); diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/properties/JUnitConsoleProperties.java b/plugins/junit/src/com/intellij/execution/junit2/ui/properties/JUnitConsoleProperties.java index 721b7afc4ce9..3b3ea763ba7b 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/properties/JUnitConsoleProperties.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/properties/JUnitConsoleProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.execution.junit2.ui.properties; import com.intellij.execution.Executor; @@ -36,6 +35,7 @@ public class JUnitConsoleProperties extends JavaAwareTestConsoleProperties