Search in sources :

Example 1 with MavenProjectStub

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

Example 2 with MavenProjectStub

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()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultArtifactFactory(org.apache.maven.artifact.factory.DefaultArtifactFactory) MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) HashMap(java.util.HashMap) StubArtifactRepository(org.apache.maven.plugin.testing.stubs.StubArtifactRepository) RepositoryManager(org.apache.maven.shared.repository.RepositoryManager) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultArtifactHandlerManager(org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager) DependencyArtifactStubFactory(org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory)

Example 3 with MavenProjectStub

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);
}
Also used : MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) Build(org.apache.maven.model.Build) File(java.io.File)

Example 4 with MavenProjectStub

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!"));
}
Also used : MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) File(java.io.File)

Example 5 with MavenProjectStub

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);
}
Also used : MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) Settings(org.apache.maven.settings.Settings)

Aggregations

MavenProjectStub (org.apache.maven.plugin.testing.stubs.MavenProjectStub)9 File (java.io.File)5 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)2 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)2 JavaDocBuilder (com.thoughtworks.qdox.JavaDocBuilder)1 JavaMethod (com.thoughtworks.qdox.model.JavaMethod)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DefaultArtifactFactory (org.apache.maven.artifact.factory.DefaultArtifactFactory)1 DefaultArtifactHandlerManager (org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager)1 MavenSession (org.apache.maven.execution.MavenSession)1 Build (org.apache.maven.model.Build)1 DeploymentRepository (org.apache.maven.model.DeploymentRepository)1 DistributionManagement (org.apache.maven.model.DistributionManagement)1 Profile (org.apache.maven.model.Profile)1 LegacySupport (org.apache.maven.plugin.LegacySupport)1 JavaEntityTags (org.apache.maven.plugin.javadoc.AbstractFixJavadocMojo.JavaEntityTags)1 StubArtifactRepository (org.apache.maven.plugin.testing.stubs.StubArtifactRepository)1 DependencyArtifactStubFactory (org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory)1