Annotation Interface MockitoBean
Mark a field to trigger a bean override using a Mockito mock. If no explicit
name() is specified, the annotated field's name is interpreted to
be the target of the override. In either case, if no existing bean is defined
a new one will be added to the context.
Dependencies that are known to the application context but are not beans
(such as those
registered directly) will not be found, and a mocked bean will be added to
the context alongside the existing dependency.
- Since:
- 6.2
- Author:
- Simon Baslé
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionorg.mockito.AnswersTheAnswerstype to use on the mock.Class<?>[]Extra interfaces that should also be declared on the mock.The name of the bean to register or replace.The reset mode to apply to the mock.booleanWhether the generated mock is serializable.
-
Element Details
-
name
String nameThe name of the bean to register or replace.If not specified, the name of the annotated field will be used.
- Returns:
- the name of the mocked bean
- Default:
- ""
-
extraInterfaces
Class<?>[] extraInterfacesExtra interfaces that should also be declared on the mock.Defaults to none.
- Returns:
- any extra interfaces
- See Also:
-
MockSettings.extraInterfaces(Class...)
- Default:
- {}
-
answers
org.mockito.Answers answersTheAnswerstype to use on the mock.Defaults to
Answers.RETURNS_DEFAULTS.- Returns:
- the answer type
- Default:
- RETURNS_DEFAULTS
-
serializable
boolean serializableWhether the generated mock is serializable.Defaults to
false.- Returns:
trueif the mock is serializable- See Also:
-
MockSettings.serializable()
- Default:
- false
-
reset
MockReset resetThe reset mode to apply to the mock.The default is
MockReset.AFTERmeaning that mocks are automatically reset after each test method is invoked.- Returns:
- the reset mode
- Default:
- AFTER
-