listen for rename of test category (IDEA-144086)
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Fri, 4 Sep 2015 14:39:00 +0000 (17:39 +0300)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Fri, 4 Sep 2015 14:46:17 +0000 (17:46 +0300)
plugins/junit/src/com/intellij/execution/junit/JUnitConfiguration.java
plugins/junit/src/com/intellij/execution/junit/TestCategory.java

index 64b8ddb7a04ac900be8f540f330d1e78a2250e96..bcf5ce81514614aadcc46a2bb65643aa36eced1e 100644 (file)
@@ -28,7 +28,6 @@ import com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties;
 import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
 import com.intellij.execution.testframework.TestSearchScope;
-import com.intellij.execution.testframework.sm.runner.SMRunnerConsolePropertiesProvider;
 import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties;
 import com.intellij.openapi.components.PathMacroManager;
 import com.intellij.openapi.module.Module;
@@ -111,6 +110,23 @@ public class JUnitConfiguration extends JavaTestConfigurationBase {
       restoreOriginalModule(originalModule);
     }
   };
+  
+  final RefactoringListeners.Accessor<PsiClass> myCategory = new RefactoringListeners.Accessor<PsiClass>() {
+    @Override
+    public void setName(@NotNull final String qualifiedName) {
+      setCategory(qualifiedName);
+    }
+
+    @Override
+    public PsiClass getPsiElement() {
+      return getConfigurationModule().findClass(myData.getCategory());
+    }
+
+    @Override
+    public void setPsiElement(final PsiClass psiClass) {
+      setCategory(JavaExecutionUtil.getRuntimeQualifiedName(psiClass));
+    }
+  };
   public boolean ALTERNATIVE_JRE_PATH_ENABLED;
   public String ALTERNATIVE_JRE_PATH;
 
@@ -282,6 +298,12 @@ public class JUnitConfiguration extends JavaTestConfigurationBase {
     if (shouldUpdateName) setGeneratedName();
   }
 
+  public void setCategory(String categoryName) {
+    final boolean shouldUpdateName = isGeneratedName();
+    myData.setCategoryName(categoryName);
+    if (shouldUpdateName) setGeneratedName();
+  }
+
   public void beMethodConfiguration(final Location<PsiMethod> methodLocation) {
     setModule(myData.setTestMethod(methodLocation));
     setGeneratedName();
index b630eef2ac8f75b8e9ed5ddbc40e48202db7fed6..6df1e677e0588c7f37765b8d9dde5f689da60979 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.execution.util.JavaParametersUtil;
 import com.intellij.execution.util.ProgramParametersUtil;
 import com.intellij.psi.*;
+import com.intellij.refactoring.listeners.RefactoringElementListener;
 
 /**
 * User: anna
@@ -67,4 +68,9 @@ class TestCategory extends TestPackage {
                                        PsiDirectory testDir) {
     return false;
   }
+
+  @Override
+  public RefactoringElementListener getListener(final PsiElement element, final JUnitConfiguration configuration) {
+    return RefactoringListeners.getClassOrPackageListener(element, configuration.myCategory);
+  }
 }