Search in sources :

Example 1 with JavaClass

use of com.thoughtworks.qdox.model.JavaClass in project maven-plugins by apache.

the class AbstractFixJavadocMojoTest method testReplaceLinkTags_spacesAfterMethod.

public void testReplaceLinkTags_spacesAfterMethod() throws Throwable {
    String comment = "/** {@link ConnectException#getMessage()       } */";
    AbstractInheritableJavaEntity entity = spy(new PrivateAbstractInheritableJavaEntity());
    JavaClass clazz = mock(JavaClass.class);
    when(entity.getParentClass()).thenReturn(clazz);
    when(clazz.resolveType("ConnectException")).thenReturn("java.net.ConnectException");
    String newComment = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "replaceLinkTags", new Class[] { String.class, AbstractInheritableJavaEntity.class }, new Object[] { comment, entity });
    assertEquals("/** {@link java.net.ConnectException#getMessage()} */", newComment);
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass) JavaClass(com.thoughtworks.qdox.model.JavaClass) AbstractInheritableJavaEntity(com.thoughtworks.qdox.model.AbstractInheritableJavaEntity)

Example 2 with JavaClass

use of com.thoughtworks.qdox.model.JavaClass in project maven-plugins by apache.

the class AbstractFixJavadocMojoTest method testReplaceLinkTags_spacesAfterLinkTag.

public void testReplaceLinkTags_spacesAfterLinkTag() throws Throwable {
    String comment = "/** {@link     ConnectException} */";
    AbstractInheritableJavaEntity entity = spy(new PrivateAbstractInheritableJavaEntity());
    JavaClass clazz = mock(JavaClass.class);
    when(entity.getParentClass()).thenReturn(clazz);
    when(clazz.resolveType("ConnectException")).thenReturn("java.net.ConnectException");
    String newComment = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "replaceLinkTags", new Class[] { String.class, AbstractInheritableJavaEntity.class }, new Object[] { comment, entity });
    assertEquals("/** {@link java.net.ConnectException} */", newComment);
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass) JavaClass(com.thoughtworks.qdox.model.JavaClass) AbstractInheritableJavaEntity(com.thoughtworks.qdox.model.AbstractInheritableJavaEntity)

Example 3 with JavaClass

use of com.thoughtworks.qdox.model.JavaClass in project maven-plugins by apache.

the class AbstractFixJavadocMojoTest method testReplaceLinkTags_missingEndBrace.

public void testReplaceLinkTags_missingEndBrace() throws Throwable {
    String comment = "/** {@link ConnectException */";
    AbstractInheritableJavaEntity entity = spy(new PrivateAbstractInheritableJavaEntity());
    JavaClass clazz = mock(JavaClass.class);
    when(entity.getParentClass()).thenReturn(clazz);
    when(clazz.resolveType("ConnectException")).thenReturn("java.net.ConnectException");
    String newComment = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "replaceLinkTags", new Class[] { String.class, AbstractInheritableJavaEntity.class }, new Object[] { comment, entity });
    assertEquals("/** {@link ConnectException */", newComment);
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass) JavaClass(com.thoughtworks.qdox.model.JavaClass) AbstractInheritableJavaEntity(com.thoughtworks.qdox.model.AbstractInheritableJavaEntity)

Example 4 with JavaClass

use of com.thoughtworks.qdox.model.JavaClass in project maven-plugins by apache.

the class FixJavadocMojoTest method testJavadocComment.

/**
     * @throws Throwable if any
     */
