Search in sources :

Example 1 with JavaEntityTags

use of org.apache.maven.plugin.javadoc.AbstractFixJavadocMojo.JavaEntityTags in project maven-plugins by apache.

the class FixJavadocMojoTest method testRemoveUnknownExceptions.

public void testRemoveUnknownExceptions() throws Exception {
    AbstractFixJavadocMojo mojoInstance = new FixJavadocMojo();
    setVariableValueToObject(mojoInstance, "fixTagsSplitted", new String[] { "all" });
    setVariableValueToObject(mojoInstance, "project", new MavenProjectStub());
    String source = "package a.b.c;" + EOL + "public class Clazz {" + EOL + " /**" + EOL + " * @throws java.lang.RuntimeException" + EOL + " * @throws NumberFormatException" + EOL + " * @throws java.lang.Exception" + // not thrown and no RTE -> remove
    EOL + " * @throws com.foo.FatalException" + // not on classpath (?!) -> see removeUnknownThrows
    EOL + " */" + EOL + " public void method() {}" + EOL + "}";
    JavaDocBuilder builder = new JavaDocBuilder();
    JavaMethod javaMethod = builder.addSource(new StringReader(source)).getClasses()[0].getMethods()[0];
    JavaEntityTags javaEntityTags = mojoInstance.parseJavadocTags(source, javaMethod, "", true);
    StringBuilder sb = new StringBuilder();
    mojoInstance.writeThrowsTag(sb, javaMethod, javaEntityTags, new String[] { "java.lang.RuntimeException" });
    assertEquals(" * @throws java.lang.RuntimeException", sb.toString());
    sb = new StringBuilder();
    mojoInstance.writeThrowsTag(sb, javaMethod, javaEntityTags, new String[] { "NumberFormatException" });
    assertEquals(" * @throws java.lang.NumberFormatException", sb.toString());
    sb = new StringBuilder();
    mojoInstance.writeThrowsTag(sb, javaMethod, javaEntityTags, new String[] { "java.lang.Exception" });
    assertEquals("", sb.toString());
    setVariableValueToObject(mojoInstance, "removeUnknownThrows", true);
    sb = new StringBuilder();
    mojoInstance.writeThrowsTag(sb, javaMethod, javaEntityTags, new String[] { "com.foo.FatalException" });
    assertEquals("", sb.toString());
    setVariableValueToObject(mojoInstance, "removeUnknownThrows", false);
    sb = new StringBuilder();
    mojoInstance.writeThrowsTag(sb, javaMethod, javaEntityTags, new String[] { "com.foo.FatalException" });
    assertEquals(" * @throws com.foo.FatalException if any.", sb.toString());
}
Also used : MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) JavaEntityTags(org.apache.maven.plugin.javadoc.AbstractFixJavadocMojo.JavaEntityTags) StringReader(java.io.StringReader) JavaMethod(com.thoughtworks.qdox.model.JavaMethod) JavaDocBuilder(com.thoughtworks.qdox.JavaDocBuilder)

Aggregations

JavaDocBuilder (com.thoughtworks.qdox.JavaDocBuilder)1 JavaMethod (com.thoughtworks.qdox.model.JavaMethod)1 StringReader (java.io.StringReader)1 JavaEntityTags (org.apache.maven.plugin.javadoc.AbstractFixJavadocMojo.JavaEntityTags)1 MavenProjectStub (org.apache.maven.plugin.testing.stubs.MavenProjectStub)1