use of org.apache.maven.plugin.testing.stubs.MavenProjectStub 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());
}
use of org.apache.maven.plugin.testing.stubs.MavenProjectStub in project maven-plugins by apache.
the class TestClassifierTypeTranslator method setUp.
protected void setUp() throws Exception {
super.setUp("classifiertype-translator", false);
artifactHandlerManager = new DefaultArtifactHandlerManager();
this.setVariableValueToObject(artifactHandlerManager, "artifactHandlers", new HashMap());
artifactFactory = new DefaultArtifactFactory();
this.setVariableValueToObject(artifactFactory, "artifactHandlerManager", artifactHandlerManager);
artifactRepository = new StubArtifactRepository(null);
DependencyArtifactStubFactory factory = new DependencyArtifactStubFactory(null, false);
artifacts = factory.getMixedArtifacts();
repoManager = lookup(RepositoryManager.class);
MavenSession session = newMavenSession(new MavenProjectStub());
buildingRequest = session.getProjectBuildingRequest();
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
use of org.apache.maven.plugin.testing.stubs.MavenProjectStub in project maven-plugins by apache.
the class CheckstyleViolationCheckMojoTest method mojoSetup.
protected void mojoSetup(Mojo mojo) throws Exception {
// mojo setup
setVariableValueToObject(mojo, "project", new MavenProjectStub() {
public File getFile() {
return new File(getBasedir(), "target/classes");
}
public Build getBuild() {
return new Build() {
private static final long serialVersionUID = -743084937617131258L;
public String getDirectory() {
return getBasedir() + "/target/classes";
}
};
}
});
setVariableValueToObject(mojo, "configLocation", "sun_checks.xml");
setVariableValueToObject(mojo, "cacheFile", getBasedir() + "/target/classes/checkstyle-cachefile");
// new File( getBasedir() + "/target" ) );
setVariableValueToObject(mojo, "sourceDirectories", Arrays.asList(getBasedir() + "/src/test/plugin-configs/src"));
setVariableValueToObject(mojo, "encoding", "UTF-8");
setVariableValueToObject(mojo, "skipExec", Boolean.TRUE);
}
use of org.apache.maven.plugin.testing.stubs.MavenProjectStub in project maven-plugins by apache.
the class AllProfilesMojoTest method testNoProfiles.
/**
* Tests the case when no profiles are present for the projects.
*
* @throws Exception in case of errors.
*/
public void testNoProfiles() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/all-profiles/plugin-config.xml");
AllProfilesMojo mojo = (AllProfilesMojo) lookupMojo("all-profiles", testPom);
setUpMojo(mojo, Arrays.<MavenProject>asList(new MavenProjectStub()), Collections.<org.apache.maven.settings.Profile>emptyList(), "empty.txt");
mojo.execute();
assertTrue(interceptingLogger.warnLogs.contains("No profiles detected!"));
}
use of org.apache.maven.plugin.testing.stubs.MavenProjectStub in project maven-plugins by apache.
the class EvaluateMojoTest method setUpMojo.
private void setUpMojo(EvaluateMojo mojo, InputHandler inputHandler, ExpressionEvaluator expressionEvaluator) throws IllegalAccessException {
setVariableValueToObject(mojo, "inputHandler", inputHandler);
setVariableValueToObject(mojo, "log", interceptingLogger);
setVariableValueToObject(mojo, "settings", new Settings());
setVariableValueToObject(mojo, "project", new MavenProjectStub());
setVariableValueToObject(mojo, "evaluator", expressionEvaluator);
}
Aggregations