View Javadoc
1   /**
2    * The MIT License
3    *
4    * Copyright 2006-2012 The Codehaus.
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
7    * associated documentation files (the "Software"), to deal in the Software without restriction,
8    * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9    * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10   * furnished to do so, subject to the following conditions:
11   *
12   * The above copyright notice and this permission notice shall be included in all copies or
13   * substantial portions of the Software.
14   *
15   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16   * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18   * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20   */
21  package org.codehaus.mojo.appassembler.util;
22  
23  import java.io.File;
24  
25  /**
26   * This class exposes helper methods to do Unit testing in a Maven/Eclipse environment.
27   *
28   * @author <a href="mailto:info@soebes.de">Karl-Heinz Marbaise</a>
29   */
30  public class TestBase
31  {
32      /**
33       * Return the base directory of the project.
34       *
35       * @return The base folder.
36       */
37      public static String getMavenBaseDir()
38      {
39          // basedir is defined by Maven
40          // but the above will not work under Eclipse.
41          // So there I'M using user.dir
42          return System.getProperty( "basedir", System.getProperty( "user.dir", "." ) );
43      }
44  
45      /**
46       * Return the <code>target</code> directory of the current project.
47       *
48       * @return The target folder.
49       */
50      public static String getTargetDir()
51      {
52          return getMavenBaseDir() + File.separatorChar + "target" + File.separator;
53      }
54  
55      /**
56       * This will give you the <code>src</code> folder.
57       *
58       * @return The string
59       */
60      public static String getSrcDirectory()
61      {
62          return getMavenBaseDir() + File.separator + "src";
63      }
64  
65      /**
66       * This will give you the <code>src/test</code> folder.
67       *
68       * @return String representing the folder.
69       */
70  
71      public static String getTestDirectory()
72      {
73          return getSrcDirectory() + File.separator + "test";
74      }
75  
76      /**
77       * This will give you the <code>src/test/resources</code> folder.
78       *
79       * @return The string representing the folder.
80       */
81      public static String getTestResourcesDirectory()
82      {
83          return getTestDirectory() + File.separator + "resources" + File.separator;
84      }
85  
86  }