public void testJavadocComment() throws Throwable {
    String content = "/**" + EOL + " * Dummy Class." + EOL + " */" + EOL + "public class DummyClass" + EOL + "{" + EOL + "    /**" + EOL + "     *" + EOL + "     * Dummy" + EOL + "     *" + EOL + "     *      Method." + EOL + "     *" + EOL + "     * @param args not" + EOL + "     *" + EOL + "     * null" + EOL + "     * @param i non negative" + EOL + "     * @param object could" + EOL + "     * be" + EOL + "     *      null" + EOL + "     * @return a" + EOL + "     * String" + EOL + "     *" + EOL + "     * @throws Exception if" + EOL + "     * any" + EOL + "     *" + EOL + "     */" + EOL + "    public static String dummyMethod( String[] args, int i, Object object )" + EOL + "        throws Exception" + EOL + "    {" + EOL + "        return null;" + EOL + "    }" + EOL + "}";
    JavaDocBuilder builder = new JavaDocBuilder();
    builder.setEncoding("UTF-8");
    builder.addSource(new StringReader(content));
    JavaClass[] classes = builder.getClasses();
    JavaClass clazz = classes[0];
    JavaMethod javaMethod = clazz.getMethods()[0];
    String javadoc = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "extractOriginalJavadoc", new Class[] { String.class, AbstractJavaEntity.class }, new Object[] { content, javaMethod });
    assertEquals("    /**" + EOL + "     *" + EOL + "     * Dummy" + EOL + "     *" + EOL + "     *      Method." + EOL + "     *" + EOL + "     * @param args not" + EOL + "     *" + EOL + "     * null" + EOL + "     * @param i non negative" + EOL + "     * @param object could" + EOL + "     * be" + EOL + "     *      null" + EOL + "     * @return a" + EOL + "     * String" + EOL + "     *" + EOL + "     * @throws Exception if" + EOL + "     * any" + EOL + "     *" + EOL + "     */", javadoc);
    String javadocContent = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "extractOriginalJavadocContent", new Class[] { String.class, AbstractJavaEntity.class }, new Object[] { content, javaMethod });
    assertEquals("     *" + EOL + "     * Dummy" + EOL + "     *" + EOL + "     *      Method." + EOL + "     *" + EOL + "     * @param args not" + EOL + "     *" + EOL + "     * null" + EOL + "     * @param i non negative" + EOL + "     * @param object could" + EOL + "     * be" + EOL + "     *      null" + EOL + "     * @return a" + EOL + "     * String" + EOL + "     *" + EOL + "     * @throws Exception if" + EOL + "     * any" + EOL + "     *", javadocContent);
    String withoutEmptyJavadocLines = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "removeLastEmptyJavadocLines", new Class[] { String.class }, new Object[] { javadocContent });
    assertTrue(withoutEmptyJavadocLines.endsWith("any"));
    String methodJavadoc = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "getJavadocComment", new Class[] { String.class, AbstractJavaEntity.class }, new Object[] { content, javaMethod });
    assertEquals("     *" + EOL + "     * Dummy" + EOL + "     *" + EOL + "     *      Method." + EOL + "     *", methodJavadoc);
    withoutEmptyJavadocLines = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "removeLastEmptyJavadocLines", new Class[] { String.class }, new Object[] { methodJavadoc });
    assertTrue(withoutEmptyJavadocLines.endsWith("Method."));
    assertEquals(5, javaMethod.getTags().length);
    AbstractFixJavadocMojo mojoInstance = new FixJavadocMojo();
    setVariableValueToObject(mojoInstance, "fixTagsSplitted", new String[] { "all" });
    DocletTag tag = javaMethod.getTags()[0];
    String tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
    assertEquals("     * @param args not" + EOL + "     *" + EOL + "     * null", tagJavadoc);
    withoutEmptyJavadocLines = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "removeLastEmptyJavadocLines", new Class[] { String.class }, new Object[] { tagJavadoc });
    assertTrue(withoutEmptyJavadocLines.endsWith("null"));
    tag = javaMethod.getTags()[1];
    tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
    assertEquals("     * @param i non negative", tagJavadoc);
    withoutEmptyJavadocLines = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "removeLastEmptyJavadocLines", new Class[] { String.class }, new Object[] { tagJavadoc });
    assertTrue(withoutEmptyJavadocLines.endsWith("negative"));
    tag = javaMethod.getTags()[2];
    tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
    assertEquals("     * @param object could" + EOL + "     * be" + EOL + "     *      null", tagJavadoc);
    withoutEmptyJavadocLines = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "removeLastEmptyJavadocLines", new Class[] { String.class }, new Object[] { tagJavadoc });
    assertTrue(withoutEmptyJavadocLines.endsWith("null"));
    tag = javaMethod.getTags()[3];
    tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
    assertEquals("     * @return a" + EOL + "     * String" + EOL + "     *", tagJavadoc);
    withoutEmptyJavadocLines = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "removeLastEmptyJavadocLines", new Class[] { String.class }, new Object[] { tagJavadoc });
    assertTrue(withoutEmptyJavadocLines.endsWith("String"));
    tag = javaMethod.getTags()[4];
    tagJavadoc = (String) PrivateAccessor.invoke(mojoInstance, "getJavadocComment", new Class[] { String.class, AbstractInheritableJavaEntity.class, DocletTag.class }, new Object[] { content, javaMethod, tag });
    assertEquals("     * @throws Exception if" + EOL + "     * any" + EOL + "     *", tagJavadoc);
    withoutEmptyJavadocLines = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "removeLastEmptyJavadocLines", new Class[] { String.class }, new Object[] { tagJavadoc });
    assertTrue(withoutEmptyJavadocLines.endsWith("any"));
}
Also used : AbstractInheritableJavaEntity(com.thoughtworks.qdox.model.AbstractInheritableJavaEntity) JavaDocBuilder(com.thoughtworks.qdox.JavaDocBuilder) AbstractJavaEntity(com.thoughtworks.qdox.model.AbstractJavaEntity) JavaClass(com.thoughtworks.qdox.model.JavaClass) StringReader(java.io.StringReader) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) JavaClass(com.thoughtworks.qdox.model.JavaClass) DocletTag(com.thoughtworks.qdox.model.DocletTag)

