You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2018/02/14 20:11:09 UTC

[maven-artifact-transfer] branch MSHARED-680 created (now 3507d81)

This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a change to branch MSHARED-680
in repository https://gitbox.apache.org/repos/asf/maven-artifact-transfer.git.


      at 3507d81  [MSHARED-680] - Add null check for DependencyResolver Interface

This branch includes the following new commits:

     new 3507d81  [MSHARED-680] - Add null check for DependencyResolver Interface

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


-- 
To stop receiving notification emails like this one, please contact
khmarbaise@apache.org.

[maven-artifact-transfer] 01/01: [MSHARED-680] - Add null check for DependencyResolver Interface

Posted by kh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a commit to branch MSHARED-680
in repository https://gitbox.apache.org/repos/asf/maven-artifact-transfer.git

commit 3507d8139bc0defb0da9aa932d9da23cff9aff2c
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Fri Feb 2 15:05:14 2018 +0100

    [MSHARED-680] - Add null check for DependencyResolver Interface
---
 .../internal/DefaultDependencyResolver.java        |  51 ++++++++-
 .../internal/DefaultDependencyResolverTest.java    | 118 +++++++++++++++++++++
 2 files changed, 164 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/dependencies/resolve/internal/DefaultDependencyResolver.java b/src/main/java/org/apache/maven/shared/dependencies/resolve/internal/DefaultDependencyResolver.java
index a58a80a..4db1828 100644
--- a/src/main/java/org/apache/maven/shared/dependencies/resolve/internal/DefaultDependencyResolver.java
+++ b/src/main/java/org/apache/maven/shared/dependencies/resolve/internal/DefaultDependencyResolver.java
@@ -51,7 +51,7 @@ public class DefaultDependencyResolver
                                                          Collection<Dependency> coordinates,
                                                          Collection<Dependency> managedDependencies,
                                                          TransformableFilter filter )
