maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From khmarba...@apache.org
Subject svn commit: r1805576 - in /maven/shared/trunk/maven-artifact-transfer/src: main/java/org/apache/maven/shared/artifact/install/ main/java/org/apache/maven/shared/artifact/install/internal/ test/java/org/apache/maven/shared/artifact/install/internal/
Date Sun, 20 Aug 2017 18:39:48 GMT
Author: khmarbaise
Date: Sun Aug 20 18:39:47 2017
New Revision: 1805576

URL: http://svn.apache.org/viewvc?rev=1805576&view=rev
Log:
[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.

Modified:
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java
    maven/shared/trunk/maven-artifact-transfer/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java

Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java?rev=1805576&r1=1805575&r2=1805576&view=diff
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java
(original)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/ArtifactInstaller.java
Sun Aug 20 18:39:47 2017
@@ -35,6 +35,9 @@ public interface ArtifactInstaller
      * @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 @@ public interface ArtifactInstaller
      * @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;

Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java?rev=1805576&r1=1805575&r2=1805576&view=diff
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java
(original)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstaller.java
Sun Aug 20 18:39:47 2017
@@ -78,6 +78,8 @@ public class DefaultArtifactInstaller
             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 @@ public class DefaultArtifactInstaller
             throw new IllegalArgumentException( "The collection mavenArtifacts is not allowed
to be empty." );
         }
     }
-    
+
     /**
      * @return true if the current Maven version is Maven 3.1.
      */

Modified: maven/shared/trunk/maven-artifact-transfer/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java?rev=1805576&r1=1805575&r2=1805576&view=diff
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java
(original)
+++ maven/shared/trunk/maven-artifact-transfer/src/test/java/org/apache/maven/shared/artifact/install/internal/DefaultArtifactInstallerTest.java
Sun Aug 20 18:39:47 2017
@@ -20,12 +20,15 @@ package org.apache.maven.shared.artifact
  */
 
 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 @@ public class DefaultArtifactInstallerTes
         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 );
+    }
+
 }



Mime
View raw message