Skip to content

Commit 3625930

Browse files
committed
Merge branch '3.3.x'
Closes gh-43053
2 parents 796ce3d + 4900ca1 commit 3625930

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ protected final Object createSpyIfNecessary(Object bean, String beanName) throws
336336
SpyDefinition definition = this.spies.get(beanName);
337337
if (definition != null) {
338338
bean = definition.createSpy(beanName, bean);
339+
this.mockitoBeans.add(bean);
339340
}
340341
return bean;
341342
}

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListenerTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ class ResetMocksTestExecutionListenerTests {
5050
@Autowired
5151
private ApplicationContext context;
5252

53+
@SpyBean
54+
ToSpy spied;
55+
5356
@Test
5457
void test001() {
5558
given(getMock("none").greeting()).willReturn("none");
5659
given(getMock("before").greeting()).willReturn("before");
5760
given(getMock("after").greeting()).willReturn("after");
5861
given(getMock("fromFactoryBean").greeting()).willReturn("fromFactoryBean");
5962
assertThat(this.context.getBean(NonSingletonFactoryBean.class).getObjectInvocations).isEqualTo(0);
63+
given(this.spied.action()).willReturn("spied");
6064
}
6165

6266
@Test
@@ -66,6 +70,7 @@ void test002() {
6670
assertThat(getMock("after").greeting()).isNull();
6771
assertThat(getMock("fromFactoryBean").greeting()).isNull();
6872
assertThat(this.context.getBean(NonSingletonFactoryBean.class).getObjectInvocations).isEqualTo(0);
73+
assertThat(this.spied.action()).isNull();
6974
}
7075

7176
ExampleService getMock(String name) {
@@ -119,6 +124,11 @@ NonSingletonFactoryBean nonSingletonFactoryBean() {
119124
return new NonSingletonFactoryBean();
120125
}
121126

127+
@Bean
128+
ToSpyFactoryBean toSpyFactoryBean() {
129+
return new ToSpyFactoryBean();
130+
}
131+
122132
}
123133

124134
static class BrokenFactoryBean implements FactoryBean<String> {
@@ -161,6 +171,14 @@ public boolean isSingleton() {
161171

162172
}
163173

174+
static class ToSpy {
175+
176+
String action() {
177+
return null;
178+
}
179+
180+
}
181+
164182
static class NonSingletonFactoryBean implements FactoryBean<ExampleService> {
165183

166184
private int getObjectInvocations = 0;
@@ -183,4 +201,18 @@ public boolean isSingleton() {
183201

184202
}
185203

204+
static class ToSpyFactoryBean implements FactoryBean<ToSpy> {
205+
206+
@Override
207+
public ToSpy getObject() throws Exception {
208+
return new ToSpy();
209+
}
210+
211+
@Override
212+
public Class<?> getObjectType() {
213+
return ToSpy.class;
214+
}
215+
216+
}
217+
186218
}

0 commit comments

Comments
 (0)