Пример #1
0
  /** @param theClass TestCase class */
  private void addTestsFromTestCase(Class<?> theClass) {
    setName(theClass.getName());

    try {
      getTestConstructor(theClass);
    } catch (NoSuchMethodException ex) {
      addTest(
          warning(
              "Class "
                  + theClass.getName()
                  + " has no public constructor TestCase(String name) or TestCase()"));

      return;
    }

    if (!Modifier.isPublic(theClass.getModifiers()))
      addTest(warning("Class " + theClass.getName() + " is not public"));
    else {
      IgnoreDescriptor clsIgnore = IgnoreDescriptor.forClass(theClass);

      Class superCls = theClass;

      int testAdded = 0;
      int testSkipped = 0;

      LinkedList<Test> addedTests = new LinkedList<>();

      for (List<String> names = new ArrayList<>();
          Test.class.isAssignableFrom(superCls);
          superCls = superCls.getSuperclass()) {

        Method[] methods = MethodSorter.getDeclaredMethods(superCls);

        for (Method each : methods) {
          AddResult res = addTestMethod(each, names, theClass, clsIgnore);

          if (res.added()) {
            testAdded++;

            addedTests.add(res.test());
          } else testSkipped++;
        }
      }

      if (testAdded == 0 && testSkipped == 0)
        addTest(warning("No tests found in " + theClass.getName()));

      // Populate tests count.
      for (Test test : addedTests) {
        if (test instanceof GridAbstractTest) {
          GridAbstractTest test0 = (GridAbstractTest) test;

          test0.forceTestCount(addedTests.size());
        }
      }
    }
  }
Пример #2
0
 public TestClass(Class<?> paramClass) {
   this.fClass = paramClass;
   if ((paramClass != null) && (paramClass.getConstructors().length > 1)) {
     throw new IllegalArgumentException("Test class can only have one constructor");
   }
   paramClass = getSuperClasses(this.fClass).iterator();
   while (paramClass.hasNext()) {
     Object localObject = (Class) paramClass.next();
     Method[] arrayOfMethod = MethodSorter.getDeclaredMethods((Class) localObject);
     int j = arrayOfMethod.length;
     int i = 0;
     while (i < j) {
       addToAnnotationLists(new FrameworkMethod(arrayOfMethod[i]), this.fMethodsForAnnotations);
       i += 1;
     }
     localObject = ((Class) localObject).getDeclaredFields();
     j = localObject.length;
     i = 0;
     while (i < j) {
       addToAnnotationLists(new FrameworkField(localObject[i]), this.fFieldsForAnnotations);
       i += 1;
     }
   }
 }