org.unitils.core
Class Unitils

java.lang.Object
  extended by org.unitils.core.Unitils

public class Unitils
extends Object

Core class of the Unitils library, and the main entry point that gives access to the TestContext and the different Modules.

An instance of Unitils is configured with a certain configuration using the init(Properties) method. Normally, only one instance of Unitils exists at any time. The default instance can be obtained using the getInstance() method. This default instance can be set to a custom initialized instance or instance of a custom subclass using setInstance(Unitils).

If not set, the singleton instance is initialized by default using initSingletonInstance(). This method uses the ConfigurationLoader to load the configuration. An instance of ModulesRepository is used to initialize and maintain the modules.

Unitils itself is also implemented as a module. In fact, an instance of Unitils behaves like a module who's behaviour is defined by the added behaviour of all modules.


Constructor Summary
Unitils()
          Creates a new instance.
 
Method Summary
protected  void afterInitModules()
          Gives all modules the opportunity to performs initialization that can only work after all other modules have been initialized
protected  ModulesRepository createModulesRepository(Properties configuration)
          Configures all unitils modules using the given Properties object, and stores them in a ModulesRepository.
 Properties getConfiguration()
          Returns all properties that are used to configure unitils and the different modules.
static Unitils getInstance()
          Returns the singleton instance
 ModulesRepository getModulesRepository()
          Returns the ModulesRepository that provides access to the modules that are configured in unitils.
 TestContext getTestContext()
          Returns the TestContext that, during the execution of the test suite, keeps track of the current test object, class and test method that are executing.
 TestListener getTestListener()
          Returns the single instance of TestListener.
 void init()
          Initializes unitils with the configuration files.
 void init(Properties configuration)
          Initializes Unitils with the given configuration.
static void initSingletonInstance()
          Initializes the singleton instance to the default value, loading the configuration using the ConfigurationLoader
protected  boolean isClassAvailable(String className)
          Utility method that verifies whether the class with the given fully qualified classname is available in the classpath.
static void setInstance(Unitils unitils)
          Sets the singleton instance to the given object
protected  void verifyPackaging(Properties configuration)
          Verifies that we're not working with a distribution that includes the necessary classes from spring, while spring is in the classpath anyway.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Unitils

public Unitils()
Creates a new instance.

Method Detail

getInstance

public static Unitils getInstance()
Returns the singleton instance

Returns:
the singleton instance, not null

setInstance

public static void setInstance(Unitils unitils)
Sets the singleton instance to the given object

Parameters:
unitils - the singleton instance

initSingletonInstance

public static void initSingletonInstance()
Initializes the singleton instance to the default value, loading the configuration using the ConfigurationLoader


init

public void init()
Initializes unitils with the configuration files.


init

public void init(Properties configuration)
Initializes Unitils with the given configuration. All the modules that are configured in the given configuration are also created and initialized with this configuration.

Parameters:
configuration - The config, not null

afterInitModules

protected void afterInitModules()
Gives all modules the opportunity to performs initialization that can only work after all other modules have been initialized


verifyPackaging

protected void verifyPackaging(Properties configuration)
Verifies that we're not working with a distribution that includes the necessary classes from spring, while spring is in the classpath anyway.

Parameters:
configuration - The configuration

isClassAvailable

protected boolean isClassAvailable(String className)
Utility method that verifies whether the class with the given fully qualified classname is available in the classpath.

Parameters:
className - The name of the class
Returns:
True if the class with the given name is available

getTestListener

public TestListener getTestListener()
Returns the single instance of TestListener. This instance provides hook callback methods that enable intervening during the execution of unit tests.

Returns:
The single TestListener

getModulesRepository

public ModulesRepository getModulesRepository()
Returns the ModulesRepository that provides access to the modules that are configured in unitils.

Returns:
the ModulesRepository

getTestContext

public TestContext getTestContext()
Returns the TestContext that, during the execution of the test suite, keeps track of the current test object, class and test method that are executing.

Returns:
the TestContext

getConfiguration

public Properties getConfiguration()
Returns all properties that are used to configure unitils and the different modules.

Returns:
a Properties object

createModulesRepository

protected ModulesRepository createModulesRepository(Properties configuration)
Configures all unitils modules using the given Properties object, and stores them in a ModulesRepository. The configuration of the modules is delegated to a ModulesLoader instance.

Parameters:
configuration - The config, not null
Returns:
a new ModulesRepository


Copyright © 2011. All Rights Reserved.