File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
framework-docs/modules/ROOT/pages/testing/annotations/integration-spring
spring-test/src/main/java/org/springframework/test/context/bean/override/mockito Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,17 @@ exactly one candidate bean exists.
77
77
78
78
[TIP]
79
79
====
80
+ As stated in the documentation for Mockito, there are times when using `Mockito.when()` is
81
+ inappropriate for stubbing a spy – for example, if calling a real method on a spy results
82
+ in undesired side effects.
83
+
84
+ To avoid such undesired side effects, consider using
85
+ `Mockito.doReturn(...).when(spy)...`, `Mockito.doThrow(...).when(spy)...`,
86
+ `Mockito.doNothing().when(spy)...`, and similar methods.
87
+ ====
88
+
89
+ [NOTE]
90
+ ====
80
91
Only _singleton_ beans can be overridden. Any attempt to override a non-singleton bean
81
92
will result in an exception.
82
93
Original file line number Diff line number Diff line change 67
67
* {@link org.springframework.beans.factory.config.ConfigurableListableBeanFactory#registerResolvableDependency(Class, Object)
68
68
* registered directly} as resolvable dependencies.
69
69
*
70
+ * <p><strong>NOTE</strong>: As stated in the documentation for Mockito, there are
71
+ * times when using {@code Mockito.when()} is inappropriate for stubbing a spy
72
+ * — for example, if calling a real method on a spy results in undesired
73
+ * side effects. To avoid such undesired side effects, consider using
74
+ * {@link org.mockito.Mockito#doReturn(Object) Mockito.doReturn(...).when(spy)...},
75
+ * {@link org.mockito.Mockito#doThrow(Class) Mockito.doThrow(...).when(spy)...},
76
+ * {@link org.mockito.Mockito#doNothing() Mockito.doNothing().when(spy)...}, and
77
+ * similar methods.
78
+ *
70
79
* <p><strong>WARNING</strong>: Using {@code @MockitoSpyBean} in conjunction with
71
80
* {@code @ContextHierarchy} can lead to undesirable results since each
72
81
* {@code @MockitoSpyBean} will be applied to all context hierarchy levels by default.
You can’t perform that action at this time.
0 commit comments