Interface MockitoPlugins


@NotExtensible public interface MockitoPlugins
Instance of this interface is available via MockitoFramework.getPlugins(). This object enables framework integrators to get access to default Mockito plugins.

Example use case: one needs to implement custom MockMaker and delegate some behavior to the default Mockito implementation. The interface was introduced to help framework integrations.

Since:
2.10.0
  • Method Details

    • getDefaultPlugin

      <T> T getDefaultPlugin(Class<T> pluginType)
      Returns the default plugin implementation used by Mockito. Mockito plugins are stateless so it is recommended to keep hold of the returned plugin implementation rather than calling this method multiple times. Each time this method is called, new instance of the plugin is created.
      Parameters:
      pluginType - type of the plugin, for example MockMaker.
      Returns:
      the plugin instance
      Since:
      2.10.0
    • getInlineMockMaker

      @Deprecated(since="5.6.0", forRemoval=true) MockMaker getInlineMockMaker()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getMockMaker(String) with MockMakers.INLINE instead.
      Returns inline mock maker, an optional mock maker that is bundled with Mockito distribution. This method is needed because getDefaultPlugin(Class) does not provide an instance of inline mock maker. Creates new instance each time is called so it is recommended to keep hold of the resulting object for future invocations. For more information about inline mock maker see the javadoc for main Mockito class.
      Returns:
      instance of inline mock maker
      Since:
      2.10.0
    • getMockMaker

      default MockMaker getMockMaker(String mockMaker)
      Returns MockMaker instance used by Mockito with the passed name mockMaker.

      This will return the instance used by Mockito itself, not a new instance of it.

      This method can be used to increase the interop of mocks created by Mockito and other libraries using Mockito mock maker API.

      Parameters:
      mockMaker - the name of the mock maker or null to retrieve the default mock maker
      Returns:
      instance of the mock maker
      Throws:
      IllegalStateException - if a mock maker with the name is not found
      Since:
      5.6.0