PsiClass (CreateTestDialog d) { final TestFramework testFrameworkDescriptor = d.getSelectedTestFrameworkDescriptor(); final FileTemplateDescriptor fileTemplateDescriptor = TestIntegrationUtils.MethodKind.TEST_CLASS.getFileTemplateDescriptor(testFrameworkDescriptor); final PsiDirectory targetDirectory = d.getTargetDirectory(); final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(targetDirectory); if (aPackage != null) { final GlobalSearchScope scope = GlobalSearchScopesCore.directoryScope(targetDirectory, false); final PsiClass[] classes = aPackage.findClassByShortName(d.getClassName(), scope); if (classes.length > 0) { if (!FileModificationService.getInstance().preparePsiElementForWrite(classes[0])) { return null; } return classes[0]; } } if (fileTemplateDescriptor != null) { final PsiClass classFromTemplate = createTestClassFromCodeTemplate(d, fileTemplateDescriptor, targetDirectory); if (classFromTemplate != null) { return classFromTemplate; } } return JavaDirectoryService.getInstance().createClass(targetDirectory, d.getClassName()); }