Class MockContainer

java.lang.Object
org.apache.struts2.mock.MockContainer
All Implemented Interfaces:
Serializable, Container

public class MockContainer extends Object implements Container
Mock implementation to be used in unittests
See Also:
  • Constructor Details

    • MockContainer

      public MockContainer()
  • Method Details

    • inject

      public void inject(Object o)
      Description copied from interface: Container
      Injects dependencies into the fields and methods of an existing object.
      Specified by:
      inject in interface Container
      Parameters:
      o - object to inject
    • inject

      public <T> T inject(Class<T> implementation)
      Description copied from interface: Container
      Creates and injects a new instance of type implementation.
      Specified by:
      inject in interface Container
      Type Parameters:
      T - type
      Parameters:
      implementation - of dependency
      Returns:
      instance
    • getInstance

      public <T> T getInstance(Class<T> type, String name)
      Description copied from interface: Container
      Gets an instance of the given dependency which was declared in ContainerBuilder.
      Specified by:
      getInstance in interface Container
      Type Parameters:
      T - type
      Parameters:
      type - of dependency
      name - of dependency
      Returns:
      instance
    • getInstance

      public <T> T getInstance(Class<T> type)
      Description copied from interface: Container
      Convenience method. Equivalent to getInstance(type, DEFAULT_NAME).
      Specified by:
      getInstance in interface Container
      Type Parameters:
      T - type
      Parameters:
      type - of dependency
      Returns:
      instance
    • getInstanceNames

      public Set<String> getInstanceNames(Class<?> type)
      Description copied from interface: Container
      Gets a set of all registered names for the given type
      Specified by:
      getInstanceNames in interface Container
      Parameters:
      type - The instance type
      Returns:
      A set of registered names or empty set if no instances are registered for that type
    • setScopeStrategy

      public void setScopeStrategy(Scope.Strategy scopeStrategy)
      Description copied from interface: Container
      Sets the scope strategy for the current thread.
      Specified by:
      setScopeStrategy in interface Container
      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 interface Container