Annotation Interface MockitoSpyBean
By default, the bean to spy is inferred from the type of the annotated
field. If multiple candidates exist, a @Qualifier annotation can be
used to help disambiguate. In the absence of a @Qualifier annotation,
the name of the annotated field will be used as a fallback qualifier.
Alternatively, you can explicitly specify a bean name to spy by setting the
value or name attribute. If a bean name is
specified, it is required that a target bean with that name has been previously
registered in the application context.
A spy cannot be created for components which are known to the application
context but are not beans — for example, components
registered directly as resolvable dependencies.
NOTE: Only singleton beans can be spied. Any attempt to create a spy for a non-singleton bean will result in an exception.
- Since:
- 6.2
- Author:
- Simon Baslé, Sam Brannen
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionName of the bean to spy.booleanIndicates that Mockito methods such asverify(mock)should use thetargetof AOP advised beans, rather than the proxy itself.The reset mode to apply to the spied bean.Alias forname().
-
Element Details
-
value
Alias forname().Intended to be used when no other attributes are needed — for example,
@MockitoSpyBean("customBeanName").- See Also:
- Default:
- ""
-
name
Name of the bean to spy.If left unspecified, the bean to spy is selected according to the annotated field's type, taking qualifiers into account if necessary. See the class-level documentation for details.
- See Also:
- Default:
- ""
-
reset
MockReset resetThe reset mode to apply to the spied bean.The default is
MockReset.AFTERmeaning that spies are automatically reset after each test method is invoked.- Returns:
- the reset mode
- Default:
- AFTER
-
proxyTargetAware
boolean proxyTargetAwareIndicates that Mockito methods such asverify(mock)should use thetargetof AOP advised beans, rather than the proxy itself.Defaults to
true.If set to
falseyou may need to use the result ofAopTestUtils.getUltimateTargetObject(...)when calling Mockito methods.- Returns:
trueif the target of AOP advised beans is used, orfalseif the proxy is used directly
- Default:
- true
-