mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
init field in setup: use setup method template(IDEA-86135)
This commit is contained in:
@@ -15,11 +15,14 @@
|
||||
*/
|
||||
package com.intellij.testIntegration;
|
||||
|
||||
import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -104,4 +107,9 @@ public abstract class JavaTestFramework implements TestFramework {
|
||||
public FileTemplateDescriptor getParametersMethodFileTemplateDescriptor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected PsiMethod createSetUpPatternMethod(JVMElementFactory factory) {
|
||||
final FileTemplate template = FileTemplateManager.getInstance().getCodeTemplate(getSetUpMethodFileTemplateDescriptor().getFileName());
|
||||
return factory.createMethodFromText(StringUtil.replace(template.getText(), "${BODY}", ""), null);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ public class GroovyTestFramework extends JavaTestFramework {
|
||||
LOG.assertTrue(clazz.getLanguage() == GroovyFileType.GROOVY_LANGUAGE);
|
||||
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(clazz.getProject());
|
||||
|
||||
final PsiMethod patternMethod = factory.createMethodFromText("protected void setUp() {\nsuper.setUp()\n}", null);
|
||||
final PsiMethod patternMethod = createSetUpPatternMethod(factory);
|
||||
|
||||
final PsiClass baseClass = clazz.getSuperClass();
|
||||
if (baseClass != null) {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class JUnit3Framework extends JavaTestFramework {
|
||||
final PsiManager manager = clazz.getManager();
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
|
||||
final PsiMethod patternMethod = factory.createMethodFromText("protected void setUp() throws Exception {\nsuper.setUp();\n}", null);
|
||||
final PsiMethod patternMethod = createSetUpPatternMethod(factory);
|
||||
|
||||
final PsiClass baseClass = clazz.getSuperClass();
|
||||
if (baseClass != null) {
|
||||
|
||||
@@ -92,7 +92,7 @@ public class JUnit4Framework extends JavaTestFramework {
|
||||
PsiManager manager = clazz.getManager();
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
|
||||
method = factory.createMethodFromText("@org.junit.Before public void setUp() throws Exception {\n}", null);
|
||||
method = createSetUpPatternMethod(factory);
|
||||
PsiMethod existingMethod = clazz.findMethodBySignature(method, false);
|
||||
if (existingMethod != null) {
|
||||
int exit = ApplicationManager.getApplication().isUnitTestMode() ?
|
||||
|
||||
@@ -99,7 +99,7 @@ public class TestNGFramework extends JavaTestFramework {
|
||||
final PsiManager manager = clazz.getManager();
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
String setUpName = "setUp";
|
||||
PsiMethod patternMethod = factory.createMethodFromText("@" + BeforeMethod.class.getName() + "\n protected void " + setUpName + "() throws Exception {}", null);
|
||||
PsiMethod patternMethod = createSetUpPatternMethod(factory);
|
||||
PsiMethod inClass = clazz.findMethodBySignature(patternMethod, false);
|
||||
if (inClass != null) {
|
||||
int exit = ApplicationManager.getApplication().isUnitTestMode() ?
|
||||
|
||||
Reference in New Issue
Block a user