testng/junit: extract common part about pattern configuration
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Tue, 11 Nov 2014 11:00:23 +0000 (12:00 +0100)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Tue, 11 Nov 2014 11:03:07 +0000 (12:03 +0100)
java/execution/impl/src/com/intellij/execution/PatternConfigurationDelegate.java [new file with mode: 0644]
plugins/junit/src/com/intellij/execution/junit/AddToTestsPatternAction.java
plugins/junit/src/com/intellij/execution/junit/PatternConfigurationProducer.java
plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGPatternConfigurationProducer.java

diff --git a/java/execution/impl/src/com/intellij/execution/PatternConfigurationDelegate.java b/java/execution/impl/src/com/intellij/execution/PatternConfigurationDelegate.java
new file mode 100644 (file)
index 0000000..93fa047
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2000-2014 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;
+
+import com.intellij.execution.JavaExecutionUtil;
+import com.intellij.execution.Location;
+import com.intellij.execution.actions.ConfigurationContext;
+import com.intellij.execution.configurations.ModuleBasedConfiguration;
+import com.intellij.execution.junit2.info.MethodLocation;
+import com.intellij.execution.testframework.TestsUIUtil;
+import com.intellij.openapi.actionSystem.CommonDataKeys;
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.LangDataKeys;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.util.Comparing;
+import com.intellij.openapi.util.Condition;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.*;
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+public abstract class PatternConfigurationDelegate {
+  protected abstract boolean isTestClass(PsiClass psiClass);
+  protected abstract boolean isTestMethod(boolean checkAbstract, PsiElement psiElement);
+
+  public Module findModule(ModuleBasedConfiguration configuration, Module contextModule, Set<String> patterns) {
+    return JavaExecutionUtil.findModule(contextModule, patterns, configuration.getProject(), new Condition<PsiClass>() {
+      @Override
+      public boolean value(PsiClass psiClass) {
+        return isTestClass(psiClass);
+      }
+    });
+  }
+
+  public boolean isMultipleElementsSelected(ConfigurationContext context) {
+    if (TestsUIUtil.isMultipleSelectionImpossible(context.getDataContext())) return false;
+    final LinkedHashSet<String> classes = new LinkedHashSet<String>();
+    final PsiElement[] elements = collectPatternElements(context, classes);
+    if (elements != null && collectTestMembers(elements, false).size() > 1) {
+      return true;
+    }
+    return false;
+  }
+
+  public boolean isConfiguredFromContext(ConfigurationContext context, Set<String> patterns) {
+    final LinkedHashSet<String> classes = new LinkedHashSet<String>();
+    collectPatternElements(context, classes);
+    if (Comparing.equal(classes, patterns)) {
+      return true;
+    }
+    return false;
+  }
+
+  public PsiElement checkPatterns(ConfigurationContext context, LinkedHashSet<String> classes) {
+    PsiElement[] elements = collectPatternElements(context, classes);
+    if (elements == null || collectTestMembers(elements, false).size() <= 1) {
+      return null;
+    }
+    return elements[0];
+  }
+
+  public Set<PsiElement> collectTestMembers(PsiElement[] psiElements, boolean checkAbstract) {
+    final Set<PsiElement> foundMembers = new LinkedHashSet<PsiElement>();
+    for (PsiElement psiElement : psiElements) {
+      if (psiElement instanceof PsiClassOwner) {
+        final PsiClass[] classes = ((PsiClassOwner)psiElement).getClasses();
+        for (PsiClass aClass : classes) {
+          if (isTestClass(aClass)) {
+            foundMembers.add(aClass);
+          }
+        }
+      } else if (psiElement instanceof PsiClass) {
+        if (isTestClass((PsiClass)psiElement)) {
+          foundMembers.add(psiElement);
+        }
+      } else if (psiElement instanceof PsiMethod) {
+        if (isTestMethod(checkAbstract, psiElement)) {
+          foundMembers.add(psiElement);
+        }
+      } else if (psiElement instanceof PsiDirectory) {
+        final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)psiElement);
+        if (aPackage != null) {
+          foundMembers.add(aPackage);
+        }
+      }
+    }
+    return foundMembers;
+  }
+  
+  private PsiElement[] collectPatternElements(ConfigurationContext context, LinkedHashSet<String> classes) {
+    final DataContext dataContext = context.getDataContext();
+    final Location<?>[] locations = Location.DATA_KEYS.getData(dataContext);
+    if (locations != null) {
+      List<PsiElement> elements = new ArrayList<PsiElement>();
+      for (Location<?> location : locations) {
+        final PsiElement psiElement = location.getPsiElement();
+        classes.add(getQName(psiElement, location));
+        elements.add(psiElement);
+      }
+      return elements.toArray(new PsiElement[elements.size()]);
+    }
+    PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
+    if (elements != null) {
+      for (PsiElement psiClass : collectTestMembers(elements, true)) {
+        classes.add(getQName(psiClass));
+      }
+      return elements;
+    } else {
+      final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
+      if (files != null) {
+        final List<PsiFile> psiFiles = new ArrayList<PsiFile>();
+        final PsiManager psiManager = PsiManager.getInstance(context.getProject());
+        for (VirtualFile file : files) {
+          final PsiFile psiFile = psiManager.findFile(file);
+          if (psiFile instanceof PsiClassOwner) {
+            for (PsiElement psiMember : collectTestMembers(((PsiClassOwner)psiFile).getClasses(), true)) {
+              classes.add(((PsiClass)psiMember).getQualifiedName());
+            }
+            psiFiles.add(psiFile);
+          }
+        }
+        return psiFiles.toArray(new PsiElement[psiFiles.size()]);
+      }
+    }
+    return null;
+  }
+
+  public static String getQName(PsiElement psiMember) {
+    return getQName(psiMember, null);
+  }
+
+  public static String getQName(PsiElement psiMember, Location location) {
+    if (psiMember instanceof PsiClass) {
+      return ((PsiClass)psiMember).getQualifiedName();
+    }
+    else if (psiMember instanceof PsiMember) {
+      final PsiClass containingClass = location instanceof MethodLocation
+                                       ? ((MethodLocation)location).getContainingClass(): ((PsiMember)psiMember).getContainingClass();
+      assert containingClass != null;
+      return containingClass.getQualifiedName() + "," + ((PsiMember)psiMember).getName();
+    } else if (psiMember instanceof PsiPackage) {
+      return ((PsiPackage)psiMember).getQualifiedName();
+    }
+    assert false;
+    return null;
+  }
+}
index df492ca1584a210a7c10fead5417a38c7488f570..a49c027ed63a6987014e17ff675adee8ee08632f 100644 (file)
@@ -20,6 +20,7 @@
  */
 package com.intellij.execution.junit;
 
