1 package org.apache.maven.shared.transfer.artifact.install.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.when;
24
25 import java.io.File;
26 import java.util.Collections;
27 import java.util.List;
28
29 import org.apache.maven.artifact.Artifact;
30 import org.apache.maven.project.ProjectBuildingRequest;
31 import org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller;
32 import org.apache.maven.shared.transfer.artifact.install.ArtifactInstallerException;
33 import org.apache.maven.shared.transfer.artifact.install.internal.DefaultArtifactInstaller;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37
38
39
40
41
42
43 public class DefaultArtifactInstallerTest
44 {
45 @Rule
46 public ExpectedException thrown = ExpectedException.none();
47
48 @Test
49 public void installShouldReturnIllegalArgumentExceptionForFirstParameterWithNull() throws IllegalArgumentException, ArtifactInstallerException
50 {
51 DefaultArtifactInstaller dai = new DefaultArtifactInstaller();
52
53 thrown.expect( IllegalArgumentException.class );
54 thrown.expectMessage( "The parameter request is not allowed to be null." );
55 dai.install( null, Collections.<Artifact>emptyList() );
56 }
57
58 @Test
59 public void installShouldReturnIllegalArgumentExceptionForSecondParameterWithNull()
60 throws ArtifactInstallerException
61 {
62 DefaultArtifactInstaller dai = new DefaultArtifactInstaller();
63
64 thrown.expect( IllegalArgumentException.class );
65 thrown.expectMessage( "The parameter mavenArtifacts is not allowed to be null." );
66 ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
67 dai.install( pbr, null );
68 }
69
70 @Test
71 public void installShouldReturnIllegalArgumentExceptionForSecondParameterWithEmpty()
72 throws ArtifactInstallerException
73 {
74 DefaultArtifactInstaller dai = new DefaultArtifactInstaller();
75
76 thrown.expect( IllegalArgumentException.class );
77 thrown.expectMessage( "The collection mavenArtifacts is not allowed to be empty." );
78 ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
79 dai.install( pbr, Collections.<Artifact>emptyList() );
80 }
81
82 @Test
83 public void installWith3ParametersShouldReturnIllegalArgumentExceptionForFirstParameterWithNull()
84 throws ArtifactInstallerException
85 {
86 DefaultArtifactInstaller dai = new DefaultArtifactInstaller();
87
88 thrown.expect( IllegalArgumentException.class );
89 thrown.expectMessage( "The parameter request is not allowed to be null." );
90 File localRepository = mock( File.class );
91 dai.install( null, localRepository, Collections.<Artifact>emptyList() );
92 }
93
94 @Test
95 public void installWith3ParametersShouldReturnIllegalArgumentExceptionForSecondParameterWithNull()
96 throws ArtifactInstallerException
97 {
98 DefaultArtifactInstaller dai = new DefaultArtifactInstaller();
99
100 thrown.expect( IllegalArgumentException.class );
101 thrown.expectMessage( "The parameter localRepository is not allowed to be null." );
102
103 List<Artifact> singleEntryList = Collections.singletonList( mock( Artifact.class ) );
104 ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
105 dai.install( pbr, null, singleEntryList );
106 }
107
108 @Test
109 public void installWith3ParametersShouldReturnIllegalArgumentExceptionForSecondParameterNotADirectory()
110 throws ArtifactInstallerException
111 {
112 DefaultArtifactInstaller dai = new DefaultArtifactInstaller();
113
114 thrown.expect( IllegalArgumentException.class );
115 thrown.expectMessage( "The parameter localRepository must be a directory." );
116 ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
117 List<Artifact> singleEntryList = Collections.singletonList( mock( Artifact.class ) );
118
119 File localRepository = mock( File.class );
120 when( localRepository.isDirectory() ).thenReturn( false );
121 dai.install( pbr, localRepository, singleEntryList );
122 }
123
124 @Test
125 public void installWith3ParametersShouldReturnIllegalArgumentExceptionForThirdParameterWithNull()
126 throws ArtifactInstallerException
127 {
128 DefaultArtifactInstaller dai = new DefaultArtifactInstaller();
129
130 thrown.expect( IllegalArgumentException.class );
131 thrown.expectMessage( "The parameter mavenArtifacts is not allowed to be null." );
132 ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
133 File localRepository = mock( File.class );
134 dai.install( pbr, localRepository, null );
135 }
136
137 }