class Helpers extends java.lang.Object
Utility class for managing the dependency container during testing.
Unlike using the raw Components class, this one has caching logic that can be useful when building the
dependency container from a @Before
or @BeforeClass
context.
To developers
Beware of over-optimizing. It is better to rebuild the entire dependency container than, say, rebuild the Settings
class only. Singletons in other modules rely on the instance of Settings that existed at the point in time they
were created, and will not see any changes to the Settings singleton going forward.
The SessionFactory, is one such class. Look at how the SessionFactoryProvider is implemented.
Constructor and description |
---|
Helpers() |
Type Params | Return Type | Name and description |
---|---|---|
<T> |
static T |
get(java.lang.Class<T> klass) Retrieves an instance of T from the dependency container. |
|
static void |
initializeContext() Initialize the dependency container. |
|
static void |
initializeContext(java.lang.String configuration) Initialize the dependency container but specify a configuration file to use. |
|
static void |
loadSettings(java.lang.String configFile) Initialize Settings. |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Retrieves an instance of T from the dependency container. This method calls Helpers.initializeContext if the container has not been initialized yet.
klass
- The instance type.Initialize the dependency container. Will abort if the container has been already initialized.
Initialize the dependency container but specify a configuration file to use. Will abort if the container has already been initialized using the configuration file specified.
configuration
- The configuration file to use, e.g. "test.conf".Initialize Settings.
configFile
- A configuration file e.g. "dev.conf" or "default" for the default configuration.