Package org.apache.struts2.mock
Class MockContainer
java.lang.Object
org.apache.struts2.mock.MockContainer
- All Implemented Interfaces:
Serializable
,Container
Mock implementation to be used in unittests
- See Also:
-
Field Summary
Fields inherited from interface org.apache.struts2.inject.Container
DEFAULT_NAME
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> T
getInstance
(Class<T> type) Convenience method. Equivalent togetInstance(type, DEFAULT_NAME)
.<T> T
getInstance
(Class<T> type, String name) Gets an instance of the given dependency which was declared inContainerBuilder
.getInstanceNames
(Class<?> type) Gets a set of all registered names for the given type<T> T
Creates and injects a new instance of typeimplementation
.void
Injects dependencies into the fields and methods of an existing object.void
Removes the scope strategy for the current thread.void
setScopeStrategy
(Scope.Strategy scopeStrategy) Sets the scope strategy for the current thread.
-
Constructor Details
-
MockContainer
public MockContainer()
-
-
Method Details
-
inject
Description copied from interface:Container
Injects dependencies into the fields and methods of an existing object. -
inject
Description copied from interface:Container
Creates and injects a new instance of typeimplementation
. -
getInstance
Description copied from interface:Container
Gets an instance of the given dependency which was declared inContainerBuilder
.- Specified by:
getInstance
in interfaceContainer
- Type Parameters:
T
- type- Parameters:
type
- of dependencyname
- of dependency- Returns:
- instance
-
getInstance
Description copied from interface:Container
Convenience method. Equivalent togetInstance(type, DEFAULT_NAME)
.- Specified by:
getInstance
in interfaceContainer
- Type Parameters:
T
- type- Parameters:
type
- of dependency- Returns:
- instance
-
getInstanceNames
Description copied from interface:Container
Gets a set of all registered names for the given type- Specified by:
getInstanceNames
in interfaceContainer
- Parameters:
type
- The instance type- Returns:
- A set of registered names or empty set if no instances are registered for that type
-
setScopeStrategy
Description copied from interface:Container
Sets the scope strategy for the current thread.- Specified by:
setScopeStrategy
in interfaceContainer
- Parameters:
scopeStrategy
- scope strategy
-
removeScopeStrategy
public void removeScopeStrategy()Description copied from interface:Container
Removes the scope strategy for the current thread.- Specified by:
removeScopeStrategy
in interfaceContainer
-