Beispiel #1
0
  public BodyDeclaration getTreeNode() {
    //        System.out.println("Building Method " + node.getName());

    String finalName = name + type.name() + Config.get().getTestMethodSuffix();
    MethodDeclaration result = new MethodDeclaration(ModifierSet.PUBLIC, new VoidType(), finalName);

    result.setComment(
        new BlockComment(
            "\n\t\tGenerated Unity test\n\t\t" + name + " - " + type.name() + " test." + "\n\t"));

    AnnotationExpr anno = new MarkerAnnotationExpr(new NameExpr("Test"));
    List<AnnotationExpr> annoList = new ArrayList<>();
    annoList.add(anno);
    result.setAnnotations(annoList);

    BlockStmt body = new BlockStmt();
    List<Statement> statements = new ArrayList<>();
    statements.add(instance.getStatement());

    body.setStmts(statements);
    result.setBody(body);

    // Set any mocks
    // Set instance
    // Set call parameters
    // Set call result
    // Set assertions
    return result;
  }
Beispiel #2
0
  @Override
  public void add(MethodInfo method) {
    MethodDeclaration methodDeclaration;

    if (method instanceof MethodDeclarationWrapper) {
      val wrapper = (MethodDeclarationWrapper) method;
      methodDeclaration = (MethodDeclaration) wrapper.declaration.clone();
      methodDeclaration.setAnnotations(Collections.emptyList());
      wrapper
          .getClassInfo()
          .changeTypeContext(wrapper.getContext(), getContext(), methodDeclaration);
    } else {
      methodDeclaration = new MethodDeclaration();
      new MethodDeclarationWrapper(methodDeclaration).setAll(method);
    }

    addMember(methodDeclaration);
  }