/
SetMojoTest.java
95 lines (87 loc) · 3.08 KB
/
SetMojoTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package org.codehaus.mojo.versions;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.versions.utils.BaseMojoTestCase;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
public class SetMojoTest extends BaseMojoTestCase
{
public void testGetIncrementedVersion() throws MojoExecutionException
{
new SetMojo()
{
{
assertThat( getIncrementedVersion( "1.0.0", null ), is( "1.0.1-SNAPSHOT" ) );
assertThat( getIncrementedVersion( "1.0.0-SNAPSHOT", null ), is( "1.0.1-SNAPSHOT" ) );
assertThat( getIncrementedVersion( "1.0.0-SNAPSHOT", 1 ), is( "2.0.0-SNAPSHOT" ) );
assertThat( getIncrementedVersion( "1.0.0-SNAPSHOT", 2 ), is( "1.1.0-SNAPSHOT" ) );
assertThat( getIncrementedVersion( "1.0.0-SNAPSHOT", 3 ), is( "1.0.1-SNAPSHOT" ) );
}
};
}
public void testNextSnapshotIndexLowerBound()
{
new SetMojo()
{
{
try
{
getIncrementedVersion( "1.0.0", 0 );
fail();
}
catch ( MojoExecutionException e )
{
assertThat( e.getMessage(),
containsString( "nextSnapshotIndexToIncrement cannot be less than 1" ) );
}
}
};
}
public void testNextSnapshotIndexUpperBound()
{
new SetMojo()
{
{
try
{
getIncrementedVersion( "1.0.0", 4 );
fail();
}
catch ( MojoExecutionException e )
{
assertThat( e.getMessage(), containsString(
"nextSnapshotIndexToIncrement cannot be greater than the last version index" ) );
}
}
};
}
public void testNextSnapshotIndexWithoutNextSnapshot() throws MojoFailureException
{
try
{
new SetMojo()
{
{
project = new MavenProject();
project.setParent( new MavenProject() );
project.setOriginalModel( new Model() );
project.getOriginalModel().setVersion( "1.2.3-SNAPSHOT" );
nextSnapshotIndexToIncrement = 4;
}
}.execute();
}
catch ( MojoExecutionException e )
{
assertThat( e.getMessage(),
containsString( "nextSnapshotIndexToIncrement is not valid when nextSnapshot is false" ) );
}
}
public void testVersionlessDependency() throws Exception
{
SetMojo myMojo = createMojo( "set", "src/test/resources/org/codehaus/mojo/set/versionless-01/pom.xml" );
myMojo.execute();
}
}