blob: 07172cab3e7fcf3a0324086d0a34990fb5b675ed [file] [log] [blame]
package sample.plugin;
import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.plugin.testing.WithoutMojo;
import org.junit.Rule;
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.File;
public class MyMojoTest
{
@Rule
public MojoRule rule = new MojoRule()
{
@Override
protected void before() throws Throwable
{
}
@Override
protected void after()
{
}
};
/**
* @throws Exception if any
*/
@Test
public void testSomething()
throws Exception
{
File pom = new File( "target/test-classes/project-to-test/" );
assertNotNull( pom );
assertTrue( pom.exists() );
MyMojo myMojo = ( MyMojo ) rule.lookupConfiguredMojo( pom, "touch" );
assertNotNull( myMojo );
myMojo.execute();
File outputDirectory = ( File ) rule.getVariableValueFromObject( myMojo, "outputDirectory" );
assertNotNull( outputDirectory );
assertTrue( outputDirectory.exists() );
File touch = new File( outputDirectory, "touch.txt" );
assertTrue( touch.exists() );
}
/** Do not need the MojoRule. */
@WithoutMojo
@Test
public void testSomethingWhichDoesNotNeedTheMojoAndProbablyShouldBeExtractedIntoANewClassOfItsOwn()
{
assertTrue( true );
}
}