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());
}
Aggregations