View Javadoc
1   package org.apache.maven.plugins.dependency;
2   
3   import org.apache.maven.plugin.Mojo;
4   import org.apache.maven.plugin.logging.Log;
5   import org.mockito.ArgumentCaptor;
6   
7   import java.io.File;
8   
9   import static org.mockito.Mockito.atLeastOnce;
10  import static org.mockito.Mockito.mock;
11  import static org.mockito.Mockito.verify;
12  
13  /*
14   * Licensed to the Apache Software Foundation (ASF) under one
15   * or more contributor license agreements.  See the NOTICE file
16   * distributed with this work for additional information
17   * regarding copyright ownership.  The ASF licenses this file
18   * to you under the Apache License, Version 2.0 (the
19   * "License"); you may not use this file except in compliance
20   * with the License.  You may obtain a copy of the License at
21   *
22   *  http://www.apache.org/licenses/LICENSE-2.0
23   *
24   * Unless required by applicable law or agreed to in writing,
25   * software distributed under the License is distributed on an
26   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
27   * KIND, either express or implied.  See the License for the
28   * specific language governing permissions and limitations
29   * under the License.
30   */
31  
32  public class TestSkip
33      extends AbstractDependencyMojoTestCase
34  {
35      public void testSkipAnalyze()
36          throws Exception
37      {
38          doTest( "analyze" );
39      }
40  
41      public void testSkipAnalyzeDepMgt()
42          throws Exception
43      {
44          doTest( "analyze-dep-mgt" );
45      }
46  
47      public void testSkipAnalyzeOnly()
48          throws Exception
49      {
50          doTest( "analyze-only" );
51      }
52  
53      public void testSkipAnalyzeReport()
54          throws Exception
55      {
56          doSpecialTest( "analyze-report" );
57      }
58  
59      public void testSkipAnalyzeDuplicate()
60          throws Exception
61      {
62          doTest( "analyze-duplicate" );
63      }
64  
65      public void testSkipBuildClasspath()
66          throws Exception
67      {
68          doTest( "build-classpath" );
69      }
70  
71      public void testSkipCopy()
72          throws Exception
73      {
74          doTest( "copy" );
75      }
76  
77      public void testSkipCopyDependencies()
78          throws Exception
79      {
80          doTest( "copy-dependencies" );
81      }
82  
83      public void testSkipGet()
84          throws Exception
85      {
86          doSpecialTest( "get" );
87      }
88  
89      public void testSkipGoOffline()
90          throws Exception
91      {
92          doTest( "go-offline" );
93      }
94  
95      public void testSkipList()
96          throws Exception
97      {
98          doTest( "list" );
99      }
100 
101     public void testSkipProperties()
102         throws Exception
103     {
104         doTest( "properties" );
105     }
106 
107     public void testSkipPurgeLocalRepository()
108         throws Exception
109     {
110         doSpecialTest( "purge-local-repository" );
111     }
112 
113     public void testSkipResolve()
114         throws Exception
115     {
116         doTest( "resolve" );
117     }
118 
119     public void testSkipResolvePlugins()
120         throws Exception
121     {
122         doTest( "resolve-plugins" );
123     }
124 
125     public void testSkipSources()
126         throws Exception
127     {
128         doTest( "sources" );
129     }
130 
131     public void testSkipTree()
132         throws Exception
133     {
134         doTest( "tree" );
135     }
136 
137     public void testSkipUnpack()
138         throws Exception
139     {
140         doTest( "unpack" );
141     }
142 
143     public void testSkipUnpackDependencies()
144         throws Exception
145     {
146         doTest( "unpack-dependencies" );
147     }
148 
149     protected void doTest( String mojoName )
150         throws Exception
151     {
152         doConfigTest( mojoName, "plugin-config.xml" );
153     }
154 
155     protected void doSpecialTest( String mojoName )
156         throws Exception
157     {
158         doConfigTest( mojoName, "plugin-" + mojoName + "-config.xml" );
159     }
160 
161     private void doConfigTest( String mojoName, String configFile )
162         throws Exception
163     {
164         File testPom = new File( getBasedir(), "target/test-classes/unit/skip-test/" + configFile );
165         Mojo mojo = lookupMojo( mojoName, testPom );
166         assertNotNull( mojo );
167         Log log = mock( Log.class );
168         mojo.setLog( log );
169         mojo.execute();
170 
171         ArgumentCaptor<String> captor = ArgumentCaptor.forClass( String.class );
172         verify( log, atLeastOnce() ).info( captor.capture() );
173         assertTrue( captor.getValue().contains( "Skipping plugin execution" ) );
174     }
175 
176 }