@Nullable public static PsiClass[] getAllTestClasses(final TestClassFilter filter, boolean sync) { final PsiClass[][] holder = new PsiClass[1][]; final Runnable process = () -> { final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); final Collection<PsiClass> set = new LinkedHashSet<>(); final PsiManager manager = PsiManager.getInstance(filter.getProject()); final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(manager.getProject()); final GlobalSearchScope scope = projectScope.intersectWith(filter.getScope()); for (final PsiClass psiClass : AllClassesSearch.search(scope, manager.getProject())) { if (filter.isAccepted(psiClass)) { if (indicator != null) { indicator.setText2( "Found test class " + ReadAction.compute(psiClass::getQualifiedName)); } set.add(psiClass); } } holder[0] = set.toArray(new PsiClass[set.size()]); }; if (sync) { ProgressManager.getInstance() .runProcessWithProgressSynchronously( process, "Searching For Tests...", true, filter.getProject()); } else { process.run(); } return holder[0]; }
public static boolean checkTestNGInClasspath(PsiElement psiElement) { final Project project = psiElement.getProject(); final PsiManager manager = PsiManager.getInstance(project); if (JavaPsiFacade.getInstance(manager.getProject()) .findClass(TestNG.class.getName(), psiElement.getResolveScope()) == null) { if (!ApplicationManager.getApplication().isUnitTestMode()) { if (Messages.showOkCancelDialog( psiElement.getProject(), "TestNG will be added to module classpath", "Unable to convert.", Messages.getWarningIcon()) != Messages.OK) { return false; } } final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement); if (module == null) return false; String url = VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Assert.class))); ModuleRootModificationUtil.addModuleLibrary(module, url); } return true; }