View Javadoc
1   package org.apache.maven.plugins.release;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.mockito.Mockito.mock;
23  import static org.mockito.Mockito.verify;
24  import static org.mockito.Mockito.verifyNoMoreInteractions;
25  
26  import java.io.File;
27  
28  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
29  import org.apache.maven.shared.release.ReleaseCleanRequest;
30  import org.apache.maven.shared.release.ReleaseManager;
31  import org.mockito.ArgumentCaptor;
32  
33  /**
34   * Test release:clean.
35   *
36   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37   */
38  public class CleanReleaseMojoTest
39      extends AbstractMojoTestCase
40  {
41      protected CleanReleaseMojo mojo;
42  
43      private File workingDirectory;
44  
45      protected void setUp()
46          throws Exception
47      {
48          super.setUp();
49  
50          File testFile = getTestFile( "target/test-classes/mojos/clean/clean.xml" );
51          mojo = (CleanReleaseMojo) lookupMojo( "clean", testFile );
52          workingDirectory = testFile.getParentFile();
53          mojo.setBasedir( workingDirectory );
54      }
55  
56      public void testClean()
57          throws Exception
58      {
59          // prepare
60          ArgumentCaptor<ReleaseCleanRequest> request = ArgumentCaptor.forClass( ReleaseCleanRequest.class );
61          
62          ReleaseManager mock = mock( ReleaseManager.class );
63          mojo.setReleaseManager( mock );
64  
65          // execute
66          mojo.execute();
67  
68          // verify
69          verify( mock ).clean( request.capture() );
70          
71          assertEquals( mojo.getReactorProjects(), request.getValue().getReactorProjects() );
72          
73          verifyNoMoreInteractions( mock );
74      }
75  }