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, a target bean is selected according to the class of the annotated field, and there must be exactly one such candidate bean. A @Qualifier annotation can be used to help disambiguate. If a name() is specified, it is required that a target bean of that name has been previously registered in the application 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 left unspecified, the bean to override is selected according to the annotated field's type.

      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