Skip to content

Commit 663cae1

Browse files
committed
Note behaviour of @MockBean and @SpyBean with non-bean dependencies
Closes gh-10381
1 parent f01bb8e commit 663cae1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockBean.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,8 +37,12 @@
3737
* or test classes that are {@link RunWith @RunWith} the {@link SpringRunner}.
3838
* <p>
3939
* Mocks can be registered by type or by {@link #name() bean name}. Any existing single
40-
* bean of the same type defined in the context will be replaced by the mock, if no
41-
* existing bean is defined a new one will be added.
40+
* bean of the same type defined in the context will be replaced by the mock. If no
41+
* existing bean is defined a new one will be added. Dependencies that are known to the
42+
* application context but are not beans (such as those
43+
* {@link org.springframework.beans.factory.config.ConfigurableListableBeanFactory#registerResolvableDependency(Class, Object)
44+
* registered directly} ) will not be found and a mocked bean will be added to the context
45+
* alongside the existing dependency.
4246
* <p>
4347
* When {@code @MockBean} is used on a field, as well as being registered in the
4448
* application context, the mock will also be injected into the field. Typical usage might

spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/SpyBean.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,11 @@
3838
* <p>
3939
* Spies can be applied by type or by {@link #name() bean name}. All beans in the context
4040
* of the same type will be wrapped with the spy. If no existing bean is defined a new one
41-
* will be added.
41+
* will be added. Dependencies that are known to the application context but are not beans
42+
* (such as those
43+
* {@link org.springframework.beans.factory.config.ConfigurableListableBeanFactory#registerResolvableDependency(Class, Object)
44+
* registered directly} ) will not be found and a spied bean will be added to the context
45+
* alongside the existing dependency.
4246
* <p>
4347
* When {@code @SpyBean} is used on a field, as well as being registered in the
4448
* application context, the spy will also be injected into the field. Typical usage might

0 commit comments

Comments
 (0)