View Javadoc
1   package org.apache.maven.shared.transfer.artifact.resolve.internal;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.mockito.Mockito.mock;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.project.ProjectBuildingRequest;
26  import org.apache.maven.shared.transfer.artifact.ArtifactCoordinate;
27  import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
28  import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
29  import org.junit.Before;
30  import org.junit.Rule;
31  import org.junit.Test;
32  import org.junit.rules.ExpectedException;
33  
34  /**
35   * Check the parameter contracts which have been made based on the interface {@link ArtifactResolver}.
36   * 
37   * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmabaise@apache.org</a>
38   */
39  public class DefaultArtifactResolverTest
40  {
41  
42      @Rule
43      public ExpectedException thrown = ExpectedException.none();
44  
45      private ArtifactResolver dap;
46  
47      @Before
48      public void setUp()
49      {
50          dap = new DefaultArtifactResolver();
51      }
52  
53      @Test
54      public void resolveArtifactWithArtifactShouldFaileWithIAEWhenParameterBuildingRequestIsNull()
55          throws ArtifactResolverException
56      {
57          thrown.expect( IllegalArgumentException.class );
58          thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." );
59  
60          dap.resolveArtifact( null, (Artifact) null );
61      }
62  
63      @Test
64      public void resolveArtifactWithArtifactShouldFaileWithIAEWhenArtifactIsNull()
65          throws ArtifactResolverException
66      {
67          thrown.expect( IllegalArgumentException.class );
68          thrown.expectMessage( "The parameter mavenArtifact is not allowed to be null." );
69  
70          ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
71  
72          dap.resolveArtifact( pbr, (Artifact) null );
73      }
74  
75      @Test
76      public void resolveArtifactWithCoordinateShouldFaileWithIAEWhenParameterBuildingRequestIsNull()
77          throws ArtifactResolverException
78      {
79          thrown.expect( IllegalArgumentException.class );
80          thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." );
81  
82          dap.resolveArtifact( null, (ArtifactCoordinate) null );
83      }
84  
85      @Test
86      public void resolveArtifactWithCoordinateShouldFaileWithIAEWhenArtifactIsNull()
87          throws ArtifactResolverException
88      {
89          thrown.expect( IllegalArgumentException.class );
90          thrown.expectMessage( "The parameter coordinate is not allowed to be null." );
91  
92          ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
93  
94          dap.resolveArtifact( pbr, (ArtifactCoordinate) null );
95      }
96  
97  }