-                                                             throws DependencyResolverException
+        throws DependencyResolverException
     {
         try
         {
@@ -70,8 +70,9 @@ public class DefaultDependencyResolver
     @Override
     public Iterable<ArtifactResult> resolveDependencies( ProjectBuildingRequest buildingRequest,
                                                          DependableCoordinate coordinate, TransformableFilter filter )
-                                                             throws DependencyResolverException
+        throws DependencyResolverException
     {
+        validateParameters( buildingRequest, coordinate, filter );
         try
         {
             String hint = isMaven31() ? "maven31" : "maven3";
@@ -85,12 +86,13 @@ public class DefaultDependencyResolver
             throw new DependencyResolverException( e.getMessage(), e );
         }
     }
-    
+
     @Override
-    public Iterable<ArtifactResult> resolveDependencies( ProjectBuildingRequest buildingRequest,
-                                                         Model model, TransformableFilter filter )
+    public Iterable<ArtifactResult> resolveDependencies( ProjectBuildingRequest buildingRequest, Model model,
+                                                         TransformableFilter filter )
         throws DependencyResolverException
     {
+        validateParameters( buildingRequest, model, filter );
         try
         {
             String hint = isMaven31() ? "maven31" : "maven3";
@@ -138,4 +140,43 @@ public class DefaultDependencyResolver
     {
         container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
     }
+
+    private void validateParameters( ProjectBuildingRequest buildingRequest, DependableCoordinate coordinate,
+                                     TransformableFilter filter )
+    {
+        validateBuildingRequest( buildingRequest );
+        if ( coordinate == null )
+        {
+            throw new IllegalArgumentException( "The parameter coordinate is not allowed to be null." );
+        }
+        if ( filter == null )
+        {
+            throw new IllegalArgumentException( "The parameter filter is not allowed to be null." );
+        }
+
+    }
+
+    private void validateParameters( ProjectBuildingRequest buildingRequest, Model model,
+                                     TransformableFilter filter )
+    {
+        validateBuildingRequest( buildingRequest );
+        if ( model == null )
+        {
+            throw new IllegalArgumentException( "The parameter model is not allowed to be null." );
+        }
+        if ( filter == null )
+        {
+            throw new IllegalArgumentException( "The parameter filter is not allowed to be null." );
+        }
+
+    }
+
+    private void validateBuildingRequest( ProjectBuildingRequest buildingRequest )
+    {
+        if ( buildingRequest == null )
+        {
+            throw new IllegalArgumentException( "The parameter buildingRequest is not allowed to be null." );
+        }
+    }
+
 }
diff --git a/src/test/java/org/apache/maven/shared/dependencies/resolve/internal/DefaultDependencyResolverTest.java b/src/test/java/org/apache/maven/shared/dependencies/resolve/internal/DefaultDependencyResolverTest.java
new file mode 100644
index 0000000..2a512ac
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/dependencies/resolve/internal/DefaultDependencyResolverTest.java
@@ -0,0 +1,118 @@
+package org.apache.maven.shared.dependencies.resolve.internal;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.mockito.Mockito.mock;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.dependencies.DependableCoordinate;
+import org.apache.maven.shared.dependencies.resolve.DependencyResolver;
+import org.apache.maven.shared.dependencies.resolve.DependencyResolverException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Check the parameter contracts which have been made based on the interface {@link DependencyResolver}.
+ * 
+ * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmabaise@apache.org</a>
+ */
+public class DefaultDependencyResolverTest
+{
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    private DependencyResolver dr;
+
+    @Before
+    public void setUp()
+    {
+        dr = new DefaultDependencyResolver();
+    }
+
+    @Test
+    public void resolveDependenciesWithDependableCoordinatShouldFailWithIAEWhenParameterBuildingRequestIsNull()
+        throws DependencyResolverException
+    {
+        thrown.expect( IllegalArgumentException.class );
+        thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." );
+
+        dr.resolveDependencies( null, (DependableCoordinate) null, null );
+    }
+
+    @Test
+    public void resolveDependenciesWithDependableCoordinatShouldFailWithIAEWhenParameterCoordinateIsNull()
+        throws DependencyResolverException
+    {
+        thrown.expect( IllegalArgumentException.class );
+        thrown.expectMessage( "The parameter coordinate is not allowed to be null." );
+
+        ProjectBuildingRequest request = mock( ProjectBuildingRequest.class );
+        dr.resolveDependencies( request, (DependableCoordinate) null, null );
+    }
+
+    @Test
+    public void resolveDependenciesWithDependableCoordinatShouldFailWithIAEWhenParameterFilterIsNull()
+        throws DependencyResolverException
+    {
+        thrown.expect( IllegalArgumentException.class );
+        thrown.expectMessage( "The parameter filter is not allowed to be null." );
+
+        ProjectBuildingRequest request = mock( ProjectBuildingRequest.class );
+        DependableCoordinate dc = mock( DependableCoordinate.class );
+        dr.resolveDependencies( request, dc, null );
+    }
+
+    @Test
+    public void resolveDependenciesWithModelShouldFailWithIAEWhenParameterBuildingRequestIsNull()
+        throws DependencyResolverException
+    {
+        thrown.expect( IllegalArgumentException.class );
+        thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." );
+
+        dr.resolveDependencies( null, (Model) null, null );
+    }
+
+    @Test
+    public void resolveDependenciesWithModelShouldFailWithIAEWhenParameterModelIsNull()
+        throws DependencyResolverException
+    {
+        thrown.expect( IllegalArgumentException.class );
+        thrown.expectMessage( "The parameter model is not allowed to be null." );
+
+        ProjectBuildingRequest request = mock( ProjectBuildingRequest.class );
+        dr.resolveDependencies( request, (Model) null, null );
+    }
+
+    @Test
+    public void resolveDependenciesWithModelShouldFailWithIAEWhenParameterFilterIsNull()
+        throws DependencyResolverException
+    {
+        thrown.expect( IllegalArgumentException.class );
+        thrown.expectMessage( "The parameter filter is not allowed to be null." );
+
+        ProjectBuildingRequest request = mock( ProjectBuildingRequest.class );
+        Model model = mock( Model.class );
+        dr.resolveDependencies( request, model, null );
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
khmarbaise@apache.org.