[MSHARED-655] ArtifactInstaller check for integrity of parameters null, empty collection, being a directory
 o Followup added test for the second part of the interface.


git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1805576 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java b/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java
index 94e42ee..f9cadf2 100644
--- a/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java
+++ b/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java
@@ -35,6 +35,9 @@
      * @param request {@link ProjectBuildingRequest}
      * @param mavenArtifacts {@link Artifact}
      * @throws ArtifactInstallerException in case of an error.
+     * @throws IllegalArgumentException in case of parameter <code>request</code> is <code>null</code> or parameter
+     *             <code>mavenArtifacts</code> is <code>null</code> or <code>mavenArtifacts.isEmpty()</code> is
+     *             <code>true</code>.
      */
     void install( ProjectBuildingRequest request, Collection<Artifact> mavenArtifacts )
         throws ArtifactInstallerException;
@@ -45,6 +48,10 @@
      * @param mavenArtifacts Collection of {@link Artifact MavenArtifacts}
      * @throws ArtifactInstallerException In case of an error which can be the a given artifact can not be found or the
      *             installation has failed.
+     * @throws IllegalArgumentException in case of parameter <code>request</code> is <code>null</code> or parameter
+     *             <code>localRepository</code> is <code>null</code> or <code>localRepository</code> is not a directory
+     *             or parameter <code>mavenArtifacts</code> is <code>null</code> or
+     *             <code>mavenArtifacts.isEmpty()</code> is <code>true</code>.
      */
     void install( ProjectBuildingRequest request, File localRepository, Collection<Artifact> mavenArtifacts )
         throws ArtifactInstallerException;
diff --git a/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java b/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java
index 21d57bc..5d39501 100644
--- a/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java
+++ b/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java
@@ -78,6 +78,8 @@
             throw new IllegalArgumentException( "The parameter localRepository must be a directory." );
         }
 
+        // TODO: Should we check for exists() ?
+
         try
         {
             String hint = isMaven31() ? "maven31" : "maven3";
@@ -107,7 +109,7 @@
             throw new IllegalArgumentException( "The collection mavenArtifacts is not allowed to be empty." );
         }
     }
-    
+
     /**
      * @return true if the current Maven version is Maven 3.1.
      */
diff --git a/maven-artifact-transfer/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java b/maven-artifact-transfer/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java
index 59741e2..e5bef32 100644
--- a/maven-artifact-transfer/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java
+++ b/maven-artifact-transfer/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java
@@ -20,12 +20,15 @@
  */
 
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
+import java.io.File;
 import java.util.Collections;
+import java.util.List;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.project.ProjectBuildingRequest;
-
+import org.apache.maven.shared.artifact.install.ArtifactInstaller;
 import org.apache.maven.shared.artifact.install.ArtifactInstallerException;
 import org.junit.Rule;
 import org.junit.Test;
@@ -75,4 +78,60 @@
         ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
         dai.install( pbr, Collections.<Artifact>emptyList() );
     }
+
+    @Test
+    public void installWith3ParametersShouldReturnIllegalArgumentExceptionForFirstParameterWithNull()
+        throws ArtifactInstallerException
+    {
+        DefaultArtifactInstaller dai = new DefaultArtifactInstaller();
+
+        thrown.expect( IllegalArgumentException.class );
+        thrown.expectMessage( "The parameter request is not allowed to be null." );
+        File localRepository = mock( File.class );
+        dai.install( null, localRepository, Collections.<Artifact>emptyList() );
+    }
+
+    @Test
+    public void installWith3ParametersShouldReturnIllegalArgumentExceptionForSecondParameterWithNull()
+        throws ArtifactInstallerException
+    {
+        DefaultArtifactInstaller dai = new DefaultArtifactInstaller();
+
+        thrown.expect( IllegalArgumentException.class );
+        thrown.expectMessage( "The parameter localRepository is not allowed to be null." );
+
+        List<Artifact> singleEntryList = Collections.singletonList( mock( Artifact.class ) );
+        ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
+        dai.install( pbr, null, singleEntryList );
+    }
+
+    @Test
+    public void installWith3ParametersShouldReturnIllegalArgumentExceptionForSecondParameterNotADirectory()
+        throws ArtifactInstallerException
+    {
+        DefaultArtifactInstaller dai = new DefaultArtifactInstaller();
+
+        thrown.expect( IllegalArgumentException.class );
+        thrown.expectMessage( "The parameter mavenArtifacts is not allowed to be null." );
+        ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
+        List<Artifact> singleEntryList = Collections.singletonList( mock( Artifact.class ) );
+
+        File localRepository = mock( File.class );
+        when( localRepository.isDirectory() ).thenReturn( false );
+        dai.install( pbr, localRepository, singleEntryList );
+    }
+
+    @Test
+    public void installWith3ParametersShouldReturnIllegalArgumentExceptionForThirdParameterWithNull()
+        throws ArtifactInstallerException
+    {
+        DefaultArtifactInstaller dai = new DefaultArtifactInstaller();
+
+        thrown.expect( IllegalArgumentException.class );
+        thrown.expectMessage( "The parameter mavenArtifacts is not allowed to be null." );
+        ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
+        File localRepository = mock( File.class );
+        dai.install( pbr, localRepository, null );
+    }
+
 }