View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.dependency.resolvers;
20  
21  import java.util.Set;
22  
23  import org.apache.maven.api.plugin.testing.InjectMojo;
24  import org.apache.maven.api.plugin.testing.MojoTest;
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
27  import org.apache.maven.plugins.dependency.utils.DependencySilentLog;
28  import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
29  import org.apache.maven.project.MavenProject;
30  import org.junit.jupiter.api.Test;
31  
32  import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
33  import static org.junit.jupiter.api.Assertions.assertEquals;
34  import static org.junit.jupiter.api.Assertions.assertFalse;
35  import static org.junit.jupiter.api.Assertions.assertTrue;
36  import static org.junit.jupiter.api.AssertionsKt.assertNotNull;
37  
38  @MojoTest
39  class TestResolveMojo {
40  
41      /**
42       * tests the proper discovery and configuration of the mojo
43       *
44       * @throws Exception in case of errors.
45       */
46      @Test
47      @InjectMojo(goal = "resolve")
48      void testResolveTestEnvironment(ResolveDependenciesMojo mojo) throws Exception {
49          assertNotNull(mojo);
50          assertNotNull(mojo.getProject());
51          MavenProject project = mojo.getProject();
52  
53          DependencyArtifactStubFactory stubFactory = new DependencyArtifactStubFactory(null, false);
54          Set<Artifact> artifacts = stubFactory.getScopedArtifacts();
55          Set<Artifact> directArtifacts = stubFactory.getReleaseAndSnapshotArtifacts();
56          artifacts.addAll(directArtifacts);
57  
58          project.setArtifacts(artifacts);
59          project.setDependencyArtifacts(directArtifacts);
60  
61          mojo.execute();
62          DependencyStatusSets results = mojo.getResults();
63          assertNotNull(results);
64          assertEquals(artifacts.size(), results.getResolvedDependencies().size());
65  
66          setVariableValueToObject(mojo, "excludeTransitive", Boolean.TRUE);
67  
68          mojo.execute();
69          results = mojo.getResults();
70          assertNotNull(results);
71          assertEquals(directArtifacts.size(), results.getResolvedDependencies().size());
72      }
73  
74      @Test
75      @InjectMojo(goal = "resolve")
76      void testSilent(ResolveDependenciesMojo mojo) {
77          assertFalse(mojo.getLog() instanceof DependencySilentLog);
78  
79          mojo.setSilent(true);
80          assertTrue(mojo.getLog() instanceof DependencySilentLog);
81  
82          mojo.setSilent(false);
83          assertFalse(mojo.getLog() instanceof DependencySilentLog);
84      } // TODO: Test skipping artifacts.
85  }