mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[junit] reuse code cleanup
GitOrigin-RevId: 97e36f162e710d628be95068d4f98e58f861eea3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
205cf1eb2b
commit
b2a120546d
@@ -339,13 +339,14 @@ public final class JUnitUtil {
|
||||
}
|
||||
|
||||
public static boolean isJUnit5(GlobalSearchScope scope, Project project) {
|
||||
JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
|
||||
Condition<String> 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) {
|
||||
|
||||
@@ -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<JUnitCon
|
||||
}
|
||||
|
||||
final List<String> 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<JUnitCon
|
||||
if (!hasJUnit5EnginesAPI(globalSearchScope, psiFacade) || !isCustomJUnit5(globalSearchScope)) {
|
||||
PsiClass testAnnotation = dumbService.computeWithAlternativeResolveEnabled(() -> 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<JUnitCon
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasPackageWithDirectories(psiFacade, VINTAGE_ENGINE_NAME, globalSearchScope)) {
|
||||
if (hasPackageWithDirectories(psiFacade, "junit.framework", globalSearchScope)) {
|
||||
if (!JUnitUtil.hasPackageWithDirectories(psiFacade, VINTAGE_ENGINE_NAME, globalSearchScope)) {
|
||||
if (JUnitUtil.hasPackageWithDirectories(psiFacade, "junit.framework", globalSearchScope)) {
|
||||
PsiClass junit4RunnerClass = dumbService.computeWithAlternativeResolveEnabled(
|
||||
() -> ReadAction.nonBlocking(() -> psiFacade.findClass("junit.runner.Version", globalSearchScope)).executeSynchronously());
|
||||
if (junit4RunnerClass != null && isAcceptableVintageVersion()) {
|
||||
@@ -419,7 +419,7 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
|
||||
}
|
||||
|
||||
public static boolean hasJUnit5EnginesAPI(GlobalSearchScope globalSearchScope, JavaPsiFacade psiFacade) {
|
||||
return hasPackageWithDirectories(psiFacade, "org.junit.platform.engine", globalSearchScope);
|
||||
return JUnitUtil.hasPackageWithDirectories(psiFacade, "org.junit.platform.engine", globalSearchScope);
|
||||
}
|
||||
|
||||
private static String getVersion(PsiClass classFromCommon) {
|
||||
@@ -481,15 +481,6 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasPackageWithDirectories(JavaPsiFacade psiFacade,
|
||||
String packageQName,
|
||||
GlobalSearchScope globalSearchScope) {
|
||||
return ReadAction.compute(() -> {
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user