1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.dependency;
20
21 import java.io.File;
22
23 import org.apache.maven.execution.MavenSession;
24 import org.apache.maven.plugin.Mojo;
25 import org.apache.maven.plugin.logging.Log;
26 import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
27 import org.apache.maven.project.MavenProject;
28 import org.mockito.ArgumentCaptor;
29
30 import static org.mockito.Mockito.atLeastOnce;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.verify;
33
34 public class TestSkip extends AbstractDependencyMojoTestCase {
35
36 @Override
37 protected void setUp() throws Exception {
38 super.setUp();
39 MavenProject project = new DependencyProjectStub();
40 getContainer().addComponent(project, MavenProject.class.getName());
41
42 MavenSession session = newMavenSession(project);
43 getContainer().addComponent(session, MavenSession.class.getName());
44 }
45
46 public void testSkipAnalyze() throws Exception {
47 doTest("analyze");
48 }
49
50 public void testSkipAnalyzeDepMgt() throws Exception {
51 doTest("analyze-dep-mgt");
52 }
53
54 public void testSkipAnalyzeOnly() throws Exception {
55 doTest("analyze-only");
56 }
57
58 public void testSkipAnalyzeReport() throws Exception {
59 doSpecialTest("analyze-report");
60 }
61
62 public void testSkipAnalyzeDuplicate() throws Exception {
63 doTest("analyze-duplicate");
64 }
65
66 public void testSkipBuildClasspath() throws Exception {
67 doTest("build-classpath");
68 }
69
70 public void testSkipCopy() throws Exception {
71 doTest("copy");
72 }
73
74 public void testSkipCopyDependencies() throws Exception {
75 doTest("copy-dependencies");
76 }
77
78 public void testSkipGet() throws Exception {
79 doSpecialTest("get");
80 }
81
82 public void testSkipGoOffline() throws Exception {
83 doTest("go-offline");
84 }
85
86 public void testSkipList() throws Exception {
87 doTest("list");
88 }
89
90 public void testSkipProperties() throws Exception {
91 doTest("properties");
92 }
93
94 public void testSkipPurgeLocalRepository() throws Exception {
95 doSpecialTest("purge-local-repository");
96 }
97
98 public void testSkipResolve() throws Exception {
99 doTest("resolve");
100 }
101
102 public void testSkipResolvePlugins() throws Exception {
103 doTest("resolve-plugins");
104 }
105
106 public void testSkipSources() throws Exception {
107 doTest("sources");
108 }
109
110 public void testSkipTree() throws Exception {
111 doTest("tree");
112 }
113
114 public void testSkipUnpack() throws Exception {
115 doTest("unpack");
116 }
117
118 public void testSkipUnpackDependencies() throws Exception {
119 doTest("unpack-dependencies");
120 }
121
122 protected void doTest(String mojoName) throws Exception {
123 doConfigTest(mojoName, "plugin-config.xml");
124 }
125
126 protected void doSpecialTest(String mojoName) throws Exception {
127 doConfigTest(mojoName, "plugin-" + mojoName + "-config.xml");
128 }
129
130 private void doConfigTest(String mojoName, String configFile) throws Exception {
131 File testPom = new File(getBasedir(), "target/test-classes/unit/skip-test/" + configFile);
132 Mojo mojo = lookupMojo(mojoName, testPom);
133 assertNotNull(mojo);
134 Log log = mock(Log.class);
135 mojo.setLog(log);
136 mojo.execute();
137
138 ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
139 verify(log, atLeastOnce()).info(captor.capture());
140 assertTrue(captor.getValue().contains("Skipping plugin execution"));
141 }
142 }