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

Reordering the checks in shouldApplyUpdate + a simple unit test #629

Merged
merged 1 commit into from
Aug 14, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -457,18 +457,18 @@ protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, A
{
getLog().debug( "Proposal is to update from " + currentVersion + " to " + updateVersion );

if ( forceUpdate )
{
getLog().info( "Force update enabled. LATEST or RELEASE versions will be overwritten with real version" );
return true;
}

if ( updateVersion == null )
{
getLog().warn( "Not updating version: could not resolve any versions" );
return false;
}

if ( forceUpdate )
{
getLog().info( "Force update enabled. LATEST or RELEASE versions will be overwritten with real version" );
return true;
}

artifact.setVersion( updateVersion.toString() );
try
{
Expand Down
45 changes: 45 additions & 0 deletions src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.codehaus.mojo.versions;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.ProjectArtifact;
import org.junit.Test;

import javax.xml.stream.XMLStreamException;
import java.util.Collections;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class UpdateParentMojoTest {

@Test
public void testArtifactIdDoesNotExist() throws MojoExecutionException, XMLStreamException, MojoFailureException {
UpdateParentMojo mojo = new UpdateParentMojo() {
{
project = new MavenProject();
project.setParent(new MavenProject());
reactorProjects = Collections.emptyList();
forceUpdate = true;

artifactFactory = mock(ArtifactFactory.class);
when(artifactFactory.createDependencyArtifact(anyString(), anyString(), any(VersionRange.class),
anyString(), anyString(), anyString()))
.thenReturn(new ProjectArtifact(project));
}

protected ArtifactVersion findLatestVersion(Artifact artifact, VersionRange versionRange,
Boolean allowingSnapshots, boolean usePluginRepositories) {
return null;
}
};
mojo.update(null);
}
}