Exemplo n.º 1
0
  /**
   * Add the pattern to the node. As a side effect, Branch or EOS nodes may be inserted in the
   * original place of this node.
   */
  public AddResult add(int depth, String pattern) {
    AddResult result;
    PatternNodeFactory patternNodeFactory = parentContext.getPNF();
    if (depth == pattern.length()) {
      PatternNode node = new EndOfStringNode(parentContext, this);
      result = node.add(depth, pattern);
      return result;
    }
    if (Pattern.getType(depth, pattern) != type) {
      PatternNode node = new BranchNode(parentContext, this);
      result = node.add(depth, pattern);
      return result;
    }

    depth++;

    // if we're at the end of the pattern, don't create unnecessary EOS nodes
    if (depth == pattern.length()) {
      return new AddResult(this, this, depth);
    }

    if (next == null) {
      next = patternNodeFactory.getInstance(parentContext, depth, pattern);
    }
    result = next.add(depth, pattern);
    next = result.root;
    result.root = this;
    return result;
  }
Exemplo n.º 2
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());
        }
      }
    }
  }