+import com.intellij.execution.PatternConfigurationDelegate;
 import com.intellij.execution.RunManager;
 import com.intellij.execution.configurations.RunConfiguration;
 import com.intellij.openapi.actionSystem.*;
@@ -47,14 +48,14 @@ public class AddToTestsPatternAction extends AnAction {
     if (patternConfigurations.size() == 1) {
       final JUnitConfiguration configuration = patternConfigurations.get(0);
       for (PsiElement aClass : classes) {
-        configuration.getPersistentData().getPatterns().add(PatternConfigurationProducer.getQName(aClass));
+        configuration.getPersistentData().getPatterns().add(PatternConfigurationDelegate.getQName(aClass));
       }
     } else {
       JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<JUnitConfiguration>("Choose suite to add", patternConfigurations) {
         @Override
         public PopupStep onChosen(JUnitConfiguration configuration, boolean finalChoice) {
           for (PsiElement aClass : classes) {
-            configuration.getPersistentData().getPatterns().add(PatternConfigurationProducer.getQName(aClass));
+            configuration.getPersistentData().getPatterns().add(PatternConfigurationDelegate.getQName(aClass));
           }
           return FINAL_CHOICE;
         }
@@ -102,7 +103,7 @@ public class AddToTestsPatternAction extends AnAction {
     for (RunConfiguration configuration : configurations) {
       final JUnitConfiguration.Data data = ((JUnitConfiguration)configuration).getPersistentData();
       if (data.TEST_OBJECT == JUnitConfiguration.TEST_PATTERN) {
-        if (foundClasses.size() > 1 || !data.getPatterns().contains(PatternConfigurationProducer.getQName(foundClasses.iterator().next())) ) {
+        if (foundClasses.size() > 1 || !data.getPatterns().contains(PatternConfigurationDelegate.getQName(foundClasses.iterator().next())) ) {
           foundConfigurations.add((JUnitConfiguration)configuration);
         }
       }
index e570f10177da2b6e1ef8c5510402db59c86a8d8e..eec90d11e7c8772ab11d95677f805de1b02d76db 100644 (file)
 
 package com.intellij.execution.junit;
 
-import com.intellij.execution.JavaExecutionUtil;
-import com.intellij.execution.Location;
+import com.intellij.execution.PatternConfigurationDelegate;
 import com.intellij.execution.actions.ConfigurationContext;
 import com.intellij.execution.configurations.ModuleBasedConfiguration;
-import com.intellij.execution.junit2.info.MethodLocation;
-import com.intellij.execution.testframework.AbstractTestProxy;
-import com.intellij.execution.testframework.TestTreeView;
-import com.intellij.execution.testframework.TestsUIUtil;
-import com.intellij.openapi.actionSystem.CommonDataKeys;
-import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.actionSystem.LangDataKeys;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
 import com.intellij.openapi.module.Module;
-import com.intellij.openapi.util.Comparing;
-import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.Ref;
-import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.*;
-import com.intellij.util.ui.Tree;
 
-import javax.swing.*;
-import javax.swing.tree.TreePath;
-import java.awt.*;
-import java.util.ArrayList;
 import java.util.LinkedHashSet;
-import java.util.List;
 import java.util.Set;
 
 public class PatternConfigurationProducer extends JUnitConfigurationProducer {
+  private static PatternConfigurationDelegate ourDelegate = new PatternConfigurationDelegate() {
+    @Override
+    protected boolean isTestClass(PsiClass psiClass) {
+      return JUnitUtil.isTestClass(psiClass);
+    }
+
+    @Override
+    protected boolean isTestMethod(boolean checkAbstract, PsiElement psiElement) {
+      return JUnitUtil.getTestMethod(psiElement, checkAbstract) != null;
+    }
+  }; 
+
   @Override
   protected boolean setupConfigurationFromContext(JUnitConfiguration configuration,
                                                   ConfigurationContext context,
                                                   Ref<PsiElement> sourceElement) {
     final LinkedHashSet<String> classes = new LinkedHashSet<String>();
-    PsiElement[] elements = collectPatternElements(context, classes);
-    if (elements == null || collectTestMembers(elements, false).size() <= 1) {
+    final PsiElement element = ourDelegate.checkPatterns(context, classes);
+    if (element == null) {
       return false;
     }
-    sourceElement.set(elements[0]);
+    sourceElement.set(element);
     final JUnitConfiguration.Data data = configuration.getPersistentData();
     data.setPatterns(classes);
     data.TEST_OBJECT = JUnitConfiguration.TEST_PATTERN;
@@ -69,120 +63,25 @@ public class PatternConfigurationProducer extends JUnitConfigurationProducer {
     return findModule(configuration, contextModule, patterns);
   }
 
-  public static Module findModule(ModuleBasedConfiguration configuration, Module contextModule, Set<String> patterns) {
-    return JavaExecutionUtil.findModule(contextModule, patterns, configuration.getProject(), new Condition<PsiClass>() {
-      @Override
-      public boolean value(PsiClass psiClass) {
-        return JUnitUtil.isTestClass(psiClass);
-      }
-    });
-  }
-
-  static Set<PsiElement> collectTestMembers(PsiElement[] psiElements, boolean checkAbstract) {
-    final Set<PsiElement> foundMembers = new LinkedHashSet<PsiElement>();
-    for (PsiElement psiElement : psiElements) {
-      if (psiElement instanceof PsiClassOwner) {
-        final PsiClass[] classes = ((PsiClassOwner)psiElement).getClasses();
-        for (PsiClass aClass : classes) {
-          if (JUnitUtil.isTestClass(aClass)) {
-            foundMembers.add(aClass);
-          }
-        }
-      } else if (psiElement instanceof PsiClass) {
-        if (JUnitUtil.isTestClass((PsiClass)psiElement)) {
-          foundMembers.add(psiElement);
-        }
-      } else if (psiElement instanceof PsiMethod) {
-        if (JUnitUtil.getTestMethod(psiElement, checkAbstract) != null) {
-          foundMembers.add(psiElement);
-        }
-      } else if (psiElement instanceof PsiDirectory) {
-        final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)psiElement);
-        if (aPackage != null) {
-          foundMembers.add(aPackage);
-        }
-      }
-    }
-    return foundMembers;
-  }
-
-  public static boolean isMultipleElementsSelected(ConfigurationContext context) {
-    if (TestsUIUtil.isMultipleSelectionImpossible(context.getDataContext())) return false;
-    final LinkedHashSet<String> classes = new LinkedHashSet<String>();
-    final PsiElement[] elements = collectPatternElements(context, classes);
-    if (elements != null && collectTestMembers(elements, false).size() > 1) {
-      return true;
+  @Override
+  public boolean isConfigurationFromContext(JUnitConfiguration unitConfiguration, ConfigurationContext context) {
+    final TestObject testobject = unitConfiguration.getTestObject();
+    if (testobject instanceof TestsPattern) {
+      final Set<String> patterns = unitConfiguration.getPersistentData().getPatterns();
+      if (ourDelegate.isConfiguredFromContext(context, patterns)) return true;
     }
     return false;
   }
-  
-  private static PsiElement[] collectPatternElements(ConfigurationContext context, LinkedHashSet<String> classes) {
-    final DataContext dataContext = context.getDataContext();
-    final Location<?>[] locations = Location.DATA_KEYS.getData(dataContext);
-    if (locations != null) {
-      List<PsiElement> elements = new ArrayList<PsiElement>();
-      for (Location<?> location : locations) {
-        final PsiElement psiElement = location.getPsiElement();
-        classes.add(getQName(psiElement, location));
-        elements.add(psiElement);
-      }
-      return elements.toArray(new PsiElement[elements.size()]);
-    }
-    PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
-    if (elements != null) {
-      for (PsiElement psiClass : collectTestMembers(elements, true)) {
-        classes.add(getQName(psiClass));
-      }
-      return elements;
-    } else {
-      final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
-      if (files != null) {
-        final List<PsiFile> psiFiles = new ArrayList<PsiFile>();
-        final PsiManager psiManager = PsiManager.getInstance(context.getProject());
-        for (VirtualFile file : files) {
-          final PsiFile psiFile = psiManager.findFile(file);
-          if (psiFile instanceof PsiClassOwner) {
-            for (PsiElement psiMember : collectTestMembers(((PsiClassOwner)psiFile).getClasses(), true)) {
-              classes.add(((PsiClass)psiMember).getQualifiedName());
-            }
-            psiFiles.add(psiFile);
-          }
-        }
-        return psiFiles.toArray(new PsiElement[psiFiles.size()]);
-      }
-    }
-    return null;
-  }
 
-  public static String getQName(PsiElement psiMember) {
-    return getQName(psiMember, null);
+  public static Module findModule(ModuleBasedConfiguration configuration, Module contextModule, Set<String> patterns) {
+    return ourDelegate.findModule(configuration, contextModule, patterns);
   }
 
-  public static String getQName(PsiElement psiMember, Location location) {
-    if (psiMember instanceof PsiClass) {
-      return ((PsiClass)psiMember).getQualifiedName();
-    }
-    else if (psiMember instanceof PsiMember) {
-      final PsiClass containingClass = location instanceof MethodLocation ? ((MethodLocation)location).getContainingClass(): ((PsiMember)psiMember).getContainingClass();
-      assert containingClass != null;
-      return containingClass.getQualifiedName() + "," + ((PsiMember)psiMember).getName();
-    } else if (psiMember instanceof PsiPackage) {
-      return ((PsiPackage)psiMember).getQualifiedName();
-    }
-    assert false;
-    return null;
+  public static boolean isMultipleElementsSelected(ConfigurationContext context) {
+    return ourDelegate.isMultipleElementsSelected(context);
   }
 
-  @Override
-  public boolean isConfigurationFromContext(JUnitConfiguration unitConfiguration, ConfigurationContext context) {
-    final LinkedHashSet<String> classes = new LinkedHashSet<String>();
-    collectPatternElements(context, classes);
-    final TestObject testobject = unitConfiguration.getTestObject();
-    if (testobject instanceof TestsPattern) {
-      if (Comparing.equal(classes, unitConfiguration.getPersistentData().getPatterns())) {
-        return true;
-      }
-    }
-    return false;
+  public static Set<PsiElement> collectTestMembers(PsiElement[] elements, boolean checkAbstract) {
+    return ourDelegate.collectTestMembers(elements, checkAbstract);
   }
 }
index 8baed4adb8895abf51c1adc335fe0a2720b8bbbd..c88019bb8ac2323ab0d16fd4ca889b2848253ccd 100644 (file)
@@ -22,6 +22,7 @@ package com.theoryinpractice.testng.configuration;
 
 import com.intellij.execution.JavaExecutionUtil;
 import com.intellij.execution.Location;
+import com.intellij.execution.PatternConfigurationDelegate;
 import com.intellij.execution.actions.ConfigurationContext;
 import com.intellij.execution.configurations.ModuleBasedConfiguration;
 import com.intellij.execution.junit.JUnitUtil;
@@ -46,127 +47,55 @@ import java.util.List;
 import java.util.Set;
 
 public class TestNGPatternConfigurationProducer extends TestNGConfigurationProducer{
+  private static PatternConfigurationDelegate ourDelegate = new PatternConfigurationDelegate() {
+    @Override
+    protected boolean isTestClass(PsiClass psiClass) {
+      return TestNGUtil.hasTest(psiClass);
+    }
+
+    @Override
+    protected boolean isTestMethod(boolean checkAbstract, PsiElement psiElement) {
+      return psiElement instanceof PsiModifierListOwner && TestNGUtil.hasTest((PsiModifierListOwner)psiElement);
+    }
+  };
 
   @Override
   protected boolean setupConfigurationFromContext(TestNGConfiguration configuration,
                                                   ConfigurationContext context,
                                                   Ref<PsiElement> sourceElement) {
     final LinkedHashSet<String> classes = new LinkedHashSet<String>();
-    PsiElement[] elements = collectPatternElements(context, classes);
-    if (elements == null || collectTestMembers(elements).size() <= 1) {
+    final PsiElement element = ourDelegate.checkPatterns(context, classes);
+    if (element == null) {
       return false;
     }
+    sourceElement.set(element);
     final TestData data = configuration.getPersistantData();
     data.setPatterns(classes);
     data.TEST_OBJECT = TestType.PATTERN.getType();
     data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
     configuration.setGeneratedName();
-    sourceElement.set(elements[0]);
     return true;
   }
 
-  static Set<PsiMember> collectTestMembers(PsiElement[] psiElements) {
-    final Set<PsiMember> foundMembers = new LinkedHashSet<PsiMember>();
-    for (PsiElement psiElement : psiElements) {
-      if (psiElement instanceof PsiClassOwner) {
-        final PsiClass[] classes = ((PsiClassOwner)psiElement).getClasses();
-        for (PsiClass aClass : classes) {
-          if (TestNGUtil.hasTest(aClass)) {
-            foundMembers.add(aClass);
-          }
-        }
-      } else if (psiElement instanceof PsiClass) {
-        if (TestNGUtil.hasTest((PsiClass)psiElement)) {
-          foundMembers.add((PsiClass)psiElement);
-        }
-      } else if (psiElement instanceof PsiMethod) {
-        if (TestNGUtil.hasTest((PsiModifierListOwner)psiElement)) {
-          foundMembers.add((PsiMember)psiElement);
-        }
-      }
-    }
-    return foundMembers;
-  }
-
   public static boolean isMultipleElementsSelected(ConfigurationContext context) {
-    if (TestsUIUtil.isMultipleSelectionImpossible(context.getDataContext())) return false;
-    final LinkedHashSet<String> classes = new LinkedHashSet<String>();
-    final PsiElement[] elements = collectPatternElements(context, classes);
-    if (elements != null && collectTestMembers(elements).size() > 1) {
-      return true;
-    }
-    return false;
+    return ourDelegate.isMultipleElementsSelected(context);
   }
 
-  private static PsiElement[] collectPatternElements(ConfigurationContext context, LinkedHashSet<String> classes) {
-    final DataContext dataContext = context.getDataContext();
-    final Location<?>[] locations = Location.DATA_KEYS.getData(dataContext);
-    if (locations != null) {
-      List<PsiElement> elements = new ArrayList<PsiElement>();
-      for (Location<?> location : locations) {
-        final PsiElement psiElement = location.getPsiElement();
-        classes.add(getQName(psiElement, location));
-        elements.add(psiElement);
-      }
-      return elements.toArray(new PsiElement[elements.size()]);
-    }
-    PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
-    if (elements != null) {
-      for (PsiMember psiMember : collectTestMembers(elements)) {
-        classes.add(getQName(psiMember, null));
-      }
-      return elements;
-    } else {
-      final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
-      if (file instanceof PsiClassOwner) {
-        for (PsiMember psiMember : collectTestMembers(((PsiClassOwner)file).getClasses())) {
-          classes.add(((PsiClass)psiMember).getQualifiedName());
-        }
-        return new PsiElement[]{file};
-      }
-    }
-    return null;
-  }
-
-  public static String getQName(PsiElement psiMember, Location location) {
-    if (psiMember instanceof PsiClass) {
-      return ((PsiClass)psiMember).getQualifiedName();
-    }
-    else if (psiMember instanceof PsiMember) {
-      final PsiClass containingClass = location instanceof MethodLocation
-                                       ? ((MethodLocation)location).getContainingClass(): ((PsiMember)psiMember).getContainingClass();
-      assert containingClass != null;
-      return containingClass.getQualifiedName() + "," + ((PsiMember)psiMember).getName();
-    } else if (psiMember instanceof PsiPackage) {
-      return ((PsiPackage)psiMember).getQualifiedName();
-    }
-    assert false;
-    return null;
+  public static Module findModule(ModuleBasedConfiguration configuration, Module contextModule, Set<String> patterns) {
+    return ourDelegate.findModule(configuration, contextModule, patterns);
   }
-
+  
   @Override
   protected Module findModule(TestNGConfiguration configuration, Module contextModule) {
     final Set<String> patterns = configuration.data.getPatterns();
-    return findModule(configuration, contextModule, patterns);
-  }
-
-  public static Module findModule(ModuleBasedConfiguration configuration, Module contextModule, Set<String> patterns) {
-    return JavaExecutionUtil.findModule(contextModule, patterns, configuration.getProject(), new Condition<PsiClass>() {
-      @Override
-      public boolean value(PsiClass psiClass) {
-        return TestNGUtil.hasTest(psiClass);
-      }
-    });
+    return ourDelegate.findModule(configuration, contextModule, patterns);
   }
 
   @Override
   public boolean isConfigurationFromContext(TestNGConfiguration testNGConfiguration, ConfigurationContext context) {
-    final LinkedHashSet<String> classes = new LinkedHashSet<String>();
-    collectPatternElements(context, classes);
     final String type = testNGConfiguration.getPersistantData().TEST_OBJECT;
-    if (Comparing.equal(type, TestType.PATTERN.getType()) &&
-        Comparing.equal(classes, testNGConfiguration.getPersistantData().getPatterns())) {
-      return true;
+    if (Comparing.equal(type, TestType.PATTERN.getType())) {
+      return ourDelegate.isConfiguredFromContext(context, testNGConfiguration.getPersistantData().getPatterns());
     }
     return false;
   }