org.sonar.test
Class TestUtils

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

public class TestUtils
extends java.lang.Object

Utilities for unit tests

Since:
2.2

Constructor Summary
TestUtils()
           
 
Method Summary
static void assertExists(java.io.File file)
          Checks that a file or a directory is not null and exists.
static void assertSimilarXml(java.lang.String expectedXml, java.lang.String xml)
           
static java.io.File getResource(java.lang.Class baseClass, java.lang.String path)
          Search for a resource in the classpath.
static java.io.File getResource(java.lang.String path)
          Search for a test resource in the classpath.
static java.io.File getTestTempDir(java.lang.Class baseClass, java.lang.String testName)
          Shortcut for getTestTempDir(baseClass, testName, true) : cleans the unit test directory
static java.io.File getTestTempDir(java.lang.Class baseClass, java.lang.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 java.io.File getResource(java.lang.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

getResource

public static java.io.File getResource(java.lang.Class baseClass,
                                       java.lang.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 java.io.File getTestTempDir(java.lang.Class baseClass,
                                          java.lang.String testName)
Shortcut for getTestTempDir(baseClass, testName, true) : cleans the unit test directory


getTestTempDir

public static java.io.File getTestTempDir(java.lang.Class baseClass,
                                          java.lang.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(java.io.File file)
Checks that a file or a directory is not null and exists.


assertSimilarXml

public static void assertSimilarXml(java.lang.String expectedXml,
                                    java.lang.String xml)
                             throws java.io.IOException,
                                    org.xml.sax.SAXException
Throws:
java.io.IOException
org.xml.sax.SAXException


Copyright © 2009-2010 SonarSource. All Rights Reserved.