Class MojoExtension
java.lang.Object
org.apache.maven.api.di.testing.MavenDIExtension
org.apache.maven.api.plugin.testing.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,- org.junit.jupiter.api.extension.TestInstantiationAwareExtension
public class MojoExtension
extends MavenDIExtension
implements org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.BeforeEachCallback
JUnit extension to help testing Mojos. The extension should be automatically registered
 by adding the 
MojoTest annotation on the test class.- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtensionorg.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope
- 
Field SummaryFieldsFields inherited from class org.apache.maven.api.di.testing.MavenDIExtensioncontext, injector
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) static org.apache.maven.api.xml.XmlNodeextractPluginConfiguration(String artifactId, org.codehaus.plexus.util.xml.Xpp3Dom pomDom) static Stringstatic Stringprotected Stringstatic StringgetVariablesAndValuesFromObject(Class<?> clazz, Object 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.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 ObjectgetVariableValueFromObject(Object object, String variable) Convenience method to obtain the value of a variable on a mojo that might not have a getter.protected String[]mojoCoordinates(String goal) resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) static voidsetVariableValueToObject(Object object, String variable, Object value) Convenience method to set values to variables in objects that don't have settersbooleansupportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) Methods inherited from class org.apache.maven.api.di.testing.MavenDIExtensionafterEach, getInjector, getTestFile, getTestFile, getTestPath, getTestPath, lookup, lookup, lookup, release, setContext, setupContainerMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtensiongetTestInstantiationExtensionContextScope
- 
Field Details- 
pluginBasedir
- 
basedir
 
- 
- 
Constructor Details- 
MojoExtensionpublic MojoExtension()
 
- 
- 
Method Details- 
getTestId
- 
getBasedir
- 
getPluginBasedir
- 
supportsParameterpublic 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:
- supportsParameterin interface- org.junit.jupiter.api.extension.ParameterResolver
- Throws:
- org.junit.jupiter.api.extension.ParameterResolutionException
 
- 
resolveParameterpublic 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:
- resolveParameterin interface- org.junit.jupiter.api.extension.ParameterResolver
- Throws:
- org.junit.jupiter.api.extension.ParameterResolutionException
 
- 
beforeEach- Specified by:
- beforeEachin interface- org.junit.jupiter.api.extension.BeforeEachCallback
- Overrides:
- beforeEachin class- MavenDIExtension
- Throws:
- Exception
 
- 
getPluginDescriptorLocation
- 
mojoCoordinates- Throws:
- Exception
 
- 
extractPluginConfigurationpublic static org.apache.maven.api.xml.XmlNode extractPluginConfiguration(String artifactId, org.codehaus.plexus.util.xml.Xpp3Dom pomDom) throws Exception - Throws:
- Exception
 
- 
getVariableValueFromObjectpublic 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
 
- 
getVariablesAndValuesFromObjectpublic 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
 
- 
getVariablesAndValuesFromObjectpublic 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
 
- 
setVariableValueToObjectpublic 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
 
 
-