Generate Test: setup/teardown+ framework selection (IDEA-19813, IDEA-54089) cidr/96.446 idea/96.447 pycharm/96.448
authorAnton Makeev <Anton.Makeev@jetbrains.com>
Tue, 22 Jun 2010 21:23:06 +0000 (01:23 +0400)
committerAnton Makeev <Anton.Makeev@jetbrains.com>
Tue, 22 Jun 2010 21:28:11 +0000 (01:28 +0400)
Generate Test: works for empty classes (IDEA-52124)

30 files changed:
java/java-impl/src/com/intellij/refactoring/introduceField/BaseExpressionToFieldHandler.java
java/java-impl/src/com/intellij/refactoring/introduceField/LocalToFieldHandler.java
java/java-impl/src/com/intellij/testIntegration/BaseGenerateTestSupportMethodAction.java [new file with mode: 0644]
java/java-impl/src/com/intellij/testIntegration/GenerateSetUpMethodAction.java [moved from java/openapi/src/com/intellij/codeInsight/TestFramework.java with 60% similarity]
java/java-impl/src/com/intellij/testIntegration/GenerateTearDownMethodAction.java [new file with mode: 0644]
java/java-impl/src/com/intellij/testIntegration/GenerateTestMethodAction.java
java/java-impl/src/com/intellij/testIntegration/JavaTestFramework.java [new file with mode: 0644]
java/java-impl/src/com/intellij/testIntegration/JavaTestFrameworkDescriptor.java [deleted file]
java/java-impl/src/com/intellij/testIntegration/TestIntegrationUtils.java
java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestAction.java
java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestDialog.java
java/openapi/src/com/intellij/codeInsight/TestUtil.java
platform/lang-api/src/com/intellij/testIntegration/TestFramework.java [moved from platform/lang-api/src/com/intellij/testIntegration/TestFrameworkDescriptor.java with 61% similarity]
platform/platform-resources-en/src/messages/ActionsBundle.properties
plugins/junit/src/META-INF/plugin.xml
plugins/junit/src/com/intellij/execution/junit/JUnit3Framework.java [new file with mode: 0644]
plugins/junit/src/com/intellij/execution/junit/JUnit3FrameworkDescriptor.java [deleted file]
plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java [new file with mode: 0644]
plugins/junit/src/com/intellij/execution/junit/JUnit4FrameworkDescriptor.java [deleted file]
plugins/junit/src/com/intellij/execution/junit/JUnitConfigurationType.java
plugins/junit/src/com/intellij/execution/junit/JUnitTestFramework.java [deleted file]
plugins/testng/src/META-INF/plugin.xml
plugins/testng/src/com/theoryinpractice/testng/TestNGFramework.java [new file with mode: 0644]
plugins/testng/src/com/theoryinpractice/testng/TestNGFrameworkDescriptor.java [deleted file]
plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfigurationType.java
plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java
plugins/testng/src/fileTemplates/code/TestNG SetUp Method.java.ft
plugins/testng/src/fileTemplates/code/TestNG TearDown Method.java.ft
resources/src/META-INF/IdeaPlugin.xml
resources/src/idea/IdeaActions.xml

