Beispiel #1
0
  /**
   * Adds a syntax to the syntaxsection
   *
   * @param doc, doc item that has to be add to the syntax section
   */
  void addSyntax(Doc doc) {
    if (doc.isConstructor() || doc.isMethod()) {
      StringBuffer syntaxBuffer = new StringBuffer();
      for (Parameter parameter : ((ExecutableMemberDoc) doc).parameters()) {
        syntaxBuffer.append(parameter.typeName() + " " + parameter.name());
        syntaxBuffer.append(", ");
      }
      if (syntaxBuffer.length() > 2) {
        syntaxBuffer.delete(syntaxBuffer.length() - 2, syntaxBuffer.length());
      }

      String returnType = "";

      if (doc.isMethod()) {
        MethodDoc methodDoc = (MethodDoc) doc;
        returnType = methodDoc.returnType().toString();
        int lastDot = returnType.lastIndexOf('.');
        if (lastDot != -1) {
          returnType = returnType.substring(lastDot + 1);
        }
        returnType += " ";
      }

      if (doc.isConstructor()) {
        addSyntax("<em>" + doc.commentText() + "</em>");
      }

      addSyntax(returnType + doc.name() + "(" + syntaxBuffer.toString() + ")");
    } else if (doc.isField()) {
      FieldDoc fieldDoc = (FieldDoc) doc;
      addSyntax(fieldDoc.type().typeName() + " " + doc.name());
    }
  }
  @Test
  public void testTagRender() {
    Doc mockDoc = mock(Doc.class);
    Tag mockTag = mock(Tag.class);

    String tagName = "tagName";
    String tagText = "tagText";
    String asciidoctorRenderedString = "rendered";

    when(mockTag.name()).thenReturn(tagName);
    when(mockTag.text()).thenReturn(tagText);

    when(mockDoc.getRawCommentText()).thenReturn("input");
    when(mockDoc.commentText()).thenReturn("input");
    when(mockDoc.tags()).thenReturn(new Tag[] {mockTag});

    when(mockAsciidoctor.render(eq("input"), argThat(new OptionsMatcher(false))))
        .thenReturn("input");
    when(mockAsciidoctor.render(eq(tagText), argThat(new OptionsMatcher(true))))
        .thenReturn(asciidoctorRenderedString);

    renderer.renderDoc(mockDoc);

    verify(mockAsciidoctor).render(eq("input"), argThat(new OptionsMatcher(false)));
    verify(mockAsciidoctor).render(eq(tagText), argThat(new OptionsMatcher(true)));
    verify(mockDoc).setRawCommentText("input");
    verify(mockDoc).setRawCommentText("input\n" + tagName + " " + asciidoctorRenderedString + "\n");
  }
Beispiel #3
0
  public String getCommentText() {

    String commentText = mDoc.commentText();
    if (commentText != null && commentText.trim().length() > 0) {
      return commentText;
    }

    return null;
  }
  @Test
  public void testAtLiteralRender() {
    Doc mockDoc = mock(Doc.class);
    String convertedText = "Test";
    String rawText = "@" + convertedText;

    when(mockDoc.getRawCommentText()).thenReturn(rawText);
    when(mockDoc.commentText()).thenReturn("input");
    when(mockDoc.tags()).thenReturn(new Tag[] {});
    when(mockAsciidoctor.render(anyString(), any(Options.class))).thenReturn("input");

    renderer.renderDoc(mockDoc);
    verify(mockDoc).setRawCommentText("{@literal @}" + convertedText);
    verify(mockAsciidoctor).render(anyString(), any(Options.class));
  }
  @Test
  public void testParamTagWithTypeParameter() {
    String commentText = "comment";
    String param1Name = "T";
    String param1Desc = "";
    String param1Text = "<" + param1Name + ">";
    String param2Name = "X";
    String param2Desc = "description";
    String param2Text = "<" + param2Name + "> " + param2Desc;
    String sourceText = commentText + "\n@param " + param1Text + "\n@param " + param2Text;

    Doc mockDoc = mock(Doc.class);
    when(mockDoc.getRawCommentText()).thenReturn(sourceText);
    when(mockDoc.commentText()).thenReturn(commentText);
    Tag[] tags = new Tag[2];
    ParamTag mockTag1 = mock(ParamTag.class);
    when(mockTag1.name()).thenReturn("@param");
    when(mockTag1.isTypeParameter()).thenReturn(true);
    when(mockTag1.parameterName()).thenReturn(param1Name);
    when(mockTag1.parameterComment()).thenReturn(param1Desc);
    tags[0] = mockTag1;
    ParamTag mockTag2 = mock(ParamTag.class);
    when(mockTag2.name()).thenReturn("@param");
    when(mockTag2.isTypeParameter()).thenReturn(true);
    when(mockTag2.parameterName()).thenReturn(param2Name);
    when(mockTag2.parameterComment()).thenReturn(param2Desc);
    tags[1] = mockTag2;
    when(mockDoc.tags()).thenReturn(tags);
    when(mockAsciidoctor.render(eq(commentText), any(Options.class))).thenReturn(commentText);
    when(mockAsciidoctor.render(eq(param2Desc), any(Options.class))).thenReturn(param2Desc);

    renderer.renderDoc(mockDoc);

    verify(mockAsciidoctor).render(eq(commentText), argThat(new OptionsMatcher(false)));
    verify(mockAsciidoctor).render(eq(param2Desc), argThat(new OptionsMatcher(true)));
    // fixture step
    verify(mockDoc).setRawCommentText(eq(sourceText));
    // result step
    verify(mockDoc).setRawCommentText(eq(sourceText));
  }