org.sonar.test
Class TestUtils

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

public final class TestUtils
extends Object

Utilities for unit tests

Since:
2.2

Method Summary
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 boolean hasOnlyPrivateConstructors(Class clazz)
          Asserts that all constructors are private, usually for helper classes with only static methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

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

hasOnlyPrivateConstructors

public static boolean hasOnlyPrivateConstructors(Class clazz)
Asserts that all constructors are private, usually for helper classes with only static methods. If a constructor does not have any parameters, then it's instantiated.



Copyright © 2009–2015 SonarSource. All rights reserved.