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);
    }
}

@@ -41,43 +41,76 @@
 ort 
-org.apache.maven.artifact.Artifact;
+javax.xml.stream.XMLStreamException;%0A%0Aimport java.util.Collections;%0A
 %0Aimp
@@ -143,24 +143,16 @@
 act.
-factory.
 Artifact
 Fact
@@ -147,23 +147,16 @@
 Artifact
-Factory
 ;%0Aimport
@@ -495,143 +495,73 @@
 org.
-junit.Test;%0A%0Aimport javax.xml.stream.XMLStreamException;%0Aimport java.util.Collections;%0A%0Aimport static org.mockito.ArgumentMatchers.any;
+apache.maven.repository.RepositorySystem;%0Aimport org.junit.Test;%0A
 %0Aimp
@@ -603,22 +603,16 @@
 hers.any
-String
 ;%0Aimport
@@ -719,17 +719,17 @@
 MojoTest
- 
+%0A
 %7B%0A%0A    @
@@ -849,16 +849,20 @@
 xception
+%0A   
  %7B%0A     
@@ -910,16 +910,24 @@
 ntMojo()
+%0A       
  %7B%0A     
@@ -1015,16 +1015,17 @@
 tParent(
+ 
 new Mave
@@ -1034,16 +1034,17 @@
 roject()
+ 
 );%0A     
@@ -1154,52 +1154,56 @@
     
-artifactFactory = mock(ArtifactFactory
+repositorySystem = mock( RepositorySystem
 .class
+ 
 );%0A 
@@ -1226,23 +1226,25 @@
 hen(
-artifactFactory
+ repositorySystem
 .cre
@@ -1269,121 +1269,17 @@
 act(
-anyString(), anyString(), any(VersionRange.class),%0A                        anyString(), anyString(), anyString())
+ any() ) 
 )%0A  
@@ -1296,20 +1296,16 @@
         
-    
 .thenRet
@@ -1308,16 +1308,17 @@
 nReturn(
+ 
 new Proj
@@ -1333,16 +1333,19 @@
 act(
+ 
 project
-)
+ ) 
 );%0A 
@@ -1414,16 +1414,17 @@
 Version(
+ 
 Artifact
@@ -1517,16 +1517,17 @@
         
+ 
 Boolean 
@@ -1574,17 +1574,30 @@
 sitories
-)
+ )%0A           
  %7B%0A     
@@ -1665,20 +1665,22 @@
 .update(
+ 
 null
+ 
 );%0A    %7D

Fix test after #624