From 41d0532aedfc83caac71b66fe6d1840bece0e276 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Mon, 22 Jan 2018 18:38:31 +0100 Subject: [PATCH] junit: try to check each class in scope --- platform/util/resources/misc/registry.properties | 3 +++ .../com/intellij/execution/junit/TestPackage.java | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 7d56f1980ecc..5734a3ea4775 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -1377,6 +1377,9 @@ batch.inspections.process.external.elements.description=When building graph for junit4.search.4.tests.in.classpath=true junit4.search.4.tests.in.classpath.description=Search for tests in the module output +junit4.search.4.tests.all.in.scope=true +junit4.search.4.tests.all.in.scope.description=Check each class in scope if it's test, then include as test + duplicates.inspection.only.extractable=false duplicates.inspection.only.extractable.description=Highlight duplicate code only if it can be extracted into a method diff --git a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java index 526a23674aff..ae0267d5b405 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java @@ -81,7 +81,19 @@ public class TestPackage extends TestObject { final TestClassFilter classFilter = getClassFilter(data); LOG.assertTrue(classFilter.getBase() != null); long start = System.currentTimeMillis(); - if (Registry.is("junit4.search.4.tests.in.classpath", false)) { + if (Registry.is("junit4.search.4.tests.all.in.scope", true)) { + String packageName = getPackageName(data); + PsiPackage aPackage = JavaPsiFacade.getInstance(myProject).findPackage(packageName); + PsiClass[] classes = aPackage == null + ? PsiClass.EMPTY_ARRAY + : ReadAction.compute(() -> + aPackage.getClasses(GlobalSearchScope.projectScope(myProject) + .intersectWith(classFilter.getScope()))); + Arrays.stream(classes) + .filter(aClass -> ReadAction.compute(() -> classFilter.isAccepted(aClass))) + .forEach(myClasses::add); + } + else if (Registry.is("junit4.search.4.tests.in.classpath", false)) { String packageName = getPackageName(data); String[] classNames = TestClassCollector.collectClassFQNames(packageName, getRootPath(), getConfiguration(), TestPackage::createPredicate); PsiManager manager = PsiManager.getInstance(myProject);