org.sonar.test
Class TestUtils

java.lang.Object
  extended by org.sonar.test.TestUtils

public class TestUtils
extends Object

Utilities for unit tests

Since:
2.2

Constructor Summary
TestUtils()
           
 
Method Summary
static void assertExists(File file)
          Checks that a file or a directory is not null and exists.
static void assertSimilarXml(String expectedXml, String xml)
           
static File getResource(Class baseClass, String path)
          Search for a resource in the classpath.
static File getResource(String path)
          Search for a test resource in the classpath.
static String getResourceContent(String path)
           
static File getTestTempDir(Class baseClass, String testName)
          Shortcut for getTestTempDir(baseClass, testName, true) : cleans the unit test directory
static File getTestTempDir(Class baseClass, String testName, boolean clean)
          Create a temporary directory for unit tests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestUtils

public TestUtils()
Method Detail

getResource

public static File getResource(String path)
Search for a test resource in the classpath. For example getResource("org/sonar/MyClass/foo.txt");

Parameters:
path - the starting slash is optional
Returns:
the resource. Null if resource not found

getResourceContent

public static String getResourceContent(String path)

getResource

public static File getResource(Class baseClass,
                               String path)
Search for a resource in the classpath. For example calling the method getResource(getClass(), "myTestName/foo.txt") from the class org.sonar.Foo loads the file $basedir/src/test/resources/org/sonar/Foo/myTestName/foo.txt

Returns:
the resource. Null if resource not found

getTestTempDir

public static File getTestTempDir(Class baseClass,
                                  String testName)
Shortcut for getTestTempDir(baseClass, testName, true) : cleans the unit test directory


getTestTempDir

public static File getTestTempDir(Class baseClass,
                                  String testName,
                                  boolean clean)
Create a temporary directory for unit tests.

Parameters:
baseClass - the unit test class
testName - the test name
clean - remove all the sub-directories and files ?

assertExists

public static void assertExists(File file)
Checks that a file or a directory is not null and exists.


assertSimilarXml

public static void assertSimilarXml(String expectedXml,
                                    String xml)
                             throws IOException,
                                    SAXException
Throws:
IOException
SAXException


Copyright © 2009-2011 SonarSource. All Rights Reserved.