Class MojoTestRule<P extends org.nuiton.plugin.AbstractPlugin>

java.lang.Object
org.apache.maven.plugin.testing.MojoRule
org.nuiton.plugin.MojoTestRule<P>
All Implemented Interfaces:
org.junit.rules.TestRule

public class MojoTestRule<P extends org.nuiton.plugin.AbstractPlugin> extends org.apache.maven.plugin.testing.MojoRule
TODO Review this documentation. To offer inside each test method (annotated by a Test) the following properties :
  • testDirectory : location where to find resources for the test
  • pomFile : location of the pom file to use to build the mojo
  • mojo : the instanciated and initialized mojo
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    MojoTestRule(Class<?> testClass, String goalName)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    org.junit.runners.model.Statement
    apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
     
    protected void
     
    protected P
    createMojo(File pomFile, String goalName)
     
     
     
    protected File
    getPomFile(File testDir, String methodName)
    Obtain the location of the pom file to use for next mojo test.
     
    protected File
    getTestDir(String methodName)
    Obtain the location of the directory where to find resources for the next test.
     
    boolean
    initMojo(P mojo)
     
    static <P extends org.nuiton.plugin.AbstractPlugin>
    MojoTestRule<P>
    newRule(Class<?> testClass, String goalName)
     
    protected void
    setUpMojo(P mojo, File pomFile)
    Initialize the given mojo.
    protected void
     

    Methods inherited from class org.apache.maven.plugin.testing.MojoRule

    configureMojo, configureMojo, executeMojo, executeMojo, executeMojo, executeMojo, extractPluginConfiguration, extractPluginConfiguration, getContainer, getPluginDescriptorLocation, getPluginDescriptorPath, getPublicDescriptorStream, getVariablesAndValuesFromObject, getVariablesAndValuesFromObject, getVariableValueFromObject, lookup, lookupConfiguredMojo, lookupConfiguredMojo, lookupConfiguredMojo, lookupEmptyMojo, lookupEmptyMojo, lookupMojo, lookupMojo, lookupMojo, newMavenSession, newMojoExecution, readMavenProject, setupContainer, setupContainerConfiguration, setVariableValueToObject

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MojoTestRule

      protected MojoTestRule(Class<?> testClass, String goalName)
  • Method Details

    • newRule

      public static <P extends org.nuiton.plugin.AbstractPlugin> MojoTestRule<P> newRule(Class<?> testClass, String goalName)
    • apply

      public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
      Specified by:
      apply in interface org.junit.rules.TestRule
      Overrides:
      apply in class org.apache.maven.plugin.testing.MojoRule
    • createMojo

      protected P createMojo(File pomFile, String goalName) throws Exception
      Throws:
      Exception
    • setUpMojo

      protected void setUpMojo(P mojo, File pomFile) throws Exception
      Initialize the given mojo.
      Parameters:
      mojo - the instanciate mojo
      pomFile - the pom file used to instanciate the mojo
      Throws:
      Exception - if any pb
    • initMojo

      public boolean initMojo(P mojo)
    • tearDownMojo

      protected void tearDownMojo(P mojo)
    • before

      protected void before() throws Throwable
      Overrides:
      before in class org.apache.maven.plugin.testing.MojoRule
      Throws:
      Throwable
    • after

      protected void after()
      Overrides:
      after in class org.apache.maven.plugin.testing.MojoRule
    • getMojo

      public P getMojo()
    • getPomFile

      public File getPomFile()
    • getTestDirectory

      public File getTestDirectory()
    • getTestDir

      protected File getTestDir(String methodName)
      Obtain the location of the directory where to find resources for the next test. By convention, will be the package named by the test class name from the TestHelper.getTestBasedir().
      Parameters:
      methodName - the method of the next test to execute
      Returns:
      the directory where to find resources for the test
    • getPomFile

      protected File getPomFile(File testDir, String methodName)
      Obtain the location of the pom file to use for next mojo test. By default, the pom file is the file with name methodName+".xml" in the testDir.
      Parameters:
      testDir - the location of resources for the next test (is the result of the method getTestDir(String).
      methodName - the name of the next test
      Returns:
      the location of the pom file for the next mojo test.
    • getRelativePathFromBasedir

      public String getRelativePathFromBasedir(File f)