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