Annotation Interface MockitoSpyBean


@Target(FIELD) @Retention(RUNTIME) @Documented public @interface MockitoSpyBean
Mark a field to trigger a bean override using a Mockito spy, which will wrap the original instance. If no explicit name() is specified, the annotated field's name is interpreted to be the target of the override. In either case, it is required that the target bean is previously registered in the context.

Dependencies that are known to the application context but are not beans (such as those registered directly) will not be found.

Since:
6.2
Author:
Simon Baslé
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The name of the bean to spy.
    boolean
    Indicates that Mockito methods such as verify(mock) should use the target of AOP advised beans, rather than the proxy itself.
    The reset mode to apply to the spied bean.
  • Element Details

    • name

      String name
      The name of the bean to spy.

      If not specified, the name of the annotated field will be used.

      Returns:
      the name of the spied bean
      Default:
      ""
    • reset

      MockReset reset
      The reset mode to apply to the spied bean.

      The default is MockReset.AFTER meaning that spies are automatically reset after each test method is invoked.

      Returns:
      the reset mode
      Default:
      AFTER
    • proxyTargetAware

      boolean proxyTargetAware
      Indicates that Mockito methods such as verify(mock) should use the target of AOP advised beans, rather than the proxy itself.

      Defaults to true.

      If set to false you may need to use the result of AopTestUtils.getUltimateTargetObject(...) when calling Mockito methods.

      Returns:
      true if the target of AOP advised beans is used, or false if the proxy is used directly
      Default:
      true