Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 676 base mojo test case #695

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/test/java/org/codehaus/mojo/versions/SetMojoTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package org.codehaus.mojo.versions;

import java.io.File;

import org.apache.maven.model.Model;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.versions.utils.BaseMojoTestCase;
import org.junit.Rule;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

public class SetMojoTest extends BaseMojoTestCase
public class SetMojoTest extends AbstractMojoTestCase
{
@Rule
MojoRule mojoRule = new MojoRule( this );

@Test
public void testGetIncrementedVersion() throws MojoExecutionException
{
Expand Down Expand Up @@ -95,7 +102,8 @@ public void testNextSnapshotIndexWithoutNextSnapshot() throws MojoFailureExcepti
@Test
public void testVersionlessDependency() throws Exception
{
SetMojo myMojo = createMojo( "set", "src/test/resources/org/codehaus/mojo/set/versionless-01/pom.xml" );
SetMojo myMojo = (SetMojo) mojoRule.lookupConfiguredMojo(
new File( "target/test-classes/org/codehaus/mojo/set/versionless-01" ), "set" );
myMojo.execute();
}
}
77 changes: 57 additions & 20 deletions src/test/java/org/codehaus/mojo/versions/SetPropertyMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,71 @@
* under the License.
*/

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Objects;

import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.mojo.versions.utils.BaseMojoTestCase;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.matchesPattern;

/**
* Basic tests for {@linkplain SetPropertyMojoTest}.
*
* @author Andrzej Jarmoniuk
*/
public class SetPropertyMojoTest extends BaseMojoTestCase
public class SetPropertyMojoTest extends AbstractMojoTestCase
{
@Test
@Rule
MojoRule mojoRule = new MojoRule( this );

private Path pomDir;

@Before
public void setUp() throws Exception
{
super.setUp();
pomDir = Files.createTempDirectory( "set-property-" );
}

@After
public void tearDown() throws Exception
{
try
{
if ( pomDir != null && pomDir.toFile().exists() )
{
Arrays.stream( Objects.requireNonNull( pomDir.toFile().listFiles() ) ).forEach( File::delete );
pomDir.toFile().delete();
}
}
finally
{
super.tearDown();
}
}
@Test
public void testNullNewVersion()
throws Exception
{
SetPropertyMojo mojo = createMojo( "set-property",
"target/test-classes/org/codehaus/mojo/set-property/pom.xml" );
assertThat( mojo.getProject().getProperties(), is( mojo.getProject().getModel().getProperties() ) );

setVariableValueToObject( mojo, "property", "dummy-api-version" );
Files.copy( Paths.get( "src/test/resources/org/codehaus/mojo/set-property/null-new-version/pom.xml" ),
Paths.get( pomDir.toString(), "pom.xml" ), REPLACE_EXISTING );
SetPropertyMojo mojo = (SetPropertyMojo) mojoRule.lookupConfiguredMojo( pomDir.toFile(),
"set-property" );
mojo.localRepository = new StubArtifactRepository( pomDir.toString() );
setVariableValueToObject( mojo, "newVersion", null );

mojo.execute();
Expand All @@ -60,11 +98,11 @@ public void testNullNewVersion()
public void testNewVersionEmpty()
throws Exception
{
SetPropertyMojo mojo = createMojo( "set-property",
"target/test-classes/org/codehaus/mojo/set-property/pom.xml" );
assertThat( mojo.getProject().getProperties(), is( mojo.getProject().getModel().getProperties() ) );

setVariableValueToObject( mojo, "property", "dummy-api-version" );
Files.copy( Paths.get( "src/test/resources/org/codehaus/mojo/set-property/null-new-version/pom.xml" ),
Paths.get( pomDir.toString(), "pom.xml" ), REPLACE_EXISTING );
SetPropertyMojo mojo = (SetPropertyMojo) mojoRule.lookupConfiguredMojo( pomDir.toFile(),
"set-property" );
mojo.localRepository = new StubArtifactRepository( pomDir.toString() );
setVariableValueToObject( mojo, "newVersion", "" );

mojo.execute();
Expand All @@ -79,15 +117,14 @@ public void testNewVersionEmpty()
public void testNullProperty()
throws Exception
{
SetPropertyMojo mojo = createMojo( "set-property",
"src/test/resources/org/codehaus/mojo/set-property/pom.xml" );
Files.copy( Paths.get( "src/test/resources/org/codehaus/mojo/set-property/null-property/pom.xml" ),
Paths.get( pomDir.toString(), "pom.xml" ), REPLACE_EXISTING );
SetPropertyMojo mojo = (SetPropertyMojo) mojoRule.lookupConfiguredMojo( pomDir.toFile(),
"set-property" );

setVariableValueToObject( mojo, "property", null );
setVariableValueToObject( mojo, "propertiesVersionsFile", null );
setVariableValueToObject( mojo, "newVersion", "2.0.0" );
try
{
mojo.execute();
mojo.update( null );
fail();
}
catch ( MojoExecutionException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,30 @@
* under the License.
*/

import java.io.File;
import java.util.Collections;

import org.codehaus.mojo.versions.utils.BaseMojoTestCase;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.MojoRule;
import org.junit.Rule;
import org.junit.Test;

/**
* Basic tests for {@linkplain UseDepVersionMojo}.
*
* @author Andrzej Jarmoniuk
*/
public class UseDepVersionMojoTest extends BaseMojoTestCase
public class UseDepVersionMojoTest extends AbstractMojoTestCase
{
@Rule
MojoRule mojoRule = new MojoRule( this );

@Test
public void testIssue673() throws Exception
{
UseDepVersionMojo mojo = createMojo( "use-dep-version",
"src/test/resources/org/codehaus/mojo/use-dep-version/issue-637-pom.xml" );
UseDepVersionMojo mojo = (UseDepVersionMojo) mojoRule.lookupConfiguredMojo(
new File( "target/test-classes/org/codehaus/mojo/use-dep-version/issue-637" ),
"use-dep-version" );
setVariableValueToObject( mojo, "processDependencies", true );
setVariableValueToObject( mojo, "processDependencyManagement", true );
setVariableValueToObject( mojo, "excludeReactor", true );
Expand Down
137 changes: 0 additions & 137 deletions src/test/java/org/codehaus/mojo/versions/utils/BaseMojoTestCase.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>default-group</groupId>
<artifactId>default-artifact</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<properties>
<dummy-api-version>1.0.0</dummy-api-version>
</properties>

<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>${dummy-api-version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<configuration>
<property>dummy-api-version</property>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<configuration/>
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<goals>
<goal>set</goal>
</goals>
<configuration>
<updateBuildOutputTimestampPolicy>onchange</updateBuildOutputTimestampPolicy>
<artifactId>dummy-api</artifactId>
<newVersion>2.0</newVersion>
</configuration>
Expand Down
Loading