com.opensymphony.xwork2.mock

## Class MockContainer

- java.lang.Object
- - com.opensymphony.xwork2.mock.MockContainer

- All Implemented Interfaces:
    Container, Serializable

      public class MockContainer
      extends Object
      implements Container

  Mock implementation to be used in unittests
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from interface com.opensymphony.xwork2.inject.Container

      `DEFAULT_NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MockContainer()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> T` | `getInstance(Class<T> type)` Convenience method. Equivalent to `getInstance(type, DEFAULT_NAME)`.
    `<T> T` | `getInstance(Class<T> type, String name)` Gets an instance of the given dependency which was declared in `ContainerBuilder`.
    `Set<String>` | `getInstanceNames(Class<?> type)` Gets a set of all registered names for the given type
    `<T> T` | `inject(Class<T> implementation)` Creates and injects a new instance of type `implementation`.
    `void` | `inject(Object o)` Injects dependencies into the fields and methods of an existing object.
    `void` | `removeScopeStrategy()` Removes the scope strategy for the current thread.
    `void` | `setScopeStrategy(Scope.Strategy scopeStrategy)` Sets the scope strategy for the current thread.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MockContainer

          public MockContainer()

  - ### Method Detail

    - #### 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`

Copyright © 2000–2022 Apache Software Foundation. All rights reserved.