View Javadoc
1   package org.apache.maven.shared.transfer.dependencies.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.model.Model;
25  import org.apache.maven.project.ProjectBuildingRequest;
26  import org.apache.maven.shared.transfer.dependencies.DependableCoordinate;
27  import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
28  import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException;
29  import org.apache.maven.shared.transfer.dependencies.resolve.internal.DefaultDependencyResolver;
30  import org.junit.Before;
31  import org.junit.Rule;
32  import org.junit.Test;
33  import org.junit.rules.ExpectedException;
34  
35  /**
36   * Check the parameter contracts which have been made based on the interface {@link DependencyResolver}.
37   * 
38   * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmabaise@apache.org</a>
39   */
40  public class DefaultDependencyResolverTest
41  {
42      @Rule
43      public ExpectedException thrown = ExpectedException.none();
44  
45      private DependencyResolver dr;
46  
47      @Before
48      public void setUp()
49      {
50          dr = new DefaultDependencyResolver();
51      }
52  
53      @Test
54      public void resolveDependenciesWithDependableCoordinatShouldFailWithIAEWhenParameterBuildingRequestIsNull()
55          throws DependencyResolverException
56      {
57          thrown.expect( IllegalArgumentException.class );
58          thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." );
59  
60          dr.resolveDependencies( null, (DependableCoordinate) null, null );
61      }
62  
63      @Test
64      public void resolveDependenciesWithDependableCoordinatShouldFailWithIAEWhenParameterCoordinateIsNull()
65          throws DependencyResolverException
66      {
67          thrown.expect( IllegalArgumentException.class );
68          thrown.expectMessage( "The parameter coordinate is not allowed to be null." );
69  
70          ProjectBuildingRequest request = mock( ProjectBuildingRequest.class );
71          dr.resolveDependencies( request, (DependableCoordinate) null, null );
72      }
73  
74      @Test
75      public void resolveDependenciesWithDependableCoordinatShouldFailWithIAEWhenParameterFilterIsNull()
76          throws DependencyResolverException
77      {
78          thrown.expect( IllegalArgumentException.class );
79          thrown.expectMessage( "The parameter filter is not allowed to be null." );
80  
81          ProjectBuildingRequest request = mock( ProjectBuildingRequest.class );
82          DependableCoordinate dc = mock( DependableCoordinate.class );
83          dr.resolveDependencies( request, dc, null );
84      }
85  
86      @Test
87      public void resolveDependenciesWithModelShouldFailWithIAEWhenParameterBuildingRequestIsNull()
88          throws DependencyResolverException
89      {
90          thrown.expect( IllegalArgumentException.class );
91          thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." );
92  
93          dr.resolveDependencies( null, (Model) null, null );
94      }
95  
96      @Test
97      public void resolveDependenciesWithModelShouldFailWithIAEWhenParameterModelIsNull()
98          throws DependencyResolverException
99      {
100         thrown.expect( IllegalArgumentException.class );
101         thrown.expectMessage( "The parameter model is not allowed to be null." );
102 
103         ProjectBuildingRequest request = mock( ProjectBuildingRequest.class );
104         dr.resolveDependencies( request, (Model) null, null );
105     }
106 
107     @Test
108     public void resolveDependenciesWithModelShouldFailWithIAEWhenParameterFilterIsNull()
109         throws DependencyResolverException
110     {
111         thrown.expect( IllegalArgumentException.class );
112         thrown.expectMessage( "The parameter filter is not allowed to be null." );
113 
114         ProjectBuildingRequest request = mock( ProjectBuildingRequest.class );
115         Model model = mock( Model.class );
116         dr.resolveDependencies( request, model, null );
117     }
118 
119 }