Example 5 with JavaClass

use of com.thoughtworks.qdox.model.JavaClass in project maven-plugins by apache.

the class AbstractFixJavadocMojoTest method testReplaceLinkTags_spacesAfterClassName.

public void testReplaceLinkTags_spacesAfterClassName() throws Throwable {
    String comment = "/** {@link ConnectException       } */";
    AbstractInheritableJavaEntity entity = spy(new PrivateAbstractInheritableJavaEntity());
    JavaClass clazz = mock(JavaClass.class);
    when(entity.getParentClass()).thenReturn(clazz);
    when(clazz.resolveType("ConnectException")).thenReturn("java.net.ConnectException");
    String newComment = (String) PrivateAccessor.invoke(AbstractFixJavadocMojo.class, "replaceLinkTags", new Class[] { String.class, AbstractInheritableJavaEntity.class }, new Object[] { comment, entity });
    assertEquals("/** {@link java.net.ConnectException} */", newComment);
}
Also used : JavaClass(com.thoughtworks.qdox.model.JavaClass) JavaClass(com.thoughtworks.qdox.model.JavaClass) AbstractInheritableJavaEntity(com.thoughtworks.qdox.model.AbstractInheritableJavaEntity)

Aggregations

JavaClass (com.thoughtworks.qdox.model.JavaClass)48 AbstractInheritableJavaEntity (com.thoughtworks.qdox.model.AbstractInheritableJavaEntity)12 JavaMethod (com.thoughtworks.qdox.model.JavaMethod)12 DocletTag (com.thoughtworks.qdox.model.DocletTag)10 JavaDocBuilder (com.thoughtworks.qdox.JavaDocBuilder)6 File (java.io.File)6 StringReader (java.io.StringReader)6 JavaParameter (com.thoughtworks.qdox.model.JavaParameter)5 JavaSource (com.thoughtworks.qdox.model.JavaSource)5 ArrayList (java.util.ArrayList)5 JavaProjectBuilder (com.thoughtworks.qdox.JavaProjectBuilder)4 BeanProperty (com.thoughtworks.qdox.model.BeanProperty)4 JavaField (com.thoughtworks.qdox.model.JavaField)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Test (org.junit.Test)3 AbstractJavaEntity (com.thoughtworks.qdox.model.AbstractJavaEntity)2 JavaExecutable (com.thoughtworks.qdox.model.JavaExecutable)2 JavaMember (com.thoughtworks.qdox.model.JavaMember)2 JavaType (com.thoughtworks.qdox.model.JavaType)2