View Javadoc

1   package org.apache.maven.plugin.dependency;
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 java.io.File;
23  import java.io.IOException;
24  
25  import org.apache.maven.plugin.dependency.testUtils.DependencyArtifactStubFactory;
26  import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
27  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
28  
29  public abstract class AbstractDependencyMojoTestCase
30      extends AbstractMojoTestCase
31  {
32  
33      protected File testDir;
34  
35      protected DependencyArtifactStubFactory stubFactory;
36  
37      public AbstractDependencyMojoTestCase()
38      {
39          super();
40      }
41  
42      protected void setUp( String testDirStr, boolean createFiles )
43          throws Exception
44      {
45          // required for mojo lookups to work
46          super.setUp();
47          testDir = new File( getBasedir(), "target" + File.separatorChar + "unit-tests" + File.separatorChar
48              + testDirStr + File.separatorChar );
49          DependencyTestUtils.removeDirectory( testDir );
50          assertFalse( testDir.exists() );
51  
52          stubFactory = new DependencyArtifactStubFactory( this.testDir, createFiles );
53  
54      }
55  
56      protected void tearDown()
57      {
58          if ( testDir != null )
59          {
60              try
61              {
62                  DependencyTestUtils.removeDirectory( testDir );
63              }
64              catch ( IOException e )
65              {
66                  // TODO Auto-generated catch block
67                  e.printStackTrace();
68                  fail( "Trying to remove directory:" + testDir + "\r\n" + e.toString() );
69              }
70              assertFalse( testDir.exists() );
71              
72              testDir = null;
73          }
74          
75          stubFactory = null;
76      }
77  
78  }