1818 */
1919package org .apache .maven .plugins .deploy ;
2020
21+ import javax .inject .Inject ;
22+
2123import java .io .File ;
2224import java .util .ArrayList ;
2325import java .util .List ;
2426import java .util .Objects ;
2527
28+ import org .apache .maven .api .plugin .testing .Basedir ;
29+ import org .apache .maven .api .plugin .testing .InjectMojo ;
30+ import org .apache .maven .api .plugin .testing .MojoTest ;
2631import org .apache .maven .execution .MavenSession ;
2732import org .apache .maven .model .Model ;
28- import org .apache .maven .plugin .testing .AbstractMojoTestCase ;
2933import org .eclipse .aether .DefaultRepositorySystemSession ;
3034import org .eclipse .aether .internal .impl .DefaultLocalPathComposer ;
3135import org .eclipse .aether .internal .impl .SimpleLocalRepositoryManagerFactory ;
3236import org .eclipse .aether .repository .LocalRepository ;
33- import org .mockito .InjectMocks ;
34- import org .mockito .Mock ;
35- import org .mockito .MockitoAnnotations ;
36-
37+ import org .junit .jupiter .api .BeforeEach ;
38+ import org .junit .jupiter .api .Test ;
39+
40+ import static org .apache .maven .api .plugin .testing .MojoExtension .getBasedir ;
41+ import static org .apache .maven .api .plugin .testing .MojoExtension .getVariableValueFromObject ;
42+ import static org .junit .jupiter .api .Assertions .assertEquals ;
43+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
44+ import static org .junit .jupiter .api .Assertions .assertTrue ;
45+ import static org .junit .jupiter .api .Assertions .fail ;
3746import static org .mockito .Mockito .when ;
3847
3948/**
4049 * @author <a href="mailto:[email protected] ">Allan Ramirez</a> 4150 */
42- public class DeployFileMojoTest extends AbstractMojoTestCase {
43- private static final String LOCAL_REPO = getBasedir () + "/target/local-repo" ;
44-
45- private List <String > expectedFiles ;
46-
47- private List <String > fileList ;
51+ @ MojoTest
52+ class DeployFileMojoTest {
4853
4954 private File remoteRepo ;
5055
51- private AutoCloseable openMocks ;
52-
53- @ Mock
56+ @ Inject
5457 private MavenSession session ;
5558
56- @ InjectMocks
57- private DeployFileMojo mojo ;
58-
59- public void setUp () throws Exception {
60- super .setUp ();
59+ @ BeforeEach
60+ void setUp () throws Exception {
61+ DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession ();
62+ repositorySession .setLocalRepositoryManager (
63+ new SimpleLocalRepositoryManagerFactory (new DefaultLocalPathComposer ())
64+ .newInstance (repositorySession , new LocalRepository (getBasedir () + "/target/local-repo" )));
65+ when (session .getRepositorySession ()).thenReturn (repositorySession );
6166
6267 remoteRepo = new File (getBasedir (), "target/remote-repo" );
6368
@@ -66,37 +71,19 @@ public void setUp() throws Exception {
6671 }
6772 }
6873
69- @ Override
70- public void tearDown () throws Exception {
71- super .tearDown ();
72- if (openMocks != null ) {
73- openMocks .close ();
74- }
75- }
76-
77- public void testDeployTestEnvironment () throws Exception {
78- File testPom = new File (getBasedir (), "target/test-classes/unit/deploy-file-test/plugin-config.xml" );
79-
80- AbstractDeployMojo mojo = (AbstractDeployMojo ) lookupMojo ("deploy-file" , testPom );
81-
74+ @ Test
75+ @ InjectMojo (goal = "deploy-file" )
76+ void testDeployTestEnvironment (DeployFileMojo mojo ) throws Exception {
8277 assertNotNull (mojo );
8378 }
8479
85- public void testBasicDeployFile () throws Exception {
86- File testPom = new File (getBasedir (), "target/test-classes/unit/deploy-file-test/plugin-config.xml" );
87-
88- mojo = (DeployFileMojo ) lookupMojo ("deploy-file" , testPom );
89-
90- openMocks = MockitoAnnotations .openMocks (this );
80+ @ Test
81+ @ InjectMojo (goal = "deploy-file" , pom = "plugin-config.xml" )
82+ @ Basedir ("/unit/deploy-file-test" )
83+ void testBasicDeployFile (DeployFileMojo mojo ) throws Exception {
9184
9285 assertNotNull (mojo );
9386
94- DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession ();
95- repositorySession .setLocalRepositoryManager (
96- new SimpleLocalRepositoryManagerFactory (new DefaultLocalPathComposer ())
97- .newInstance (repositorySession , new LocalRepository (LOCAL_REPO )));
98- when (session .getRepositorySession ()).thenReturn (repositorySession );
99-
10087 String groupId = (String ) getVariableValueFromObject (mojo , "groupId" );
10188
10289 String artifactId = (String ) getVariableValueFromObject (mojo , "artifactId" );
@@ -155,8 +142,8 @@ public void testBasicDeployFile() throws Exception {
155142 assertEquals ("POM was created from deploy:deploy-file" , model .getDescription ());
156143
157144 // check the remote-repo
158- expectedFiles = new ArrayList <>();
159- fileList = new ArrayList <>();
145+ ArrayList < String > expectedFiles = new ArrayList <>();
146+ List < String > fileList = new ArrayList <>();
160147
161148 File repo = new File (remoteRepo , "deploy-file-test" );
162149
@@ -187,21 +174,13 @@ public void testBasicDeployFile() throws Exception {
187174 assertEquals (0 , getSizeOfExpectedFiles (fileList , expectedFiles ));
188175 }
189176
190- public void testDeployIfClassifierIsSet () throws Exception {
191- File testPom = new File (getBasedir (), "target/test-classes/unit/deploy-file-classifier/plugin-config.xml" );
192-
193- mojo = (DeployFileMojo ) lookupMojo ("deploy-file" , testPom );
194-
195- openMocks = MockitoAnnotations .openMocks (this );
177+ @ Test
178+ @ InjectMojo (goal = "deploy-file" , pom = "plugin-config.xml" )
179+ @ Basedir ("/unit/deploy-file-classifier" )
180+ void testDeployIfClassifierIsSet (DeployFileMojo mojo ) throws Exception {
196181
197182 assertNotNull (mojo );
198183
199- DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession ();
200- repositorySession .setLocalRepositoryManager (
201- new SimpleLocalRepositoryManagerFactory (new DefaultLocalPathComposer ())
202- .newInstance (repositorySession , new LocalRepository (LOCAL_REPO )));
203- when (session .getRepositorySession ()).thenReturn (repositorySession );
204-
205184 String classifier = (String ) getVariableValueFromObject (mojo , "classifier" );
206185
207186 String groupId = (String ) getVariableValueFromObject (mojo , "groupId" );
@@ -237,22 +216,13 @@ public void testDeployIfClassifierIsSet() throws Exception {
237216 assertTrue (prodDeployedArtifact .exists ());
238217 }
239218
240- public void testDeployIfArtifactIsNotJar () throws Exception {
241- File testPom =
242- new File (getBasedir (), "target/test-classes/unit/deploy-file-artifact-not-jar/plugin-config.xml" );
243-
244- mojo = (DeployFileMojo ) lookupMojo ("deploy-file" , testPom );
245-
246- openMocks = MockitoAnnotations .openMocks (this );
219+ @ Test
220+ @ InjectMojo (goal = "deploy-file" , pom = "plugin-config.xml" )
221+ @ Basedir ("/unit/deploy-file-artifact-not-jar" )
222+ void testDeployIfArtifactIsNotJar (DeployFileMojo mojo ) throws Exception {
247223
248224 assertNotNull (mojo );
249225
250- DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession ();
251- repositorySession .setLocalRepositoryManager (
252- new SimpleLocalRepositoryManagerFactory (new DefaultLocalPathComposer ())
253- .newInstance (repositorySession , new LocalRepository (LOCAL_REPO )));
254- when (session .getRepositorySession ()).thenReturn (repositorySession );
255-
256226 String groupId = (String ) getVariableValueFromObject (mojo , "groupId" );
257227
258228 String artifactId = (String ) getVariableValueFromObject (mojo , "artifactId" );
@@ -276,20 +246,13 @@ public void testDeployIfArtifactIsNotJar() throws Exception {
276246 assertTrue (file .exists ());
277247 }
278248
279- public void testDeployFileIfPackagingIsSet () throws Exception {
280- File testPom = new File (getBasedir (), "target/test-classes/unit/deploy-file-packaging/plugin-config.xml" );
281- mojo = (DeployFileMojo ) lookupMojo ("deploy-file" , testPom );
282-
283- openMocks = MockitoAnnotations .openMocks (this );
249+ @ Test
250+ @ InjectMojo (goal = "deploy-file" , pom = "plugin-config.xml" )
251+ @ Basedir ("/unit/deploy-file-packaging" )
252+ void testDeployFileIfPackagingIsSet (DeployFileMojo mojo ) throws Exception {
284253
285254 assertNotNull (mojo );
286255
287- DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession ();
288- repositorySession .setLocalRepositoryManager (
289- new SimpleLocalRepositoryManagerFactory (new DefaultLocalPathComposer ())
290- .newInstance (repositorySession , new LocalRepository (LOCAL_REPO )));
291- when (session .getRepositorySession ()).thenReturn (repositorySession );
292-
293256 String packaging = (String ) getVariableValueFromObject (mojo , "packaging" );
294257
295258 String groupId = (String ) getVariableValueFromObject (mojo , "groupId" );
0 commit comments