Class MojoExtension

java.lang.Object
org.codehaus.plexus.testing.PlexusExtension
org.apache.maven.plugin.testing.junit5.MojoExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.ParameterResolver

public class MojoExtension extends org.codehaus.plexus.testing.PlexusExtension implements org.junit.jupiter.api.extension.ParameterResolver
JUnit extension to help testing Mojos. The extension should be automatically registered by adding the MojoTest annotation on the test class.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
     
    static org.codehaus.plexus.util.xml.Xpp3Dom
    extractPluginConfiguration(String artifactId, org.codehaus.plexus.util.xml.Xpp3Dom pomDom)
     
    protected String
     
    static Map<String,Object>
    Convenience method to obtain all variables and values from the mojo (including its superclasses)
    Note: the values in the map are of type Object so the caller is responsible for casting to desired types.
    static Map<String,Object>
    Convenience method to obtain all variables and values from the mojo (including its superclasses)
    Note: the values in the map are of type Object so the caller is responsible for casting to desired types.
    static Object
    Convenience method to obtain the value of a variable on a mojo that might not have a getter.
    protected org.apache.maven.plugin.Mojo
    lookupMojo(String[] coord, org.codehaus.plexus.util.xml.Xpp3Dom pluginConfiguration, org.apache.maven.plugin.descriptor.PluginDescriptor descriptor)
    lookup the mojo while we have all the relevent information
    protected String[]
     
    resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     
    static void
    setVariableValueToObject(Object object, String variable, Object value)
    Convenience method to set values to variables in objects that don't have setters
    boolean
    supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     

    Methods inherited from class org.codehaus.plexus.testing.PlexusExtension

    afterEach, customizeComponentConfiguration, customizeContainerConfiguration, customizeContext, getBasedir, getClassLoader, getConfiguration, getConfiguration, getConfigurationName, getContainer, getCustomConfigurationName, getResourceAsStream, getTestConfiguration, getTestConfiguration, getTestFile, getTestFile, getTestPath, getTestPath, lookup, lookup, lookup, lookup, release, setupContainer

    Methods inherited from class java.lang.Object

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

    • MojoExtension

      public MojoExtension()
  • Method Details

    • supportsParameter

      public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
      Specified by:
      supportsParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException
    • resolveParameter

      public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
      Specified by:
      resolveParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException
    • beforeEach

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
      Overrides:
      beforeEach in class org.codehaus.plexus.testing.PlexusExtension
      Throws:
      Exception
    • getPluginDescriptorLocation

      protected String getPluginDescriptorLocation()
    • mojoCoordinates

      protected String[] mojoCoordinates(String goal) throws Exception
      Throws:
      Exception
    • lookupMojo

      protected org.apache.maven.plugin.Mojo lookupMojo(String[] coord, org.codehaus.plexus.util.xml.Xpp3Dom pluginConfiguration, org.apache.maven.plugin.descriptor.PluginDescriptor descriptor) throws Exception
      lookup the mojo while we have all the relevent information
      Throws:
      Exception
    • extractPluginConfiguration

      public static org.codehaus.plexus.util.xml.Xpp3Dom extractPluginConfiguration(String artifactId, org.codehaus.plexus.util.xml.Xpp3Dom pomDom) throws Exception
      Throws:
      Exception
    • getVariableValueFromObject

      public static Object getVariableValueFromObject(Object object, String variable) throws IllegalAccessException
      Convenience method to obtain the value of a variable on a mojo that might not have a getter.
      Note: the caller is responsible for casting to what the desired type is.
      Throws:
      IllegalAccessException
    • getVariablesAndValuesFromObject

      public static Map<String,Object> getVariablesAndValuesFromObject(Object object) throws IllegalAccessException
      Convenience method to obtain all variables and values from the mojo (including its superclasses)
      Note: the values in the map are of type Object so the caller is responsible for casting to desired types.
      Throws:
      IllegalAccessException
    • getVariablesAndValuesFromObject

      public static Map<String,Object> getVariablesAndValuesFromObject(Class<?> clazz, Object object) throws IllegalAccessException
      Convenience method to obtain all variables and values from the mojo (including its superclasses)
      Note: the values in the map are of type Object so the caller is responsible for casting to desired types.
      Returns:
      map of variable names and values
      Throws:
      IllegalAccessException
    • setVariableValueToObject

      public static void setVariableValueToObject(Object object, String variable, Object value) throws IllegalAccessException
      Convenience method to set values to variables in objects that don't have setters
      Throws:
      IllegalAccessException