diff --git a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java index 80c54bd6fa6c..abf91e2a388e 100644 --- a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java +++ b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java @@ -339,13 +339,14 @@ public final class JUnitUtil { } public static boolean isJUnit5(GlobalSearchScope scope, Project project) { - JavaPsiFacade facade = JavaPsiFacade.getInstance(project); - Condition foundCondition = aPackageName -> { - PsiPackage aPackage = facade.findPackage(aPackageName); - return aPackage != null && aPackage.getDirectories(scope).length > 0; - }; + return hasPackageWithDirectories(JavaPsiFacade.getInstance(project), TEST5_PACKAGE_FQN, scope); + } - return ReadAction.compute(() -> foundCondition.value(TEST5_PACKAGE_FQN)); + public static boolean hasPackageWithDirectories(JavaPsiFacade facade, String packageQName, GlobalSearchScope globalSearchScope) { + return ReadAction.compute(() -> { + PsiPackage aPackage = facade.findPackage(packageQName); + return aPackage != null && aPackage.getDirectories(globalSearchScope).length > 0; + }); } public static boolean isTestAnnotated(final PsiMethod method) { diff --git a/plugins/junit/src/com/intellij/execution/junit/TestObject.java b/plugins/junit/src/com/intellij/execution/junit/TestObject.java index e88a64457cd3..1b73babe0abb 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestObject.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestObject.java @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.execution.junit; import com.intellij.codeInsight.TestFrameworks; @@ -340,7 +340,7 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState additionalDependencies = new ArrayList<>(); - if (!hasPackageWithDirectories(psiFacade, "org.junit.platform.launcher", globalSearchScope)) { + if (!JUnitUtil.hasPackageWithDirectories(psiFacade, "org.junit.platform.launcher", globalSearchScope)) { downloadDependenciesWhenRequired(project, additionalDependencies, new RepositoryLibraryProperties("org.junit.platform", "junit-platform-launcher", launcherVersion)); } @@ -349,8 +349,8 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState ReadAction.nonBlocking(() -> psiFacade.findClass(JUnitUtil.TEST5_ANNOTATION, globalSearchScope)).executeSynchronously()); String jupiterVersion = ObjectUtils.notNull(getVersion(testAnnotation), "5.0.0"); - if (hasPackageWithDirectories(psiFacade, JUnitUtil.TEST5_PACKAGE_FQN, globalSearchScope)) { - if (!hasPackageWithDirectories(psiFacade, JUPITER_ENGINE_NAME, globalSearchScope)) { + if (JUnitUtil.hasPackageWithDirectories(psiFacade, JUnitUtil.TEST5_PACKAGE_FQN, globalSearchScope)) { + if (!JUnitUtil.hasPackageWithDirectories(psiFacade, JUPITER_ENGINE_NAME, globalSearchScope)) { downloadDependenciesWhenRequired(project, additionalDependencies, new RepositoryLibraryProperties("org.junit.jupiter", "junit-jupiter-engine", jupiterVersion)); } @@ -359,8 +359,8 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState ReadAction.nonBlocking(() -> psiFacade.findClass("junit.runner.Version", globalSearchScope)).executeSynchronously()); if (junit4RunnerClass != null && isAcceptableVintageVersion()) { @@ -419,7 +419,7 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState { - PsiPackage aPackage = psiFacade.findPackage(packageQName); - return aPackage != null && aPackage.getDirectories(globalSearchScope).length > 0; - }); - } - private static GlobalSearchScope getScopeForJUnit(@Nullable Module module, Project project) { return module != null ? GlobalSearchScope.moduleRuntimeScope(module, true) : GlobalSearchScope.allScope(project); }