1818 */
1919package org .apache .maven .plugins .dependency ;
2020
21- import java .io .File ;
2221import java .util .Set ;
2322
23+ import org .apache .maven .api .plugin .testing .InjectMojo ;
24+ import org .apache .maven .api .plugin .testing .MojoParameter ;
25+ import org .apache .maven .api .plugin .testing .MojoTest ;
2426import org .apache .maven .artifact .Artifact ;
25- import org .apache .maven .execution .MavenSession ;
2627import org .apache .maven .plugins .dependency .resolvers .CollectDependenciesMojo ;
27- import org .apache .maven .plugins .dependency .resolvers .ResolveDependenciesMojo ;
28- import org .apache .maven .plugins .dependency .testUtils .stubs .DependencyProjectStub ;
28+ import org .apache .maven .plugins .dependency .testUtils .DependencyArtifactStubFactory ;
2929import org .apache .maven .plugins .dependency .utils .DependencySilentLog ;
3030import org .apache .maven .plugins .dependency .utils .DependencyStatusSets ;
3131import org .apache .maven .project .MavenProject ;
32+ import org .junit .jupiter .api .BeforeEach ;
33+ import org .junit .jupiter .api .Test ;
3234
33- public class TestCollectMojo extends AbstractDependencyMojoTestCase {
35+ import static org .junit .jupiter .api .Assertions .assertEquals ;
36+ import static org .junit .jupiter .api .Assertions .assertFalse ;
37+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
38+ import static org .junit .jupiter .api .Assertions .assertTrue ;
3439
35- @ Override
36- protected String getTestDirectoryName () {
37- return "markers" ;
38- }
39-
40- @ Override
41- protected boolean shouldCreateFiles () {
42- return false ;
43- }
44-
45- @ Override
46- protected void setUp () throws Exception {
47- // required for mojo lookups to work
48- super .setUp ();
40+ @ MojoTest
41+ class TestCollectMojo {
4942
50- MavenProject project = new DependencyProjectStub ();
51- getContainer ().addComponent (project , MavenProject .class .getName ());
43+ private DependencyArtifactStubFactory stubFactory ;
5244
53- MavenSession session = newMavenSession (project );
54- getContainer ().addComponent (session , MavenSession .class .getName ());
45+ @ BeforeEach
46+ void setUp () throws Exception {
47+ stubFactory = new DependencyArtifactStubFactory (null , false );
5548 }
5649
5750 /**
5851 * tests the proper discovery and configuration of the mojo
5952 *
6053 * @throws Exception if a problem occurs
6154 */
62- public void testCollectTestEnvironment () throws Exception {
63- File testPom = new File ( getBasedir (), "target/test-classes/unit/ collect-test/plugin-config.xml" );
64- CollectDependenciesMojo mojo = ( CollectDependenciesMojo ) lookupMojo ( "collect" , testPom );
55+ @ Test
56+ @ InjectMojo ( goal = " collect" )
57+ void testCollectTestEnvironment ( CollectDependenciesMojo mojo ) throws Exception {
6558
6659 assertNotNull (mojo );
6760 assertNotNull (mojo .getProject ());
@@ -85,10 +78,10 @@ public void testCollectTestEnvironment() throws Exception {
8578 *
8679 * @throws Exception if a problem occurs
8780 */
88- public void testCollectTestEnvironmentExcludeTransitive () throws Exception {
89- File testPom = new File ( getBasedir (), "target/test-classes/unit/ collect-test/plugin-config.xml" );
90- CollectDependenciesMojo mojo = ( CollectDependenciesMojo ) lookupMojo ( "collect" , testPom );
91-
81+ @ Test
82+ @ InjectMojo ( goal = " collect" )
83+ @ MojoParameter ( name = "excludeTransitive" , value = "true" )
84+ void testCollectTestEnvironmentExcludeTransitive ( CollectDependenciesMojo mojo ) throws Exception {
9285 assertNotNull (mojo );
9386 assertNotNull (mojo .getProject ());
9487 MavenProject project = mojo .getProject ();
@@ -100,18 +93,15 @@ public void testCollectTestEnvironmentExcludeTransitive() throws Exception {
10093 project .setArtifacts (artifacts );
10194 project .setDependencyArtifacts (directArtifacts );
10295
103- setVariableValueToObject (mojo , "excludeTransitive" , Boolean .TRUE );
104-
10596 mojo .execute ();
10697 DependencyStatusSets results = mojo .getResults ();
10798 assertNotNull (results );
10899 assertEquals (directArtifacts .size (), results .getResolvedDependencies ().size ());
109100 }
110101
111- public void testSilent () throws Exception {
112- File testPom = new File (getBasedir (), "target/test-classes/unit/resolve-test/plugin-config.xml" );
113- ResolveDependenciesMojo mojo = (ResolveDependenciesMojo ) lookupMojo ("resolve" , testPom );
114-
102+ @ Test
103+ @ InjectMojo (goal = "collect" )
104+ void testSilent (CollectDependenciesMojo mojo ) throws Exception {
115105 assertFalse (mojo .getLog () instanceof DependencySilentLog );
116106
117107 mojo .setSilent (true );
0 commit comments