下面列出了怎么用org.apache.maven.plugin.testing.stubs.MavenProjectStub的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Main can print a simple text.
* @throws Exception If some problem inside
*/
public void testSimpleCompilation() throws Exception {
final CompileMojo mojo = new CompileMojo();
this.temp.create();
final File src = this.temp.newFolder();
this.setVariableValueToObject(mojo, "sourceDirectory", src);
new LengthOf(
new TeeInput(
new InputOf(
"type Pixel:\n Pixel moveTo(Integer x, Integer y)"
),
new OutputTo(new File(src, "main.eo"))
)
).value();
final File target = this.temp.newFolder();
this.setVariableValueToObject(mojo, "targetDirectory", target);
this.setVariableValueToObject(mojo, "project", new MavenProjectStub());
mojo.execute();
MatcherAssert.assertThat(
new File(target, "Pixel.java").exists(),
Matchers.is(true)
);
}
@Test
public void testGenerateCode() throws Exception {
File pom = getTestFile("src/test/resources/properties-pom.xml");
assertNotNull(pom);
assertTrue(pom.exists());
DslPlatformMojo mojo = (DslPlatformMojo) lookupMojo(DslPlatformMojo.GOAL, pom);
assertNotNull(mojo);
mojo.setProject(new MavenProjectStub());
mojo.execute();
File tempPath = TempPath.getTempProjectPath(mojo.getContext());
String sourcesPath = tempPath.getAbsolutePath() + "/JAVA_POJO";
TestUtils.assertDir(sourcesPath);
TestUtils.assertDir(sourcesPath + "/DslPlatformMojoTestModule");
TestUtils.assertFile(sourcesPath + "/DslPlatformMojoTestModule/Guards.java");
TestUtils.assertFile(sourcesPath + "/DslPlatformMojoTestModule/DslPlatformMojoTestAggregate.java");
}
@Test
public void testGenerateCode() throws Exception {
File pom = getTestFile("src/test/resources/generate-code-pom.xml");
assertNotNull(pom);
assertTrue(pom.exists());
GenerateCodeMojo mojo = (GenerateCodeMojo) lookupMojo(GenerateCodeMojo.GOAL, pom);
assertNotNull(mojo);
mojo.setProject(new MavenProjectStub());
mojo.execute();
String sourcesPath = mojo.getGeneratedSources();
TestUtils.assertDir(sourcesPath);
TestUtils.assertDir(sourcesPath + "/MojoTestModule");
TestUtils.assertFile(sourcesPath + "/MojoTestModule/Guards.java");
TestUtils.assertFile(sourcesPath + "/MojoTestModule/MojoTestAggregate.java");
String[] settings = mojo.getOptions();
assertEquals(null, settings);
}
@Before
public void setup() {
sut = new Publisher();
MockitoAnnotations.initMocks(this);
AxwayPublishingAdapter.cleanInstance();
when(sut.getLog()).thenReturn(log);
when(sut.getPublicationReader()).thenReturn(publicationReader);
when(sut.getAxwayPublishingAdapter()).thenReturn(axwayPublishingAdapter);
when(sut.getStageConfigurationFile()).thenReturn("");
when(sut.getProject()).thenReturn(new MavenProjectStub());
}
public void setUp()
throws Exception
{
super.setUp();
p = new Properties();
p.load( getClass().getResourceAsStream( "/test.properties" ) );
mojo = new SqlExecMojo();
// populate parameters
mojo.setDriver( p.getProperty( "driver" ) );
mojo.setUsername( p.getProperty( "user" ) );
mojo.setPassword( p.getProperty( "password" ) );
mojo.setUrl( p.getProperty( "url" ) );
mojo.setDriverProperties( p.getProperty( "driverProperties" ) );
mojo.setSqlCommand( null );
mojo.setDelimiter( SqlExecMojo.DEFAULT_DELIMITER );// This will simulate the defaultValue of @Parameter (...)
mojo.setOnError( SqlExecMojo.ON_ERROR_ABORT );
mojo.setDelimiterType( DelimiterType.NORMAL );
mojo.setEscapeProcessing( true );
MavenFileFilter filter =
(MavenFileFilter) lookup( "org.apache.maven.shared.filtering.MavenFileFilter", "default" );
mojo.setFileFilter( filter );
SecDispatcher securityDispatcher =
(SecDispatcher) lookup( "org.sonatype.plexus.components.sec.dispatcher.SecDispatcher", "default" );
mojo.setSecurityDispatcher( securityDispatcher );
MavenProject project = new MavenProjectStub();
setVariableValueToObject( mojo, "project", project );
}
protected Mojo lookupAndPrepareMojo( String artifactId, File testPom )
throws Exception
{
Mojo mojo = lookupMojo( artifactId, testPom );
MavenProject mavenProject = new MavenProjectStub();
setVariableValueToObject( mojo, "project", mavenProject );
return mojo;
}
@Test
public void addsNoRepositoryIfThereAreNoCompileSourceRoots() throws MojoExecutionException {
MavenProjectStub mavenProject = new MavenProjectStub();
mavenProject.setCompileSourceRoots(null);
Iterable<Repository> repositories = objectUnderTest.getAdditionalRepositoriesFor(mavenProject);
assertThat(repositories, is(emptyIterable()));
}