Пример #1
0
 private Boolean hasCorrectCategoryAnnotation(Description description) {
   Category category = description.getAnnotation(Category.class);
   if (category == null) return null;
   for (Class<?> each : category.value()) {
     if (getCategoryMarkerClass().isAssignableFrom(each)) return true;
   }
   return false;
 }
 private static void findSuperclassCategories(Set<Class<?>> cats, Class<?> clazz) {
   if (clazz != null && clazz.getSuperclass() != null) {
     Category cat = clazz.getSuperclass().getAnnotation(Category.class);
     if (cat != null) {
       addAll(cats, cat.value());
     } else {
       findSuperclassCategories(cats, clazz.getSuperclass());
     }
   }
 }
  private boolean shouldRun(Description description, Description parent, Class<?> parentClass) {
    if (matcher == null) {
      return true;
    } else {
      Set<Class<?>> cats = new HashSet<Class<?>>();
      Category cat = description.getAnnotation(Category.class);
      if (cat != null) {
        addAll(cats, cat.value());
      }

      if (parent != null) {
        cat = parent.getAnnotation(Category.class);
        if (cat != null) {
          addAll(cats, cat.value());
        }
      }

      if (parentClass != null) {
        findSuperclassCategories(cats, parentClass);
      }

      Class<?> testClass = description.getTestClass();
      if (testClass != null) {
        cat = testClass.getAnnotation(Category.class);
        if (cat != null) {
          addAll(cats, cat.value());
        }
      }

      cats.remove(null);

      boolean result = matcher.enabled(cats.toArray(new Class<?>[cats.size()]));

      if (!result) {
        ArrayList<Description> children = description.getChildren();
        if (children != null) {
          for (Description child : children) {
            if (shouldRun(child, description, null)) {
              result = true;
              break;
            }
          }
        }
      }

      return result;
    }
  }
Пример #4
0
    // TODO: this type correct?
    @Override
    public List<Runner> matchingRunners(List<? extends Runner> allPossibleRunners) {
      ArrayList<Runner> result = new ArrayList<Runner>();
      for (Runner eachRunner : allPossibleRunners) {
        Collection<Annotation> annotations = eachRunner.getDescription().getAnnotations();
        // TODO: extract method
        for (Annotation eachAnnotation : annotations) {
          if (eachAnnotation.annotationType().equals(Category.class)) {
            Category category = (Category) eachAnnotation;
            Class<?>[] categories = category.value();
            if (Arrays.asList(categories).contains(fIncluded)) result.add(eachRunner);
          }
        }
      }

      // TODO Auto-generated method stub
      return result;
    }