index a0e1176346f846b27e1f9c0bd293ee4c200cb77a..ba351f2a84554cff0205bdeb95f225128cc9d152 100644 (file)
@@ -425,7 +425,7 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase
   private void addInitializationToSetUp(final PsiExpression initializer,
                                         final PsiField field,
                                         final OccurenceManager occurenceManager, final boolean replaceAll) throws IncorrectOperationException {
-    final PsiMethod setupMethod = TestUtil.findSetUpMethod(myParentClass);
+    final PsiMethod setupMethod = TestUtil.findOrCreateSetUpMethod(myParentClass);
 
     assert setupMethod != null;
 
index 44aac11d613769426000aa9ab2f85369fbb765e2..0f3ef3cac69be123cbc77ac65dcc6c5120b9a26b 100644 (file)
@@ -226,7 +226,7 @@ public abstract class LocalToFieldHandler {
 
   private void addInitializationToSetUp(final PsiLocalVariable local, final PsiField field, final PsiElementFactory factory)
                                                                                                                              throws IncorrectOperationException {
-    PsiMethod inClass = TestUtil.findSetUpMethod(field.getContainingClass());
+    PsiMethod inClass = TestUtil.findOrCreateSetUpMethod(field.getContainingClass());
     assert inClass != null;
     PsiStatement assignment = createAssignment(local, field.getName(), factory);
     final PsiCodeBlock body = inClass.getBody();
diff --git a/java/java-impl/src/com/intellij/testIntegration/BaseGenerateTestSupportMethodAction.java b/java/java-impl/src/com/intellij/testIntegration/BaseGenerateTestSupportMethodAction.java
new file mode 100644 (file)
index 0000000..123b2fc
--- /dev/null
@@ -0,0 +1,213 @@
+/*
+ * Copyright 2000-2009 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.testIntegration;
+
+import com.intellij.codeInsight.CodeInsightActionHandler;
+import com.intellij.codeInsight.CodeInsightUtilBase;
+import com.intellij.codeInsight.generation.GenerateMembersUtil;
+import com.intellij.codeInsight.generation.GenerationInfo;
+import com.intellij.codeInsight.generation.actions.BaseGenerateAction;
+import com.intellij.codeInsight.hint.HintManager;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.popup.PopupChooserBuilder;
+import com.intellij.psi.*;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.util.Function;
+import com.intellij.util.IncorrectOperationException;
+import com.intellij.util.SmartList;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class BaseGenerateTestSupportMethodAction extends BaseGenerateAction {
+  protected static final Logger LOG = Logger.getInstance("#" + BaseGenerateTestSupportMethodAction.class.getName());
+
+  public BaseGenerateTestSupportMethodAction(TestIntegrationUtils.MethodKind methodKind) {
+    super(new MyHandler(methodKind));
+  }
+
+  @Override
+  protected PsiClass getTargetClass(Editor editor, PsiFile file) {
+    return findTargetClass(editor, file);
+  }
+
+  private static PsiClass findTargetClass(Editor editor, PsiFile file) {
+    int offset = editor.getCaretModel().getOffset();
+    PsiElement element = file.findElementAt(offset);
+    return TestIntegrationUtils.findOuterClass(element);
+  }
+
+  @Override
+  protected boolean isValidForClass(PsiClass targetClass) {
+    List<TestFramework> frameworks = findSuitableFrameworks(targetClass);
+    if (frameworks.isEmpty()) return false;
+
+    for (TestFramework each : frameworks) {
+      if (isValidFor(targetClass, each)) return true;
+    }
+    return false;
+  }
+
+  protected boolean isValidFor(PsiClass targetClass, TestFramework framework) {
+    return true;
+  }
+
+  private static List<TestFramework> findSuitableFrameworks(PsiClass targetClass) {
+    TestFramework[] frameworks = Extensions.getExtensions(TestFramework.EXTENSION_NAME);
+    for (TestFramework each : frameworks) {
+      if (each.isTestClass(targetClass)) {
+        return Collections.singletonList(each);
+      }
+    }
+
+    List<TestFramework> result = new SmartList<TestFramework>();
+    for (TestFramework each : frameworks) {
+      if (each.isPotentialTestClass(targetClass)) {
+        result.add(each);
+      }
+    }
+    return result;
+  }
+
+  private static class MyHandler implements CodeInsightActionHandler {
+    private TestIntegrationUtils.MethodKind myMethodKind;
+
+    private MyHandler(TestIntegrationUtils.MethodKind methodKind) {
+      myMethodKind = methodKind;
+    }
+
+    public void invoke(@NotNull Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
+      final PsiClass targetClass = findTargetClass(editor, file);
+      final List<TestFramework> frameworks = findSuitableFrameworks(targetClass);
+      if (frameworks.isEmpty()) return;
+
+      if (frameworks.size() == 1) {
+        doGenerate(editor, file, targetClass, frameworks.get(0));
+      } else {
+        final JList list = new JList(frameworks.toArray(new TestFramework[frameworks.size()]));
+        list.setCellRenderer(new DefaultListCellRenderer() {
+          @Override
+          public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+            Component result = super.getListCellRendererComponent(list, "", index, isSelected, cellHasFocus);
+            if (value == null) return result;
+            TestFramework framework = (TestFramework)value;
+
+            setIcon(framework.getIcon());
+            setText(framework.getName());
+            
+            return result;
+          }
+        });
+
+        final Runnable runnable = new Runnable() {
+          public void run() {
+            TestFramework selected = (TestFramework)list.getSelectedValue();
+            if (selected == null) return;
+            doGenerate(editor, file, targetClass, selected);
+          }
+        };
+
+        PopupChooserBuilder builder = new PopupChooserBuilder(list);
+        builder.setFilteringEnabled(new Function<Object, String>() {
+          @Override
+          public String fun(Object o) {
+            return ((TestFramework)o).getName();
+          }
+        });
+
+        builder
+          .setTitle("Choose Framework")
+          .setItemChoosenCallback(runnable)
+          .setMovable(true)
+          .createPopup().showInBestPositionFor(editor);
+      }
+    }
+
+    private void doGenerate(final Editor editor, final PsiFile file, final PsiClass targetClass, final TestFramework framework) {
+      ApplicationManager.getApplication().runWriteAction(new Runnable() {
+        @Override
+        public void run() {
+          try {
+            PsiMethod method = generateDummyMethod(editor, file);
+            if (method == null) return;
+
+            TestIntegrationUtils.runTestMethodTemplate(myMethodKind,
+                                                       framework,
+                                                       editor,
+                                                       targetClass,
+                                                       method,
+                                                       "name",
+                                                       false);
+          }
+          catch (IncorrectOperationException e) {
+            HintManager.getInstance().showErrorHint(editor, "Cannot generate method: " + e.getMessage());
+            LOG.warn(e);
+          }
+        }
+      });
+    }
+
+    @Nullable
+    private PsiMethod generateDummyMethod(Editor editor, PsiFile file) throws IncorrectOperationException {
+      List<GenerationInfo> members = new ArrayList<GenerationInfo>();
+
+      final PsiMethod method = TestIntegrationUtils.createDummyMethod(file.getProject());
+      final PsiMethod[] result = new PsiMethod[1];
+
+      members.add(new GenerationInfo() {
+        @NotNull
+        public PsiMember getPsiMember() {
+          return method;
+        }
+
+        public void insert(PsiClass aClass, PsiElement anchor, boolean before) throws IncorrectOperationException {
+          result[0] = (PsiMethod)GenerateMembersUtil.insert(aClass, method, anchor, before);
+        }
+      });
+
+      int offset = findOffsetToInsertMethodTo(editor, file);
+
+      GenerateMembersUtil.insertMembersAtOffset(file, offset, members);
+      return CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(result[0]);
+    }
+
+    private int findOffsetToInsertMethodTo(Editor editor, PsiFile file) {
+      int result = editor.getCaretModel().getOffset();
+
+      PsiClass classAtCursor = PsiTreeUtil.getParentOfType(file.findElementAt(result), PsiClass.class, false);
+
+      while (classAtCursor != null && !(classAtCursor.getParent() instanceof PsiFile)) {
+        result = classAtCursor.getTextRange().getEndOffset();
+        classAtCursor = PsiTreeUtil.getParentOfType(classAtCursor, PsiClass.class);
+      }
+
+      return result;
+    }
+
+    public boolean startInWriteAction() {
+      return false;
+    }
+  }
+}
similarity index 60%
rename from java/openapi/src/com/intellij/codeInsight/TestFramework.java
rename to java/java-impl/src/com/intellij/testIntegration/GenerateSetUpMethodAction.java
index 037425648b9e6948e445a850df29e7963b0b3fee..b70a2ea6bcc1ea48df61bfcc59bd886232d036f0 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-/*
- * User: anna
- * Date: 28-May-2007
- */
-package com.intellij.codeInsight;
+package com.intellij.testIntegration;
 
 import com.intellij.psi.PsiClass;
-import com.intellij.psi.PsiMethod;
-import com.intellij.util.IncorrectOperationException;
 
-public interface TestFramework {
-  boolean isTestKlass(PsiClass psiClass);
-  PsiMethod findSetUpMethod(PsiClass psiClass) throws IncorrectOperationException;
+public class GenerateSetUpMethodAction extends BaseGenerateTestSupportMethodAction {
+  public GenerateSetUpMethodAction() {
+    super(TestIntegrationUtils.MethodKind.SET_UP);
+  }
 
-  boolean isTestMethodOrConfig(PsiMethod psiMethod);
-}
\ No newline at end of file
+  @Override
+  protected boolean isValidFor(PsiClass targetClass, TestFramework framework) {
+    return super.isValidFor(targetClass, framework) && framework.findSetUpMethod(targetClass) == null;
+  }
+}
diff --git a/java/java-impl/src/com/intellij/testIntegration/GenerateTearDownMethodAction.java b/java/java-impl/src/com/intellij/testIntegration/GenerateTearDownMethodAction.java
new file mode 100644 (file)
index 0000000..26fd871
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2000-2009 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.testIntegration;
+
+import com.intellij.psi.PsiClass;
+
+public class GenerateTearDownMethodAction extends BaseGenerateTestSupportMethodAction {
+  public GenerateTearDownMethodAction() {
+    super(TestIntegrationUtils.MethodKind.TEAR_DOWN);
+  }
+
+  @Override
+  protected boolean isValidFor(PsiClass targetClass, TestFramework framework) {
+    return super.isValidFor(targetClass, framework) && framework.findTearDownMethod(targetClass) == null;
+  }
+}
index de32acbf0d95636f70ad1990f3afa48ca1b7d8c7..32b116af5fb9b2aa35ccc0e73e79406d9b5167bd 100644 (file)
  */
 package com.intellij.testIntegration;
 
-import com.intellij.codeInsight.CodeInsightActionHandler;
-import com.intellij.codeInsight.CodeInsightUtilBase;
-import com.intellij.codeInsight.generation.GenerateMembersUtil;
-import com.intellij.codeInsight.generation.GenerationInfo;
-import com.intellij.codeInsight.generation.actions.BaseGenerateAction;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.extensions.Extensions;
-import com.intellij.openapi.project.Project;
-import com.intellij.psi.*;
-import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.util.IncorrectOperationException;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class GenerateTestMethodAction extends BaseGenerateAction {
+public class GenerateTestMethodAction extends BaseGenerateTestSupportMethodAction {
   public GenerateTestMethodAction() {
-    super(new MyHandler());
-  }
-
-  @Override
-  protected PsiClass getTargetClass(Editor editor, PsiFile file) {
-    return findTargetClass(editor, file);
-  }
-
-  private static PsiClass findTargetClass(Editor editor, PsiFile file) {
-    int offset = editor.getCaretModel().getOffset();
-    PsiElement element = file.findElementAt(offset);
-    return TestIntegrationUtils.findOuterClass(element);
-  }
-
-  @Override
-  protected boolean isValidForClass(PsiClass targetClass) {
-    return TestIntegrationUtils.isTest(targetClass) && findDescriptor(targetClass) != null;
-  }
-
-  private static TestFrameworkDescriptor findDescriptor(PsiClass targetClass) {
-    for (TestFrameworkDescriptor each : Extensions.getExtensions(TestFrameworkDescriptor.EXTENSION_NAME)) {
-      if (each.isTestClass(targetClass)) {
-        return each;
-      }
-    }
-    return null;
-  }
-
-  private static class MyHandler implements CodeInsightActionHandler {
-    public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
-      try {
-        PsiMethod method = generateDummyMethod(editor, file);
-        if (method == null) return;
-
-        PsiClass targetClass = findTargetClass(editor, file);
-        TestIntegrationUtils.runTestMethodTemplate(TestIntegrationUtils.MethodKind.TEST,
-                                                   findDescriptor(targetClass),
-                                                   editor,
-                                                   targetClass,
-                                                   method,
-                                                   "name",
-                                                   false);
-      }
-      catch (IncorrectOperationException e) {
-        throw new RuntimeException(e);
-      }
-    }
-
-    @Nullable
-    private PsiMethod generateDummyMethod(Editor editor, PsiFile file) throws IncorrectOperationException {
-      List<GenerationInfo> members = new ArrayList<GenerationInfo>();
-
-      final PsiMethod method = TestIntegrationUtils.createDummyMethod(file.getProject());
-      final PsiMethod[] result = new PsiMethod[1];
-
-      members.add(new GenerationInfo() {
-        @NotNull
-        public PsiMember getPsiMember() {
-          return method;
-        }
-
-        public void insert(PsiClass aClass, PsiElement anchor, boolean before) throws IncorrectOperationException {
-          result[0] = (PsiMethod)GenerateMembersUtil.insert(aClass, method, anchor, before);
-        }
-      });
-
-      int offset = findOffetToInsertMethodTo(editor, file);
-      GenerateMembersUtil.insertMembersAtOffset(file, offset, members);
-
-      return CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(result[0]);
-    }
-
-    private int findOffetToInsertMethodTo(Editor editor, PsiFile file) {
-      int result = editor.getCaretModel().getOffset();
-
-      PsiClass classAtCursor = PsiTreeUtil.getParentOfType(file.findElementAt(result), PsiClass.class, false);
-
-      while (classAtCursor != null && !(classAtCursor.getParent() instanceof PsiFile)) {
-        result = classAtCursor.getTextRange().getEndOffset();
-        classAtCursor = PsiTreeUtil.getParentOfType(classAtCursor, PsiClass.class);
-      }
-
-      return result;
-    }
-
-    public boolean startInWriteAction() {
-      return true;
-    }
+    super(TestIntegrationUtils.MethodKind.TEST);
   }
 }
diff --git a/java/java-impl/src/com/intellij/testIntegration/JavaTestFramework.java b/java/java-impl/src/com/intellij/testIntegration/JavaTestFramework.java
new file mode 100644 (file)
index 0000000..8cf21dd
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2000-2009 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.testIntegration;
+
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.roots.ProjectRootManager;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.*;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public abstract class JavaTestFramework implements TestFramework {
+  public boolean isLibraryAttached(@NotNull Module module) {
+    GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
+    PsiClass c = JavaPsiFacade.getInstance(module.getProject()).findClass(getMarkerClassFQName(), scope);
+    return c != null;
+  }
+
+  protected abstract String getMarkerClassFQName();
+
+  public boolean isTestClass(@NotNull PsiElement clazz) {
+    return clazz instanceof PsiClass && isTestClass((PsiClass)clazz, false);
+  }
+
+  @Override
+  public boolean isPotentialTestClass(@NotNull PsiElement clazz) {
+    return clazz instanceof PsiClass && isTestClass((PsiClass)clazz, true);
+  }
+
+  protected abstract boolean isTestClass(PsiClass clazz, boolean canBePotential);
+
+  protected boolean isUnderTestSources(PsiClass clazz) {
+    PsiFile psiFile = clazz.getContainingFile();
+    VirtualFile vFile = psiFile.getVirtualFile();
+    if (vFile == null) return false;
+    return ProjectRootManager.getInstance(clazz.getProject()).getFileIndex().isInTestSourceContent(vFile);
+  }
+
+  @Override
+  @Nullable
+  public PsiElement findSetUpMethod(@NotNull PsiElement clazz) {
+    return clazz instanceof PsiClass ? findSetUpMethod((PsiClass)clazz) : null;
+  }
+
+  @Nullable
+  protected abstract PsiMethod findSetUpMethod(@NotNull PsiClass clazz);
+
+  @Override
+  @Nullable
+  public PsiElement findTearDownMethod(@NotNull PsiElement clazz) {
+    return clazz instanceof PsiClass ? findTearDownMethod((PsiClass)clazz) : null;
+  }
+
+  @Nullable
+  protected abstract PsiMethod findTearDownMethod(@NotNull PsiClass clazz);
+
+  @Override
+  public PsiElement findOrCreateSetUpMethod(@NotNull PsiElement clazz) throws IncorrectOperationException {
+    return clazz instanceof PsiClass ? findOrCreateSetUpMethod((PsiClass)clazz) : null;
+  }
+
+  @Nullable
+  protected abstract PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException;
+}
diff --git a/java/java-impl/src/com/intellij/testIntegration/JavaTestFrameworkDescriptor.java b/java/java-impl/src/com/intellij/testIntegration/JavaTestFrameworkDescriptor.java
deleted file mode 100644 (file)
index 90b9609..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.testIntegration;
-
-import com.intellij.openapi.module.Module;
-import com.intellij.psi.JavaPsiFacade;
-import com.intellij.psi.PsiClass;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.search.GlobalSearchScope;
-
-public abstract class JavaTestFrameworkDescriptor implements TestFrameworkDescriptor {
-  public boolean isLibraryAttached(Module m) {
-    GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(m);
-    PsiClass c = JavaPsiFacade.getInstance(m.getProject()).findClass(getMarkerClassFQName(), scope);
-    return c != null;
-  }
-
-  protected abstract String getMarkerClassFQName();
-
- public boolean isTestClass(PsiElement element) {
-   return element instanceof PsiClass && isTestClass((PsiClass)element);
- }
-
- public abstract boolean isTestClass(PsiClass clazz);
-}
index 9cc10b93819026a178b0f7cae5907d66ec23e658..e2bf9db8b59207d026124e5be7e9a5a7a1dbfa17 100644 (file)
@@ -47,19 +47,19 @@ public class TestIntegrationUtils {
 
   public enum MethodKind {
     SET_UP {
-      public FileTemplateDescriptor getFileTemplateDescriptor(TestFrameworkDescriptor frameworkDescriptor) {
-        return frameworkDescriptor.getSetUpMethodFileTemplateDescriptor();
+      public FileTemplateDescriptor getFileTemplateDescriptor(TestFramework framework) {
+        return framework.getSetUpMethodFileTemplateDescriptor();
       }},
     TEAR_DOWN {
-      public FileTemplateDescriptor getFileTemplateDescriptor(TestFrameworkDescriptor frameworkDescriptor) {
-        return frameworkDescriptor.getTearDownMethodFileTemplateDescriptor();
+      public FileTemplateDescriptor getFileTemplateDescriptor(TestFramework framework) {
+        return framework.getTearDownMethodFileTemplateDescriptor();
       }},
     TEST {
-      public FileTemplateDescriptor getFileTemplateDescriptor(TestFrameworkDescriptor frameworkDescriptor) {
-        return frameworkDescriptor.getTestMethodFileTemplateDescriptor();
+      public FileTemplateDescriptor getFileTemplateDescriptor(TestFramework framework) {
+        return framework.getTestMethodFileTemplateDescriptor();
       }};
 
-    public abstract FileTemplateDescriptor getFileTemplateDescriptor(TestFrameworkDescriptor frameworkDescriptor);
+    public abstract FileTemplateDescriptor getFileTemplateDescriptor(TestFramework framework);
   }
 
   public static boolean isTest(PsiElement element) {
@@ -122,13 +122,13 @@ public class TestIntegrationUtils {
   }
 
   public static void runTestMethodTemplate(MethodKind methodKind,
-                                           TestFrameworkDescriptor descriptor,
+                                           TestFramework framework,
                                            final Editor editor,
                                            PsiClass targetClass,
                                            final PsiMethod method,
                                            String name,
                                            boolean automatic) {
-    Template template = createTestMethodTemplate(methodKind, descriptor, targetClass, name, automatic);
+    Template template = createTestMethodTemplate(methodKind, framework, targetClass, name, automatic);
     template.setToIndent(true);
     template.setToReformat(true);
     template.setToShortenLongNames(true);
@@ -168,7 +168,7 @@ public class TestIntegrationUtils {
   }
 
   private static Template createTestMethodTemplate(MethodKind methodKind,
-                                                   TestFrameworkDescriptor descriptor,
+                                                   TestFramework descriptor,
                                                    PsiClass targetClass,
                                                    String name,
                                                    boolean automatic) {
index 3077be1cc536c110bc62799050c9969a2542b6b5..c7fee6885760df02974a95012db2cb3c3625f5ff 100644 (file)
@@ -35,7 +35,7 @@ import com.intellij.psi.impl.source.PostprocessReformattingAspect;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.refactoring.util.classMembers.MemberInfo;
-import com.intellij.testIntegration.TestFrameworkDescriptor;
+import com.intellij.testIntegration.TestFramework;
 import com.intellij.testIntegration.TestIntegrationUtils;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
@@ -54,7 +54,7 @@ public class CreateTestAction extends PsiElementBaseIntentionAction {
   }
 
   public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
-    if (Extensions.getExtensions(TestFrameworkDescriptor.EXTENSION_NAME).length == 0) return false;
+    if (Extensions.getExtensions(TestFramework.EXTENSION_NAME).length == 0) return false;
 
     if (!isAvailableForElement(element)) return false;
 
@@ -177,7 +177,7 @@ public class CreateTestAction extends PsiElementBaseIntentionAction {
 
   private void addTestMethods(Editor editor,
                               PsiClass targetClass,
-                              TestFrameworkDescriptor descriptor,
+                              TestFramework descriptor,
                               Collection<MemberInfo> methods,
                               boolean generateBefore,
                               boolean generateAfter) throws IncorrectOperationException {
@@ -185,14 +185,14 @@ public class CreateTestAction extends PsiElementBaseIntentionAction {
       generateMethod(TestIntegrationUtils.MethodKind.SET_UP, descriptor, targetClass, editor, "setUp");
     }
     if (generateAfter) {
-      generateMethod(TestIntegrationUtils.MethodKind.TEAR_DOWN, descriptor, targetClass, editor, "tearUp");
+      generateMethod(TestIntegrationUtils.MethodKind.TEAR_DOWN, descriptor, targetClass, editor, "tearDown");
     }
     for (MemberInfo m : methods) {
       generateMethod(TestIntegrationUtils.MethodKind.TEST, descriptor, targetClass, editor, m.getMember().getName());
     }
   }
 
-  private void generateMethod(TestIntegrationUtils.MethodKind methodKind, TestFrameworkDescriptor descriptor, PsiClass targetClass, Editor editor, String name) {
+  private void generateMethod(TestIntegrationUtils.MethodKind methodKind, TestFramework descriptor, PsiClass targetClass, Editor editor, String name) {
     PsiMethod method = (PsiMethod)targetClass.add(TestIntegrationUtils.createDummyMethod(targetClass.getProject()));
     PsiDocumentManager.getInstance(targetClass.getProject()).doPostponedOperationsAndUnblockDocument(editor.getDocument());
     TestIntegrationUtils.runTestMethodTemplate(methodKind, descriptor, editor, targetClass, method, name, true);
index 0d170970cd8bf455463eed5928f85384bd0633c6..fd1b11722c1784da8cafa06ae74454f162ae3961 100644 (file)
@@ -18,7 +18,10 @@ package com.intellij.testIntegration.createTest;
 import com.intellij.CommonBundle;
 import com.intellij.codeInsight.CodeInsightBundle;
 import com.intellij.codeInsight.daemon.impl.quickfix.OrderEntryFix;
-import com.intellij.ide.util.*;
+import com.intellij.ide.util.PackageUtil;
+import com.intellij.ide.util.PropertiesComponent;
+import com.intellij.ide.util.TreeClassChooser;
+import com.intellij.ide.util.TreeClassChooserFactory;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.CustomShortcutSet;
@@ -46,7 +49,7 @@ import com.intellij.refactoring.ui.PackageNameReferenceEditorCombo;
 import com.intellij.refactoring.util.RefactoringMessageUtil;
 import com.intellij.refactoring.util.RefactoringUtil;
 import com.intellij.refactoring.util.classMembers.MemberInfo;
-import com.intellij.testIntegration.TestFrameworkDescriptor;
+import com.intellij.testIntegration.TestFramework;
 import com.intellij.testIntegration.TestIntegrationUtils;
 import com.intellij.ui.*;
 import com.intellij.util.IncorrectOperationException;
@@ -72,7 +75,7 @@ public class CreateTestDialog extends DialogWrapper {
   private final Module myTargetModule;
 
   private PsiDirectory myTargetDirectory;
-  private TestFrameworkDescriptor mySelectedTestDescriptor;
+  private TestFramework mySelectedFramework;
 
   private final List<JRadioButton> myLibraryButtons = new ArrayList<JRadioButton>();
   private JTextField myTargetClassNameField;
@@ -112,7 +115,7 @@ public class CreateTestDialog extends DialogWrapper {
     Map<String, JRadioButton> nameToButtonMap = new HashMap<String, JRadioButton>();
     List<Pair<String, JRadioButton>> attachedLibraries = new ArrayList<Pair<String, JRadioButton>>();
 
-    for (final TestFrameworkDescriptor descriptor : Extensions.getExtensions(TestFrameworkDescriptor.EXTENSION_NAME)) {
+    for (final TestFramework descriptor : Extensions.getExtensions(TestFramework.EXTENSION_NAME)) {
       final JRadioButton b = new JRadioButton(descriptor.getName());
       myLibraryButtons.add(b);
       group.add(b);
@@ -156,7 +159,7 @@ public class CreateTestDialog extends DialogWrapper {
       public void actionPerformed(ActionEvent e) {
         ApplicationManager.getApplication().runWriteAction(new Runnable() {
           public void run() {
-            OrderEntryFix.addJarToRoots(mySelectedTestDescriptor.getLibraryPath(), myTargetModule, null);
+            OrderEntryFix.addJarToRoots(mySelectedFramework.getLibraryPath(), myTargetModule, null);
           }
         });
         myFixLibraryPanel.setVisible(false);
@@ -199,14 +202,14 @@ public class CreateTestDialog extends DialogWrapper {
     updateMethodsTable();
   }
 
-  private void onLibrarySelected(TestFrameworkDescriptor descriptor) {
+  private void onLibrarySelected(TestFramework descriptor) {
     String text = CodeInsightBundle.message("intention.create.test.dialog.library.not.found", descriptor.getName());
     myFixLibraryLabel.setText(text);
     myFixLibraryPanel.setVisible(!descriptor.isLibraryAttached(myTargetModule));
 
     String superClass = descriptor.getDefaultSuperClass();
     mySuperClassField.setText(superClass == null ? "" : superClass);
-    mySelectedTestDescriptor = descriptor;
+    mySelectedFramework = descriptor;
   }
 
   private void setPreferredSize(JTextField field) {
@@ -236,7 +239,7 @@ public class CreateTestDialog extends DialogWrapper {
   }
 
   private void saveDefaultLibraryName() {
-    getProperties().setValue(DEFAULT_LIBRARY_NAME_PROPERTY, mySelectedTestDescriptor.getName());
+    getProperties().setValue(DEFAULT_LIBRARY_NAME_PROPERTY, mySelectedFramework.getName());
   }
 
   private void restoreShowInheritedMembersStatus() {
@@ -410,8 +413,8 @@ public class CreateTestDialog extends DialogWrapper {
     return myGenerateBeforeBox.isSelected();
   }
 
-  public TestFrameworkDescriptor getSelectedTestFrameworkDescriptor() {
-    return mySelectedTestDescriptor;
+  public TestFramework getSelectedTestFrameworkDescriptor() {
+    return mySelectedFramework;
   }
 
   protected void doOKAction() {
index b22d4f2f211fa62f5d2c0d2de3cf79417f19c623..1cb45b145f710f0c1b7e05b50bb02dd0f43352b1 100644 (file)
  */
 package com.intellij.codeInsight;
 
-import com.intellij.openapi.extensions.ExtensionPointName;
 import com.intellij.openapi.extensions.Extensions;
 import com.intellij.psi.PsiClass;
 import com.intellij.psi.PsiMethod;
+import com.intellij.testIntegration.TestFramework;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.Nullable;
 
 public class TestUtil {
-  public static final ExtensionPointName<TestFramework> TEST_FRAMEWORK = ExtensionPointName.create("com.intellij.testFramework");
-
-  private TestUtil() {}
+  private TestUtil() {
+  }
 
   public static boolean isTestClass(final PsiClass psiClass) {
-    final TestFramework[] testFrameworks = Extensions.getExtensions(TEST_FRAMEWORK);
+    final TestFramework[] testFrameworks = Extensions.getExtensions(TestFramework.EXTENSION_NAME);
     for (TestFramework framework : testFrameworks) {
-      if (framework.isTestKlass(psiClass)) {
+      if (framework.isTestClass(psiClass)) {
         return true;
       }
     }
@@ -43,12 +42,12 @@ public class TestUtil {
   }
 
   @Nullable
-  public static PsiMethod findSetUpMethod(final PsiClass psiClass) {
-    final TestFramework[] testFrameworks = Extensions.getExtensions(TEST_FRAMEWORK);
+  public static PsiMethod findOrCreateSetUpMethod(final PsiClass psiClass) {
+    final TestFramework[] testFrameworks = Extensions.getExtensions(TestFramework.EXTENSION_NAME);
     for (TestFramework framework : testFrameworks) {
-      if (framework.isTestKlass(psiClass)) {
+      if (framework.isTestClass(psiClass)) {
         try {
-          final PsiMethod setUpMethod = framework.findSetUpMethod(psiClass);
+          final PsiMethod setUpMethod = (PsiMethod)framework.findOrCreateSetUpMethod(psiClass);
           if (setUpMethod != null) {
             return setUpMethod;
           }
@@ -60,13 +59,4 @@ public class TestUtil {
     }
     return null;
   }
-
-  public static boolean isTestMethodOrConfig(PsiMethod psiMethod) {
-    for (TestFramework framework : Extensions.getExtensions(TEST_FRAMEWORK)) {
-      if (framework.isTestMethodOrConfig(psiMethod)) {
-        return true;
-      }
-    }
-    return false;
-  }
 }
\ No newline at end of file
similarity index 61%
rename from platform/lang-api/src/com/intellij/testIntegration/TestFrameworkDescriptor.java
rename to platform/lang-api/src/com/intellij/testIntegration/TestFramework.java
index a8f01d254c2c3fdb577e8b302eec74ae7a7dc1d7..7dce065423b7b2d7b73694189c509ed1bdfd20a0 100644 (file)
@@ -20,21 +20,41 @@ import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
 import com.intellij.openapi.extensions.ExtensionPointName;
 import com.intellij.openapi.module.Module;
 import com.intellij.psi.PsiElement;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-public interface TestFrameworkDescriptor {
-  ExtensionPointName<TestFrameworkDescriptor> EXTENSION_NAME = ExtensionPointName.create("com.intellij.testFrameworkDescriptor");
+import javax.swing.*;
 
+public interface TestFramework {
+  ExtensionPointName<TestFramework> EXTENSION_NAME = ExtensionPointName.create("com.intellij.testFramework");
+
+  @NotNull
   String getName();
 
-  boolean isLibraryAttached(Module m);
+  @NotNull
+  Icon getIcon();
+
+  boolean isLibraryAttached(@NotNull Module module);
 
+  @NotNull
   String getLibraryPath();
 
   @Nullable
   String getDefaultSuperClass();
 
-  boolean isTestClass(PsiElement element);
+  boolean isTestClass(@NotNull PsiElement clazz);
+
+  boolean isPotentialTestClass(@NotNull PsiElement clazz);
+
+  @Nullable
+  PsiElement findSetUpMethod(@NotNull PsiElement clazz);
+
+  @Nullable
+  PsiElement findTearDownMethod(@NotNull PsiElement clazz);
+
+  @Nullable
+  PsiElement findOrCreateSetUpMethod(@NotNull PsiElement clazz) throws IncorrectOperationException;
 
   FileTemplateDescriptor getSetUpMethodFileTemplateDescriptor();
 
index 1290a2e21c1ca857275e11ea58555a6f95fd3b10..efe2b25fe5113b2e0534985318eee4834460ee88 100644 (file)
@@ -140,6 +140,8 @@ action.CollapseTreeNode.text=Collapse Tree Node
 action.FullyExpandTreeNode.text=Fully Expand Tree Node
 group.GenerateGroup.text=_Generate
 action.GenerateTestMethod.text=Test Method
+action.GenerateSetUpMethod.text=SetUp Method
+action.GenerateTearDownMethod.text=TearDown Method
 action.GenerateConstructor.text=Constructor
 action.GenerateGetter.text=Getter
 action.GenerateSetter.text=Setter
index 960db94f108e9d54ab1833dc66a23d0bf529d56a..23c63070a133225bd2eb873d925f873081aa4cbe 100644 (file)
@@ -27,9 +27,8 @@
     <configurationProducer implementation="com.intellij.execution.junit.TestMethodConfigurationProducer"/>
     <deadCode implementation="com.intellij.execution.junit2.inspection.JUnitUnusedCodeExtension"/>
     <cantBeStatic implementation="com.intellij.execution.junit2.inspection.JUnitCantBeStaticExtension" />
-    <testFramework implementation="com.intellij.execution.junit.JUnitTestFramework"/>
-    <testFrameworkDescriptor implementation="com.intellij.execution.junit.JUnit3FrameworkDescriptor"/>
-    <testFrameworkDescriptor implementation="com.intellij.execution.junit.JUnit4FrameworkDescriptor"/>
+    <testFramework implementation="com.intellij.execution.junit.JUnit3Framework"/>
+    <testFramework implementation="com.intellij.execution.junit.JUnit4Framework"/>
     <configurationType implementation="com.intellij.execution.junit.JUnitConfigurationType"/>
   </extensions>
 
diff --git a/plugins/junit/src/com/intellij/execution/junit/JUnit3Framework.java b/plugins/junit/src/com/intellij/execution/junit/JUnit3Framework.java
new file mode 100644 (file)
index 0000000..1ce38f3
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2000-2009 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.execution.junit;
+
+import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
+import com.intellij.openapi.projectRoots.ex.JavaSdkUtil;
+import com.intellij.psi.*;
+import com.intellij.psi.util.PsiUtil;
+import com.intellij.testIntegration.JavaTestFramework;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+
+public class JUnit3Framework extends JavaTestFramework {
+  @NotNull
+  public String getName() {
+    return "JUnit3";
+  }
+
+  @NotNull
+  @Override
+  public Icon getIcon() {
+    return JUnitConfigurationType.ICON;
+  }
+
+  protected String getMarkerClassFQName() {
+    return "junit.framework.TestCase";
+  }
+
+  @NotNull
+  public String getLibraryPath() {
+    return JavaSdkUtil.getJunit3JarPath();
+  }
+
+  @Nullable
+  public String getDefaultSuperClass() {
+    return "junit.framework.TestCase";
+  }
+
+  public boolean isTestClass(PsiClass clazz, boolean canBePotential) {
+    return JUnitUtil.isJUnit3TestClass(clazz);
+  }
+
+  @Override
+  @Nullable
+  protected PsiMethod findSetUpMethod(@NotNull PsiClass clazz) {
+    for (PsiMethod each : clazz.getMethods()) {
+      if (each.getName().equals("setUp")) return each;
+    }
+    return null;
+  }
+
+  @Override
+  @Nullable
+  protected PsiMethod findTearDownMethod(@NotNull PsiClass clazz) {
+    for (PsiMethod each : clazz.getMethods()) {
+      if (each.getName().equals("tearDown")) return each;
+    }
+    return null;
+  }
+
+  @Override
+  @Nullable
+  protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException {
+    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 PsiClass baseClass = clazz.getSuperClass();
+    if (baseClass != null) {
+      final PsiMethod baseMethod = baseClass.findMethodBySignature(patternMethod, false);
+      if (baseMethod != null && baseMethod.hasModifierProperty(PsiModifier.PUBLIC)) {
+        PsiUtil.setModifierProperty(patternMethod, PsiModifier.PROTECTED, false);
+        PsiUtil.setModifierProperty(patternMethod, PsiModifier.PUBLIC, true);
+      }
+    }
+
+    PsiMethod inClass = clazz.findMethodBySignature(patternMethod, false);
+    if (inClass == null) {
+      return (PsiMethod)clazz.add(patternMethod);
+    }
+    else if (inClass.getBody() == null) {
+      return (PsiMethod)inClass.replace(patternMethod);
+    }
+    return inClass;
+  }
+
+  public FileTemplateDescriptor getSetUpMethodFileTemplateDescriptor() {
+    return new FileTemplateDescriptor("JUnit3 SetUp Method.java");
+  }
+
+  public FileTemplateDescriptor getTearDownMethodFileTemplateDescriptor() {
+    return new FileTemplateDescriptor("JUnit3 TearDown Method.java");
+  }
+
+  public FileTemplateDescriptor getTestMethodFileTemplateDescriptor() {
+    return new FileTemplateDescriptor("JUnit3 Test Method.java");
+  }
+}
diff --git a/plugins/junit/src/com/intellij/execution/junit/JUnit3FrameworkDescriptor.java b/plugins/junit/src/com/intellij/execution/junit/JUnit3FrameworkDescriptor.java
deleted file mode 100644 (file)
index b50d501..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.execution.junit;
-
-import com.intellij.openapi.projectRoots.ex.JavaSdkUtil;
-import com.intellij.psi.PsiClass;
-import com.intellij.testIntegration.JavaTestFrameworkDescriptor;
-import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
-import org.jetbrains.annotations.Nullable;
-
-public class JUnit3FrameworkDescriptor extends JavaTestFrameworkDescriptor {
-  public String getName() {
-    return "JUnit3";
-  }
-
-  protected String getMarkerClassFQName() {
-    return "junit.framework.TestCase";
-  }
-
-  public String getLibraryPath() {
-    return JavaSdkUtil.getJunit3JarPath();
-  }
-
-  @Nullable
-  public String getDefaultSuperClass() {
-    return "junit.framework.TestCase";
-  }
-
-  public boolean isTestClass(PsiClass clazz) {
-    return JUnitUtil.isJUnit3TestClass(clazz);
-  }
-
-  public FileTemplateDescriptor getSetUpMethodFileTemplateDescriptor() {
-    return new FileTemplateDescriptor("JUnit3 SetUp Method.java");
-  }
-
-  public FileTemplateDescriptor getTearDownMethodFileTemplateDescriptor() {
-    return new FileTemplateDescriptor("JUnit3 TearDown Method.java");
-  }
-
-  public FileTemplateDescriptor getTestMethodFileTemplateDescriptor() {
-    return new FileTemplateDescriptor("JUnit3 Test Method.java");
-  }
-}
diff --git a/plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java b/plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java
new file mode 100644 (file)
index 0000000..27853db
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2000-2009 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.execution.junit;
+
+import com.intellij.codeInsight.AnnotationUtil;
+import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
+import com.intellij.openapi.projectRoots.ex.JavaSdkUtil;
+import com.intellij.psi.*;
+import com.intellij.psi.codeStyle.JavaCodeStyleManager;
+import com.intellij.testIntegration.JavaTestFramework;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+
+public class JUnit4Framework extends JavaTestFramework {
+  @NotNull
+  public String getName() {
+    return "JUnit4";
+  }
+
+  @NotNull
+  @Override
+  public Icon getIcon() {
+    return JUnitConfigurationType.ICON;
+  }
+
+  protected String getMarkerClassFQName() {
+    return "org.junit.Test";
+  }
+
+  @NotNull
+  public String getLibraryPath() {
+    return JavaSdkUtil.getJunit4JarPath();
+  }
+
+  @Nullable
+  public String getDefaultSuperClass() {
+    return null;
+  }
+
+  public boolean isTestClass(PsiClass clazz, boolean canBePotential) {
+    if (canBePotential) return isUnderTestSources(clazz);
+    return JUnitUtil.isJUnit4TestClass(clazz);
+  }
+
+  @Nullable
+  @Override
+  protected PsiMethod findSetUpMethod(@NotNull PsiClass clazz) {
+    for (PsiMethod each : clazz.getMethods()) {
+      if (AnnotationUtil.isAnnotated(each, "org.junit.Before", false)) return each;
+    }
+    return null;
+  }
+
+  @Nullable
+  @Override
+  protected PsiMethod findTearDownMethod(@NotNull PsiClass clazz) {
+    for (PsiMethod each : clazz.getMethods()) {
+      if (AnnotationUtil.isAnnotated(each, "org.junit.After", false)) return each;
+    }
+    return null;
+  }
+
+  @Override
+  @Nullable
+  protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException {
+    PsiManager manager = clazz.getManager();
+    PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
+
+    PsiMethod method = factory.createMethodFromText("@org.junit.Before public void setUp() throws Exception {\n}", null);
+    method = (PsiMethod)clazz.add(method);
+    JavaCodeStyleManager.getInstance(manager.getProject()).shortenClassReferences(method);
+
+    return method;
+  }
+
+  public FileTemplateDescriptor getSetUpMethodFileTemplateDescriptor() {
+    return new FileTemplateDescriptor("JUnit4 SetUp Method.java");
+  }
+
+  public FileTemplateDescriptor getTearDownMethodFileTemplateDescriptor() {
+    return new FileTemplateDescriptor("JUnit4 TearDown Method.java");
+  }
+
+  public FileTemplateDescriptor getTestMethodFileTemplateDescriptor() {
+    return new FileTemplateDescriptor("JUnit4 Test Method.java");
+  }
+}
\ No newline at end of file
diff --git a/plugins/junit/src/com/intellij/execution/junit/JUnit4FrameworkDescriptor.java b/plugins/junit/src/com/intellij/execution/junit/JUnit4FrameworkDescriptor.java
deleted file mode 100644 (file)
index e6cea9a..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.execution.junit;
-
-import com.intellij.openapi.projectRoots.ex.JavaSdkUtil;
-import com.intellij.psi.PsiClass;
-import com.intellij.testIntegration.JavaTestFrameworkDescriptor;
-import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
-import org.jetbrains.annotations.Nullable;
-
-public class JUnit4FrameworkDescriptor extends JavaTestFrameworkDescriptor {
-  public String getName() {
-    return "JUnit4";
-  }
-
-  protected String getMarkerClassFQName() {
-    return "org.junit.Test";
-  }
-
-  public String getLibraryPath() {
-    return JavaSdkUtil.getJunit4JarPath();
-  }
-
-  @Nullable
-  public String getDefaultSuperClass() {
-    return null;
-  }
-
-  public boolean isTestClass(PsiClass clazz) {
-    return JUnitUtil.isJUnit4TestClass(clazz);
-  }
-
-  public FileTemplateDescriptor getSetUpMethodFileTemplateDescriptor() {
-    return new FileTemplateDescriptor("JUnit4 SetUp Method.java");
-  }
-
-  public FileTemplateDescriptor getTearDownMethodFileTemplateDescriptor() {
-    return new FileTemplateDescriptor("JUnit4 TearDown Method.java");
-  }
-
-  public FileTemplateDescriptor getTestMethodFileTemplateDescriptor() {
-    return new FileTemplateDescriptor("JUnit4 Test Method.java");
-  }
-}
\ No newline at end of file
index 00eedbb85d077b0b3f5a503cb54c85c9e546dcd2..f41597de897e4b5ecfbfcfe100d067046ad0740c 100644 (file)
@@ -31,7 +31,7 @@ import org.jetbrains.annotations.Nullable;
 import javax.swing.*;
 
 public class JUnitConfigurationType implements ConfigurationType {
-  private static final Icon ICON = IconLoader.getIcon("/runConfigurations/junit.png");
+  public static final Icon ICON = IconLoader.getIcon("/runConfigurations/junit.png");
   private final ConfigurationFactory myFactory;
 
   /**reflection*/
diff --git a/plugins/junit/src/com/intellij/execution/junit/JUnitTestFramework.java b/plugins/junit/src/com/intellij/execution/junit/JUnitTestFramework.java
deleted file mode 100644 (file)
index 5abcc25..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * User: anna
- * Date: 15-Aug-2007
- */
-package com.intellij.execution.junit;
-
-import com.intellij.codeInsight.AnnotationUtil;
-import com.intellij.codeInsight.TestFramework;
-import com.intellij.psi.*;
-import com.intellij.psi.util.PsiUtil;
-import com.intellij.psi.codeStyle.JavaCodeStyleManager;
-import com.intellij.util.IncorrectOperationException;
-
-public class JUnitTestFramework implements TestFramework {
-   public boolean isTestKlass(final PsiClass psiClass) {
-    return JUnitUtil.isTestClass(psiClass);
-  }
-
-  public PsiMethod findSetUpMethod(final PsiClass psiClass) throws IncorrectOperationException {
-    final PsiManager manager = psiClass.getManager();
-    final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
-    if (JUnitUtil.isJUnit4TestClass(psiClass)) {
-      final PsiMethod[] methods = psiClass.getMethods();
-      for (PsiMethod method : methods) {
-        if (AnnotationUtil.isAnnotated(method, "org.junit.Before", false)) return method;
-      }
-      final PsiMethod method =
-        (PsiMethod)psiClass.add(factory.createMethodFromText("@org.junit.Before public void setUp() throws Exception {\n}", null));
-      JavaCodeStyleManager.getInstance(manager.getProject()).shortenClassReferences(method);
-      return method;
-    }
-
-    final PsiMethod patternMethod = factory.createMethodFromText("protected void setUp() throws Exception {\nsuper.setUp();\n}", null);
-
-    final PsiClass baseClass = psiClass.getSuperClass();
-    if (baseClass != null) {
-      final PsiMethod baseMethod = baseClass.findMethodBySignature(patternMethod, false);
-      if (baseMethod != null && baseMethod.hasModifierProperty(PsiModifier.PUBLIC)) {
-        PsiUtil.setModifierProperty(patternMethod, PsiModifier.PROTECTED, false);
-        PsiUtil.setModifierProperty(patternMethod, PsiModifier.PUBLIC, true);
-      }
-    }
-
-    PsiMethod inClass = psiClass.findMethodBySignature(patternMethod, false);
-    if (inClass == null) {
-      return (PsiMethod)psiClass.add(patternMethod);
-    }
-    else if (inClass.getBody() == null) {
-      return (PsiMethod)inClass.replace(patternMethod);
-    }
-    return inClass;
-  }
-
-  public boolean isTestMethodOrConfig(PsiMethod psiMethod) {
-    return JUnitUtil.isTestMethodOrConfig(psiMethod);
-  }
-}
\ No newline at end of file
index 5c4f366b33e80c43cdb53a6a2283638f31b97ef2..41c42cd7b13c2bab1d6feb4d0494c107b965939d 100644 (file)
         <configurationProducer implementation="com.theoryinpractice.testng.configuration.TestNGInClassConfigurationProducer"/>
         <configurationProducer implementation="com.theoryinpractice.testng.configuration.TestNGPackageConfigurationProducer"/>
         <configurationProducer implementation="com.theoryinpractice.testng.configuration.TestNGSuiteConfigurationProducer"/>
-        <testFramework implementation="com.theoryinpractice.testng.util.TestNGUtil"/>
         <inspectionToolProvider implementation="com.theoryinpractice.testng.inspection.TestNGInspectionsToolProvider"/>
         <configurationType implementation="com.theoryinpractice.testng.configuration.TestNGConfigurationType"/>
        <psi.referenceContributor implementation="com.theoryinpractice.testng.TestNGReferenceContributor"/>
         <intentionAction>
           <className>com.theoryinpractice.testng.intention.TestNGOrderEntryFix</className>
         </intentionAction>
-        <testFrameworkDescriptor implementation="com.theoryinpractice.testng.TestNGFrameworkDescriptor"/>
+        <testFramework implementation="com.theoryinpractice.testng.TestNGFramework"/>
       <standardResourceProvider implementation="com.theoryinpractice.testng.TestNGPlugin"/>
       <overrideImplementsAnnotationsHandler implementation="com.theoryinpractice.testng.intention.OverrideImplementsTestNGAnnotationsHandler"/>
     </extensions>
diff --git a/plugins/testng/src/com/theoryinpractice/testng/TestNGFramework.java b/plugins/testng/src/com/theoryinpractice/testng/TestNGFramework.java
new file mode 100644 (file)
index 0000000..a9edb4a
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2000-2009 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.theoryinpractice.testng;
+
+import com.intellij.codeInsight.AnnotationUtil;
+import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
+import com.intellij.psi.*;
+import com.intellij.psi.codeStyle.JavaCodeStyleManager;
+import com.intellij.testIntegration.JavaTestFramework;
+import com.intellij.util.IncorrectOperationException;
+import com.intellij.util.PathUtil;
+import com.theoryinpractice.testng.configuration.TestNGConfigurationType;
+import com.theoryinpractice.testng.util.TestNGUtil;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.testng.annotations.BeforeMethod;
+
+import javax.swing.*;
+
+public class TestNGFramework extends JavaTestFramework {
+  @NotNull
+  public String getName() {
+    return "TestNG";
+  }
+
+  @NotNull
+  @Override
+  public Icon getIcon() {
+    return TestNGConfigurationType.ICON;
+  }
+
+  protected String getMarkerClassFQName() {
+    return "org.testng.annotations.Test";
+  }
+
+  @NotNull
+  public String getLibraryPath() {
+    try {
+      return PathUtil.getJarPathForClass(Class.forName("org.testng.annotations.Test"));
+    }
+    catch (ClassNotFoundException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  @Nullable
+  public String getDefaultSuperClass() {
+    return null;
+  }
+
+  public boolean isTestClass(PsiClass clazz, boolean canBePotential) {
+    if (canBePotential) return isUnderTestSources(clazz);
+    return TestNGUtil.isTestNGClass(clazz);
+  }
+
+  @Nullable
+  @Override
+  protected PsiMethod findSetUpMethod(@NotNull PsiClass clazz) {
+    for (PsiMethod each : clazz.getMethods()) {
+      if (AnnotationUtil.isAnnotated(each, "org.testng.annotations.BeforeMethod", false)) return each;
+    }
+    return null;
+  }
+
+  @Nullable
+  @Override
+  protected PsiMethod findTearDownMethod(@NotNull PsiClass clazz) {
+    for (PsiMethod each : clazz.getMethods()) {
+      if (AnnotationUtil.isAnnotated(each, "org.testng.annotations.AfterMethod", false)) return each;
+    }
+    return null;
+  }
+
+  @Override
+  protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException {
+    final PsiManager manager = clazz.getManager();
+    final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
+    PsiMethod patternMethod =
+      factory.createMethodFromText("@org.testng.annotations.BeforeMethod\n protected void setUp() throws Exception {}", null);
+
+    final PsiClass superClass = clazz.getSuperClass();
+    if (superClass != null) {
+      final PsiMethod[] methods = superClass.findMethodsBySignature(patternMethod, false);
+      if (methods.length > 0) {
+        final PsiModifierList modifierList = methods[0].getModifierList();
+        if (!modifierList.hasModifierProperty(PsiModifier.PRIVATE)) { //do not override private method
+          @NonNls String pattern = "@org.testng.annotations.BeforeMethod\n";
+          if (modifierList.hasModifierProperty(PsiModifier.PROTECTED)) {
+            pattern += "protected ";
+          }
+          else if (modifierList.hasModifierProperty(PsiModifier.PUBLIC)) {
+            pattern += "public ";
+          }
+          patternMethod = factory.createMethodFromText(pattern + "void setUp() throws Exception {\nsuper.setUp();\n}", null);
+        }
+      }
+    }
+
+    final PsiMethod[] psiMethods = clazz.getMethods();
+    PsiMethod inClass = null;
+    for (PsiMethod psiMethod : psiMethods) {
+      if (AnnotationUtil.isAnnotated(psiMethod, BeforeMethod.class.getName(), false)) {
+        inClass = psiMethod;
+        break;
+      }
+    }
+    if (inClass == null) {
+      final PsiMethod psiMethod = (PsiMethod)clazz.add(patternMethod);
+      JavaCodeStyleManager.getInstance(clazz.getProject()).shortenClassReferences(clazz);
+      return psiMethod;
+    }
+    else if (inClass.getBody() == null) {
+      return (PsiMethod)inClass.replace(patternMethod);
+    }
+    return inClass;
+  }
+
+  public FileTemplateDescriptor getSetUpMethodFileTemplateDescriptor() {
+    return new FileTemplateDescriptor("TestNG SetUp Method.java");
+  }
+
+  public FileTemplateDescriptor getTearDownMethodFileTemplateDescriptor() {
+    return new FileTemplateDescriptor("TestNG TearDown Method.java");
+  }
+
+  public FileTemplateDescriptor getTestMethodFileTemplateDescriptor() {
+    return new FileTemplateDescriptor("TestNG Test Method.java");
+  }
+}
diff --git a/plugins/testng/src/com/theoryinpractice/testng/TestNGFrameworkDescriptor.java b/plugins/testng/src/com/theoryinpractice/testng/TestNGFrameworkDescriptor.java
deleted file mode 100644 (file)
index 16653fd..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.theoryinpractice.testng;
-
-import com.intellij.testIntegration.JavaTestFrameworkDescriptor;
-import com.intellij.util.PathUtil;
-import com.intellij.psi.PsiClass;
-import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
-import com.theoryinpractice.testng.util.TestNGUtil;
-import org.jetbrains.annotations.Nullable;
-
-public class TestNGFrameworkDescriptor extends JavaTestFrameworkDescriptor {
-  public String getName() {
-    return "TestNG";
-  }
-
-  protected String getMarkerClassFQName() {
-    return "org.testng.annotations.Test";
-  }
-
-  public String getLibraryPath() {
-    try {
-      return PathUtil.getJarPathForClass(Class.forName("org.testng.annotations.Test"));
-    }
-    catch (ClassNotFoundException e) {
-      throw new RuntimeException(e);
-    }
-  }
-
-  @Nullable
-  public String getDefaultSuperClass() {
-    return null;
-  }
-
-  public boolean isTestClass(PsiClass clazz) {
-    return TestNGUtil.isTestNGClass(clazz);
-  }
-
-  public FileTemplateDescriptor getSetUpMethodFileTemplateDescriptor() {
-    return new FileTemplateDescriptor("TestNG SetUp Method.java");
-  }
-
-  public FileTemplateDescriptor getTearDownMethodFileTemplateDescriptor() {
-    return new FileTemplateDescriptor("TestNG TearDown Method.java");
-  }
-
-  public FileTemplateDescriptor getTestMethodFileTemplateDescriptor() {
-    return new FileTemplateDescriptor("TestNG Test Method.java");
-  }
-}
index d3a70ee22127f47a00b43f2996836779aa154bad..7cc32bf57c6858f28b74657b437b8dc7617a500d 100644 (file)
@@ -44,8 +44,8 @@ import javax.swing.*;
 
 public class TestNGConfigurationType implements ConfigurationType
 {
-    private static final Logger LOGGER = Logger.getInstance("TestNG Runner");
-    private static final Icon ICON = IconLoader.getIcon("/resources/testNG.png");
+  public static final Icon ICON = IconLoader.getIcon("/resources/testNG.png");
+  private static final Logger LOGGER = Logger.getInstance("TestNG Runner");
 
     private final ConfigurationFactory myFactory;
 
index ec396fd77e7c9a8a9c37a7b48b5b8beb517d9387..25bf6337aeb27d13730b28d31a1a8e861c0ca778 100644 (file)
@@ -16,7 +16,6 @@
 package com.theoryinpractice.testng.util;
 
 import com.intellij.codeInsight.AnnotationUtil;
-import com.intellij.codeInsight.TestFramework;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.module.Module;
@@ -35,7 +34,6 @@ import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.psi.*;
-import com.intellij.psi.codeStyle.JavaCodeStyleManager;
 import com.intellij.psi.impl.source.jsp.jspJava.JspClass;
 import com.intellij.psi.javadoc.PsiDocComment;
 import com.intellij.psi.javadoc.PsiDocTag;
@@ -44,7 +42,6 @@ import com.intellij.psi.search.searches.AllClassesSearch;
 import com.intellij.psi.util.InheritanceUtil;
 import com.intellij.psi.util.PsiElementFilter;
 import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.PathUtil;
 import com.intellij.util.Processor;
 import com.intellij.util.xml.NanoXmlUtil;
@@ -63,7 +60,7 @@ import java.util.regex.Pattern;
 /**
  * @author Hani Suleiman Date: Jul 20, 2005 Time: 1:37:36 PM
  */
-public class TestNGUtil implements TestFramework
+public class TestNGUtil
 {
   private static final Logger LOGGER = Logger.getInstance("TestNG Runner");
   public static final String TESTNG_GROUP_NAME = "TestNG";
@@ -429,59 +426,10 @@ public class TestNGUtil implements TestFramework
     return array;
   }
 
-  public boolean isTestKlass(PsiClass psiClass) {
-    return isTestNGClass(psiClass);
-  }
-
   public static boolean isTestNGClass(PsiClass psiClass) {
     return hasTest(psiClass, true, false);
   }
 
-  public PsiMethod findSetUpMethod(final PsiClass psiClass) throws IncorrectOperationException {
-    final PsiManager manager = psiClass.getManager();
-    final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
-    PsiMethod patternMethod = factory.createMethodFromText("@org.testng.annotations.BeforeMethod\n protected void setUp() throws Exception {}", null);
-
-    final PsiClass superClass = psiClass.getSuperClass();
-    if (superClass != null) {
-      final PsiMethod[] methods = superClass.findMethodsBySignature(patternMethod, false);
-      if (methods.length > 0) {
-        final PsiModifierList modifierList = methods[0].getModifierList();
-        if (!modifierList.hasModifierProperty(PsiModifier.PRIVATE)) { //do not override private method
-          @NonNls String pattern = "@org.testng.annotations.BeforeMethod\n";
-          if (modifierList.hasModifierProperty(PsiModifier.PROTECTED)) {
-            pattern += "protected ";
-          } else if (modifierList.hasModifierProperty(PsiModifier.PUBLIC)) {
-            pattern +="public ";
-          }
-          patternMethod = factory.createMethodFromText(pattern + "void setUp() throws Exception {\nsuper.setUp();\n}", null);
-        }
-      }
-    }
-
-    final PsiMethod[] psiMethods = psiClass.getMethods();
-    PsiMethod inClass = null;
-    for (PsiMethod psiMethod : psiMethods) {
-      if (AnnotationUtil.isAnnotated(psiMethod, BeforeMethod.class.getName(), false)) {
-        inClass = psiMethod;
-        break;
-      }
-    }
-    if (inClass == null) {
-      final PsiMethod psiMethod = (PsiMethod)psiClass.add(patternMethod);
-      JavaCodeStyleManager.getInstance(psiClass.getProject()).shortenClassReferences(psiClass);
-      return psiMethod;
-    }
-    else if (inClass.getBody() == null) {
-      return (PsiMethod)inClass.replace(patternMethod);
-    }
-    return inClass;
-  }
-
-  public boolean isTestMethodOrConfig(PsiMethod psiMethod) {
-    return hasTest(psiMethod) || hasConfig(psiMethod);
-  }
-
   public static boolean checkTestNGInClasspath(PsiElement psiElement) {
     final Project project = psiElement.getProject();
     final PsiManager manager = PsiManager.getInstance(project);
index 935695467d6712e03753f94c7cc822e8763ae577..6362911c47c9588828c845bd9bb978e0da12c116 100644 (file)
@@ -1,3 +1,3 @@
-@org.testng.annotations.BeforeTest
+@org.testng.annotations.BeforeMethod
 public void setUp() {
 }
\ No newline at end of file
index 735d98064b53302a8412a65e712366c7fbeb79ce..b25acdba52b02dd6a10fcfa576f74bcf6c0016b3 100644 (file)
@@ -1,3 +1,3 @@
-@org.testng.annotations.AfterTest
+@org.testng.annotations.AfterMethod
 public void tearDown() {
 }
\ No newline at end of file
index 499d518d6bf3a832747ed9771aac8cc94b35f848..2187842a62529eb783ef3289905615b1952dc96e 100644 (file)
     <extensionPoint name="javaExpressionSurrounder"
                     interface="com.intellij.codeInsight.generation.surroundWith.JavaExpressionSurrounder"/>
 
-    <extensionPoint name="testFramework"
-                    interface="com.intellij.codeInsight.TestFramework"/>
-
     <extensionPoint name="frameworkSupport" interface="com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider"/>
 
     <!--new project wizard-->
 
     <extensionPoint name="customPropertyScopeProvider" interface="com.intellij.psi.impl.search.CustomPropertyScopeProvider"/>
 
-    <extensionPoint name="testFrameworkDescriptor" interface="com.intellij.testIntegration.TestFrameworkDescriptor"/>
+    <extensionPoint name="testFramework" interface="com.intellij.testIntegration.TestFramework"/>
 
     <extensionPoint name="unscrambleSupport" interface="com.intellij.unscramble.UnscrambleSupport"/>
 
index 43b88ef0481c5ae9668cf7553a952b676a30697b..67df97c823787c062681b6468bde599d16632fa2 100644 (file)
@@ -28,6 +28,9 @@
 
     <group id="JavaGenerateGroup1">
       <action id="GenerateTestMethod" class="com.intellij.testIntegration.GenerateTestMethodAction"/>
+      <action id="GenerateSetUpMethod" class="com.intellij.testIntegration.GenerateSetUpMethodAction"/>
+      <action id="GenerateTearDownMethod" class="com.intellij.testIntegration.GenerateTearDownMethodAction"/>
+      <separator/>
       <action id="GenerateConstructor" class="com.intellij.codeInsight.generation.actions.GenerateConstructorAction"/>
       <action id="GenerateGetter" class="com.intellij.codeInsight.generation.actions.GenerateGetterAction"/>
       <action id="GenerateSetter" class="com.intellij.codeInsight.generation.actions.GenerateSetterAction"/>