View Javadoc
1   package org.apache.maven.shared.transfer.artifact.deploy.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 java.util.Collections;
25  
26  import org.apache.maven.artifact.Artifact;
27  import org.apache.maven.project.ProjectBuildingRequest;
28  import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployer;
29  import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
30  import org.apache.maven.shared.transfer.artifact.deploy.internal.DefaultArtifactDeployer;
31  import org.junit.Before;
32  import org.junit.Rule;
33  import org.junit.Test;
34  import org.junit.rules.ExpectedException;
35  
36  /**
37   * Check the parameter contracts which have been made based on the interface {@link ArtifactDeployer}.
38   * 
39   * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmabaise@apache.org</a>
40   */
41  public class DefaultArtifactDeployerTest
42  {
43      @Rule
44      public ExpectedException thrown = ExpectedException.none();
45      
46      private ArtifactDeployer dap;
47      
48      @Before
49      public void setUp()
50      {
51          dap = new DefaultArtifactDeployer();
52      }
53  
54      @Test
55      public void deployShouldReturnIllegalArgumentExceptionForFirstParameterWithNull()
56          throws ArtifactDeployerException
57      {
58          thrown.expect( IllegalArgumentException.class );
59          thrown.expectMessage( "The parameter request is not allowed to be null." );
60          dap.deploy( null, Collections.<Artifact>emptyList() );
61      }
62  
63      @Test
64      public void deployShouldReturnIllegalArgumentExceptionForSecondParameterWithNull()
65          throws ArtifactDeployerException
66      {
67          ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
68  
69          thrown.expect( IllegalArgumentException.class );
70          thrown.expectMessage( "The parameter mavenArtifacts is not allowed to be null." );
71          dap.deploy( pbr, null );
72      }
73  
74      @Test
75      public void deployShouldReturnIllegalArgumentExceptionForSecondParameterWithEmpty()
76          throws ArtifactDeployerException
77      {
78          ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
79  
80          thrown.expect( IllegalArgumentException.class );
81          thrown.expectMessage( "The collection mavenArtifacts is not allowed to be empty." );
82          dap.deploy( pbr, Collections.<Artifact>emptyList() );
83      }
84  
85  
86      @Test
87      public void deploy3ParametersShouldReturnIllegalArgumentExceptionForFirstParameterWithNull()
88          throws ArtifactDeployerException
89      {
90          thrown.expect( IllegalArgumentException.class );
91          thrown.expectMessage( "The parameter request is not allowed to be null." );
92          dap.deploy( null, null, Collections.<Artifact>emptyList() );
93      }
94  
95      @Test
96      public void deploy3ParametersShouldReturnIllegalArgumentExceptionForSecondParameterWithNull()
97          throws ArtifactDeployerException
98      {
99          ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
100 
101         thrown.expect( IllegalArgumentException.class );
102         thrown.expectMessage( "The parameter mavenArtifacts is not allowed to be null." );
103         dap.deploy( pbr, null, null );
104     }
105 
106     @Test
107     public void deploy3ParametersShouldReturnIllegalArgumentExceptionForSecondParameterWithEmpty()
108         throws ArtifactDeployerException
109     {
110         ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
111 
112         thrown.expect( IllegalArgumentException.class );
113         thrown.expectMessage( "The collection mavenArtifacts is not allowed to be empty." );
114         dap.deploy( pbr, null, Collections.<Artifact>emptyList() );
115     }
116 
117 }