Skip to content

Commit

Permalink
Fixing mojohaus#670: allowSnapshots was disabled in PR mojohaus#665
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 committed Sep 6, 2022
1 parent e3beb05 commit 4cfb878
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected void update( ModifiedPomXMLEventReader pom )
ArtifactVersion artifactVersion;
try
{
artifactVersion = findLatestVersion( artifact, versionRange, false, true,
artifactVersion = findLatestVersion( artifact, versionRange, allowSnapshots, true,
allowDowngrade );
}
catch ( ArtifactMetadataRetrievalException e )
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ private static ArtifactMetadataSource mockArtifactMetaDataSource() throws Artifa
new DefaultArtifactVersion( "1.0.0" ),
new DefaultArtifactVersion( "0.9.0" ) );
}
else if ( "issue-670-artifact".equals( artifact.getArtifactId() ) )
{
return Arrays.asList( new DefaultArtifactVersion( "0.0.1-1" ),
new DefaultArtifactVersion( "0.0.1-1-impl-SNAPSHOT" ) );
}
else if ( "unknown-artifact".equals( artifact.getArtifactId() ) )
{
return Collections.emptyList();
Expand Down Expand Up @@ -236,4 +241,27 @@ public void testParentDowngradeForbiddenWithRange()
}
assertThat( changeRecorder.getChanges(), is( empty() ) );
}

@Test
public void testParentDowngradeForbiddenWithSnapshots()
throws MojoExecutionException, XMLStreamException, MojoFailureException
{
mojo.allowSnapshots = true;
mojo.getProject().setParent( new MavenProject()
{{
setGroupId( "default-group" );
setArtifactId( "issue-670-artifact" );
setVersion( "0.0.1-1" );
}} );

try ( MockedStatic<PomHelper> pomHelper = mockStatic( PomHelper.class ) )
{
pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), any() ) )
.thenReturn( true );
mojo.update( null );
}
assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group",
"issue-670-artifact", "0.0.1-1",
"0.0.1-1-impl-SNAPSHOT" ) ) );
}
}

0 comments on commit 4cfb878

Please sign in to comment.