// Path: phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/Archive.java
// public interface Archive {
//   String getUrl();
//   String getExtension();
// 	String getArchiveName();
// 	String getPathToExecutable();
// 	String getVersion();
// 	String getClassifier();
// }
// 
// Path: phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/resolve/RepositoryDetails.java
// public class RepositoryDetails {
// 
//   private final RepositorySystem repositorySystem;
//   private final RepositorySystemSession repositorySystemSession;
//   private final List<RemoteRepository> remoteRepositories;
// 
//   public RepositoryDetails(RepositorySystem repositorySystem,
//                            RepositorySystemSession repositorySystemSession,
//                            List<RemoteRepository> remoteRepositories) {
//     this.repositorySystem = repositorySystem;
//     this.repositorySystemSession = repositorySystemSession;
//     this.remoteRepositories = remoteRepositories;
//   }
// 
//   public RepositorySystem getRepositorySystem() {
//     return repositorySystem;
//   }
// 
//   public RepositorySystemSession getRepositorySystemSession() {
//     return repositorySystemSession;
//   }
// 
//   public List<RemoteRepository> getRemoteRepositories() {
//     return remoteRepositories;
//   }
// 
// }
// 
// Path: phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/util/ArtifactBuilder.java
// @Named
// public class ArtifactBuilder {
// 
//   public static final String GROUP_ID = "com.github.klieber";
//   public static final String ARTIFACT_ID = "phantomjs";
// 
//   public Artifact createArtifact(String groupId, String artifactId, Archive archive) {
//     return new DefaultArtifact(
//         groupId,
//         artifactId,
//         archive.getClassifier(),
//         archive.getExtension(),
//         archive.getVersion()
//     );
//   }
// 
//   public Artifact createArtifact(Archive archive) {
//     return createArtifact(GROUP_ID, ARTIFACT_ID, archive);
//   }
// }


import com.github.klieber.phantomjs.archive.Archive;
import com.github.klieber.phantomjs.resolve.RepositoryDetails;
import com.github.klieber.phantomjs.util.ArtifactBuilder;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.when;
  private RepositoryDownloader repositoryDownloader;

  @Before
  public void before() {
    artifactResult = new ArtifactResult(new ArtifactRequest());
    artifactResult.setArtifact(artifact);

    when(repositoryDetails.getRepositorySystem()).thenReturn(repositorySystem);
    when(repositoryDetails.getRemoteRepositories()).thenReturn(remoteRepositories);
    when(repositoryDetails.getRepositorySystemSession()).thenReturn(repositorySystemSession);
  }

  @Test
  public void shouldDownload() throws DownloadException, ArtifactResolutionException {
    when(artifactBuilder.createArtifact(archive)).thenReturn(artifact);
    when(repositorySystem.resolveArtifact(same(repositorySystemSession), artifactRequestCaptor.capture())).thenReturn(
      artifactResult);
    when(artifact.getFile()).thenReturn(archiveFile);

    assertThat(repositoryDownloader.download(archive)).isSameAs(archiveFile);

    ArtifactRequest request = artifactRequestCaptor.getValue();
    assertThat(request.getArtifact()).isSameAs(artifact);
    assertThat(request.getRepositories()).isSameAs(remoteRepositories);
  }

  @Test
  public void shouldHandleArtifactResolutionException() throws DownloadException, ArtifactResolutionException {
    when(artifactBuilder.createArtifact(archive)).thenReturn(artifact);
    when(repositorySystem.resolveArtifact(
// Path: phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/archive/Archive.java
// public interface Archive {
//   String getUrl();
//   String getExtension();
// 	String getArchiveName();
// 	String getPathToExecutable();
// 	String getVersion();
// 	String getClassifier();
// }
// 
// Path: phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/resolve/RepositoryDetails.java
// public class RepositoryDetails {
// 
//   private final RepositorySystem repositorySystem;
//   private final RepositorySystemSession repositorySystemSession;
//   private final List<RemoteRepository> remoteRepositories;
// 
//   public RepositoryDetails(RepositorySystem repositorySystem,
//                            RepositorySystemSession repositorySystemSession,
//                            List<RemoteRepository> remoteRepositories) {
//     this.repositorySystem = repositorySystem;
//     this.repositorySystemSession = repositorySystemSession;
//     this.remoteRepositories = remoteRepositories;
//   }
// 
//   public RepositorySystem getRepositorySystem() {
//     return repositorySystem;
//   }
// 
//   public RepositorySystemSession getRepositorySystemSession() {
//     return repositorySystemSession;
//   }
// 
//   public List<RemoteRepository> getRemoteRepositories() {
//     return remoteRepositories;
//   }
// 
// }
// 
// Path: phantomjs-maven-core/src/main/java/com/github/klieber/phantomjs/util/ArtifactBuilder.java
// @Named
// public class ArtifactBuilder {
// 
//   public static final String GROUP_ID = "com.github.klieber";
//   public static final String ARTIFACT_ID = "phantomjs";
// 
//   public Artifact createArtifact(String groupId, String artifactId, Archive archive) {
//     return new DefaultArtifact(
//         groupId,
//         artifactId,
//         archive.getClassifier(),
//         archive.getExtension(),
//         archive.getVersion()
//     );
//   }
// 
//   public Artifact createArtifact(Archive archive) {
//     return createArtifact(GROUP_ID, ARTIFACT_ID, archive);
//   }
// }


// Path: phantomjs-maven-core/src/test/java/com/github/klieber/phantomjs/download/RepositoryDownloaderTest.java
import com.github.klieber.phantomjs.archive.Archive;
import com.github.klieber.phantomjs.resolve.RepositoryDetails;
import com.github.klieber.phantomjs.util.ArtifactBuilder;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.when;

  private RepositoryDownloader repositoryDownloader;

  @Before
  public void before() {
    artifactResult = new ArtifactResult(new ArtifactRequest());
    artifactResult.setArtifact(artifact);

    when(repositoryDetails.getRepositorySystem()).thenReturn(repositorySystem);
    when(repositoryDetails.getRemoteRepositories()).thenReturn(remoteRepositories);
    when(repositoryDetails.getRepositorySystemSession()).thenReturn(repositorySystemSession);
  }

  @Test
  public void shouldDownload() throws DownloadException, ArtifactResolutionException {
    when(artifactBuilder.createArtifact(archive)).thenReturn(artifact);
    when(repositorySystem.resolveArtifact(same(repositorySystemSession), artifactRequestCaptor.capture())).thenReturn(
      artifactResult);
    when(artifact.getFile()).thenReturn(archiveFile);

    assertThat(repositoryDownloader.download(archive)).isSameAs(archiveFile);

    ArtifactRequest request = artifactRequestCaptor.getValue();
    assertThat(request.getArtifact()).isSameAs(artifact);
    assertThat(request.getRepositories()).isSameAs(remoteRepositories);
  }

  @Test
  public void shouldHandleArtifactResolutionException() throws DownloadException, ArtifactResolutionException {
    when(artifactBuilder.createArtifact(archive)).thenReturn(artifact);
    when(repositorySystem.resolveArtifact(
      same(repositorySystemSession),