Ejemplo n.º 1
0
  private static Method findDataProvider(Class clazz, Method m, IAnnotationFinder finder) {
    Method result = null;
    String dataProviderName = null;
    Class dataProviderClass = null;

    ITestAnnotation annotation = AnnotationHelper.findTest(finder, m);
    if (annotation != null) {
      dataProviderName = annotation.getDataProvider();
      dataProviderClass = annotation.getDataProviderClass();
    }

    if (dataProviderName == null) {
      IFactoryAnnotation factory = AnnotationHelper.findFactory(finder, m);
      if (factory != null) {
        dataProviderName = factory.getDataProvider();
        dataProviderClass = null;
      }
    }

    if (null != dataProviderName && !"".equals(dataProviderName)) {
      result = findDataProvider(clazz, finder, dataProviderName, dataProviderClass);

      if (null == result) {
        throw new TestNGException(
            "Method "
                + m
                + " requires a @DataProvider named : "
                + dataProviderName
                + (dataProviderClass != null ? " in class " + dataProviderClass.getName() : ""));
      }
    }

    return result;
  }
Ejemplo n.º 2
0
  /** @return an instance from Guice if @Test(guiceModule) attribute was found, null otherwise */
  @SuppressWarnings("unchecked")
  private Object getInstanceFromGuice() {
    Annotation annotation = AnnotationHelper.findAnnotationSuperClasses(Guice.class, m_class);
    if (annotation == null) return null;

    Guice guice = (Guice) annotation;
    Module[] modules = getModules(guice, m_class);

    if (modules.length == 0) {
      throw new TestNGException("Couldn't find any Guice module for class " + m_class);
    }

    List<Module> moduleInstances = new ArrayList<Module>();
    for (Module module : modules) {
      moduleInstances.add(module);
    }

    return com.google.inject.Guice.createInjector(moduleInstances).getInstance(m_class);
  }
Ejemplo n.º 3
0
  private void init() {
    IAnnotation a = AnnotationHelper.findConfiguration(m_annotationFinder, m_method.getMethod());
    IConfigurationAnnotation annotation = (IConfigurationAnnotation) a;
    if (a != null) {
      m_inheritGroupsFromTestClass = annotation.getInheritGroups();
      setEnabled(annotation.getEnabled());
      setDescription(annotation.getDescription());
    }

    if (annotation != null && annotation.isFakeConfiguration()) {
      if (annotation.getBeforeSuite()) {
        initGroups(IBeforeSuite.class);
      }
      if (annotation.getAfterSuite()) {
        initGroups(IAfterSuite.class);
      }
      if (annotation.getBeforeTest()) {
        initGroups(IBeforeTest.class);
      }
      if (annotation.getAfterTest()) {
        initGroups(IAfterTest.class);
      }
      if (annotation.getBeforeGroups().length != 0) {
        initGroups(IBeforeGroups.class);
      }
      if (annotation.getAfterGroups().length != 0) {
        initGroups(IAfterGroups.class);
      }
      if (annotation.getBeforeTestClass()) {
        initGroups(IBeforeClass.class);
      }
      if (annotation.getAfterTestClass()) {
        initGroups(IAfterClass.class);
      }
      if (annotation.getBeforeTestMethod()) {
        initGroups(IBeforeMethod.class);
      }
      if (annotation.getAfterTestMethod()) {
        initGroups(IAfterMethod.class);
      }
    } else {
      initGroups(IConfigurationAnnotation.class);
    }

    // If this configuration method has inherit-groups=true, add the groups
    // defined in the @Test class
    if (inheritGroupsFromTestClass()) {
      ITestAnnotation classAnnotation =
          (ITestAnnotation) m_annotationFinder.findAnnotation(m_methodClass, ITestAnnotation.class);
      if (classAnnotation != null) {
        String[] groups = classAnnotation.getGroups();
        Map<String, String> newGroups = Maps.newHashMap();
        for (String g : getGroups()) {
          newGroups.put(g, g);
        }
        if (groups != null) {
          for (String g : groups) {
            newGroups.put(g, g);
          }
          setGroups(newGroups.values().toArray(new String[newGroups.size()]));
        }
      }
    }

    if (annotation != null) {
      setTimeOut(annotation.getTimeOut());
    }
  }