Skip to content

Commit b019ebe

Browse files
committed
Document that @⁠MockitoSpyBean cannot spy on a scoped proxy
See gh-35722
1 parent c0c94d5 commit b019ebe

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

framework-docs/modules/ROOT/pages/testing/annotations/integration-spring/annotation-mockitobean.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ will be replaced with a singleton mock of the type of object created by the `Fac
102102
103103
Similarly, when using `@MockitoSpyBean` to create a spy for a `FactoryBean`, a spy will
104104
be created for the object created by the `FactoryBean`, not for the `FactoryBean` itself.
105+
106+
Furthermore, `@MockitoSpyBean` cannot be used to spy on a scoped proxy — for example, a
107+
bean annotated with `@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)`. Any attempt to do
108+
so will fail with an exception.
105109
====
106110

107111
[NOTE]

spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBean.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@
9494
* be created for the object created by the {@code FactoryBean}, not for the
9595
* {@code FactoryBean} itself.
9696
*
97+
* <p><strong>WARNING</strong>: {@code @MockitoSpyBean} cannot be used to spy on
98+
* a scoped proxy &mdash; for example, a bean annotated with
99+
* {@link org.springframework.context.annotation.Scope
100+
* &#64;Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)}. Any attempt to do so will
101+
* fail with an exception.
102+
*
97103
* <p>There are no restrictions on the visibility of a {@code @MockitoSpyBean} field.
98104
* Such fields can therefore be {@code public}, {@code protected}, package-private
99105
* (default visibility), or {@code private} depending on the needs or coding

0 commit comments

Comments
 (0)