public class TestServiceLocator extends Object
The behavior of HK2Runner can be customized by annotating the class extending
HK2Runner with Packages,
Classes, Excludes
or InhabitantFiles.
Packages gives the names of packages
that will automatically be scanned for classes that should be added to testLocator
as services. Classes gives an
explicit set of classes that should be added to testLocator as services.
Excludes gives a set of services
that should not be automatically added to the testLocator.
InhabitantFiles gives a set of
inhabitant files to load in the classpath of the test.
This behavior can be customized by overriding the before method of the test and calling one
of the initialize(String, List, List) methods. The annotations listed above
are overridden by any values passed to the initialize methods
| Constructor and Description |
|---|
TestServiceLocator(Object test)
This will generate the default testLocator for this test
class, which will search the package of the test itself for
classes annotated with @Service.
|
| Modifier and Type | Method and Description |
|---|---|
ServiceLocator |
getServiceLocator() |
void |
initialize()
This method initializes the service locator with services.
|
void |
initialize(String name,
List<String> packages,
List<Class<?>> clazzes)
This method initializes the service locator with services from the given list
of packages (in "." format) and with the set of classes given.
|
void |
initialize(String name,
List<String> packages,
List<Class<?>> clazzes,
Set<String> excludes)
This method initializes the service locator with services from the given list
of packages (in "." format) and with the set of classes given.
|
void |
initialize(String name,
List<String> packages,
List<Class<?>> clazzes,
Set<String> excludes,
Set<String> locatorFiles)
This method initializes the service locator with services from the given list
of packages (in "." format) and with the set of classes given.
|
void |
initializeOnBefore() |
void |
setVerbosity(boolean verbose) |
public TestServiceLocator(Object test)
public void initializeOnBefore()
public ServiceLocator getServiceLocator()
public void initialize()
public void initialize(String name, List<String> packages, List<Class<?>> clazzes)
name - The name of the service locator to create. If there is already a
service locator of this name then the remaining fields will be ignored and the existing
locator with this name will be returned. May not be nullpackages - The list of packages (in "." format, i.e. "com.acme.test.services") that
we should hunt through the classpath for in order to find services. If null this is considered
to be the empty setclazzes - A set of classes that should be analyzed as services, whether they declare
@Service or not. If null this is considered to be the empty setpublic void initialize(String name, List<String> packages, List<Class<?>> clazzes, Set<String> excludes)
name - The name of the service locator to create. If there is already a
service locator of this name then the remaining fields will be ignored and the existing
locator with this name will be returned. May not be nullpackages - The list of packages (in "." format, i.e. "com.acme.test.services") that
we should hunt through the classpath for in order to find services. If null this is considered
to be the empty setclazzes - A set of classes that should be analyzed as services, whether they declare
@Service or not. If null this is considered to be the empty setexcludes - A set of implementations that should be excluded from being added. This list is
NOT checked against the clazzes list (the explicit include wins), but instead against the set of
things coming from packages or from the hk2-locator/default filepublic void initialize(String name, List<String> packages, List<Class<?>> clazzes, Set<String> excludes, Set<String> locatorFiles)
name - The name of the service locator to create. If there is already a
service locator of this name then the remaining fields will be ignored and the existing
locator with this name will be returned. May not be nullpackages - The list of packages (in "." format, i.e. "com.acme.test.services") that
we should hunt through the classpath for in order to find services. If null this is considered
to be the empty setclazzes - A set of classes that should be analyzed as services, whether they declare
@Service or not. If null this is considered to be the empty setexcludes - A set of implementations that should be excluded from being added. This list is
NOT checked against the clazzes list (the explicit include wins), but instead against the set of
things coming from packages or from the hk2-locator/default filelocatorFiles - A set of locator inhabitant files to search the classpath for to load. If
this value is null then only META-INF/hk2-locator/default files on the classpath will be searched.
If this value is an empty set then no inhabitant files will be loaded. If this value contains
values those will be searched as resources from the jars in the classpath to load the registry withpublic void setVerbosity(boolean verbose)
Copyright © 2009–2020 Oracle Corporation. All rights reserved.