Skip to content

Commit 9e35eaf

Browse files
committed
Remove unnecessary explicit Mockito.times(1)
1 parent 8e313d0 commit 9e35eaf

File tree

23 files changed

+66
-82
lines changed

23 files changed

+66
-82
lines changed

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private void assertCacheIsUsed(Map<String, Object> parameters, Principal princip
144144
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
145145
Object response = invoker.invoke(context);
146146
assertThat(response).isSameAs(expected);
147-
then(target).should(times(1)).invoke(context);
147+
then(target).should().invoke(context);
148148
Object cachedResponse = invoker.invoke(context);
149149
assertThat(cachedResponse).isSameAs(response);
150150
then(target).shouldHaveNoMoreInteractions();
@@ -202,8 +202,8 @@ void targetInvokedWhenCalledWithAndWithoutPrincipal() {
202202
assertThat(invoker.invoke(authenticatedContext)).isEqualTo(authenticatedResult);
203203
assertThat(invoker.invoke(anonymousContext)).isEqualTo(anonymousResult);
204204
assertThat(invoker.invoke(authenticatedContext)).isEqualTo(authenticatedResult);
205-
then(target).should(times(1)).invoke(anonymousContext);
206-
then(target).should(times(1)).invoke(authenticatedContext);
205+
then(target).should().invoke(anonymousContext);
206+
then(target).should().invoke(authenticatedContext);
207207
}
208208

209209
@Test
@@ -236,10 +236,10 @@ void targetInvokedWithDifferentApiVersion() {
236236
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
237237
Object responseV2 = invoker.invoke(contextV2);
238238
assertThat(responseV2).isSameAs(expectedV2);
239-
then(target).should(times(1)).invoke(contextV2);
239+
then(target).should().invoke(contextV2);
240240
Object responseV3 = invoker.invoke(contextV3);
241241
assertThat(responseV3).isNotSameAs(responseV2);
242-
then(target).should(times(1)).invoke(contextV3);
242+
then(target).should().invoke(contextV3);
243243
}
244244

245245
@Test
@@ -256,10 +256,10 @@ void targetInvokedWithDifferentWebServerNamespace() {
256256
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
257257
Object responseServer = invoker.invoke(contextServer);
258258
assertThat(responseServer).isSameAs(expectedServer);
259-
then(target).should(times(1)).invoke(contextServer);
259+
then(target).should().invoke(contextServer);
260260
Object responseManagement = invoker.invoke(contextManagement);
261261
assertThat(responseManagement).isNotSameAs(responseServer);
262-
then(target).should(times(1)).invoke(contextManagement);
262+
then(target).should().invoke(contextManagement);
263263
}
264264

265265
private static class MonoOperationInvoker implements OperationInvoker {

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jms/JmsHealthIndicatorTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import static org.mockito.BDDMockito.willAnswer;
3535
import static org.mockito.BDDMockito.willThrow;
3636
import static org.mockito.Mockito.mock;
37-
import static org.mockito.Mockito.times;
3837

3938
/**
4039
* Tests for {@link JmsHealthIndicator}.
@@ -56,7 +55,7 @@ void jmsBrokerIsUp() throws JMSException {
5655
Health health = indicator.health();
5756
assertThat(health.getStatus()).isEqualTo(Status.UP);
5857
assertThat(health.getDetails().get("provider")).isEqualTo("JMS test provider");
59-
then(connection).should(times(1)).close();
58+
then(connection).should().close();
6059
}
6160

6261
@Test
@@ -81,7 +80,7 @@ void jmsBrokerCouldNotRetrieveProviderMetadata() throws JMSException {
8180
Health health = indicator.health();
8281
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
8382
assertThat(health.getDetails().get("provider")).isNull();
84-
then(connection).should(times(1)).close();
83+
then(connection).should().close();
8584
}
8685

8786
@Test

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/solr/SolrHealthIndicatorTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void healthWhenSolrStatusUpAndBaseUrlPointsToRootReturnsUp() throws Exception {
5252
given(solrClient.request(any(CoreAdminRequest.class), isNull())).willReturn(mockResponse(0));
5353
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
5454
assertHealth(healthIndicator, Status.UP, 0, "root");
55-
then(solrClient).should(times(1)).request(any(CoreAdminRequest.class), isNull());
55+
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
5656
then(solrClient).shouldHaveNoMoreInteractions();
5757
}
5858

@@ -62,7 +62,7 @@ void healthWhenSolrStatusDownAndBaseUrlPointsToRootReturnsDown() throws Exceptio
6262
given(solrClient.request(any(CoreAdminRequest.class), isNull())).willReturn(mockResponse(400));
6363
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
6464
assertHealth(healthIndicator, Status.DOWN, 400, "root");
65-
then(solrClient).should(times(1)).request(any(CoreAdminRequest.class), isNull());
65+
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
6666
then(solrClient).shouldHaveNoMoreInteractions();
6767
}
6868

@@ -74,8 +74,8 @@ void healthWhenSolrStatusUpAndBaseUrlPointsToParticularCoreReturnsUp() throws Ex
7474
given(solrClient.ping()).willReturn(mockPingResponse(0));
7575
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
7676
assertHealth(healthIndicator, Status.UP, 0, "particular core");
77-
then(solrClient).should(times(1)).request(any(CoreAdminRequest.class), isNull());
78-
then(solrClient).should(times(1)).ping();
77+
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
78+
then(solrClient).should().ping();
7979
then(solrClient).shouldHaveNoMoreInteractions();
8080
}
8181

@@ -87,8 +87,8 @@ void healthWhenSolrStatusDownAndBaseUrlPointsToParticularCoreReturnsDown() throw
8787
given(solrClient.ping()).willReturn(mockPingResponse(400));
8888
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
8989
assertHealth(healthIndicator, Status.DOWN, 400, "particular core");
90-
then(solrClient).should(times(1)).request(any(CoreAdminRequest.class), isNull());
91-
then(solrClient).should(times(1)).ping();
90+
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
91+
then(solrClient).should().ping();
9292
then(solrClient).shouldHaveNoMoreInteractions();
9393
}
9494

@@ -101,7 +101,7 @@ void healthWhenSolrConnectionFailsReturnsDown() throws Exception {
101101
Health health = healthIndicator.health();
102102
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
103103
assertThat((String) health.getDetails().get("error")).contains("Connection failed");
104-
then(solrClient).should(times(1)).request(any(CoreAdminRequest.class), isNull());
104+
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
105105
then(solrClient).shouldHaveNoMoreInteractions();
106106
}
107107

@@ -113,8 +113,8 @@ void healthWhenMakingMultipleCallsRemembersStatusStrategy() throws Exception {
113113
given(solrClient.ping()).willReturn(mockPingResponse(0));
114114
SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
115115
healthIndicator.health();
116-
then(solrClient).should(times(1)).request(any(CoreAdminRequest.class), isNull());
117-
then(solrClient).should(times(1)).ping();
116+
then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
117+
then(solrClient).should().ping();
118118
then(solrClient).shouldHaveNoMoreInteractions();
119119
healthIndicator.health();
120120
then(solrClient).should(times(2)).ping();

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mail/MailSenderAutoConfigurationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import static org.mockito.BDDMockito.then;
4242
import static org.mockito.Mockito.mock;
4343
import static org.mockito.Mockito.never;
44-
import static org.mockito.Mockito.times;
4544

4645
/**
4746
* Tests for {@link MailSenderAutoConfiguration}.
@@ -225,7 +224,7 @@ void connectionOnStartup() {
225224
.withPropertyValues("spring.mail.host:10.0.0.23", "spring.mail.test-connection:true").run((context) -> {
226225
assertThat(context).hasSingleBean(JavaMailSenderImpl.class);
227226
JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class);
228-
then(mailSender).should(times(1)).testConnection();
227+
then(mailSender).should().testConnection();
229228
});
230229
}
231230

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import static org.mockito.BDDMockito.given;
3939
import static org.mockito.BDDMockito.then;
4040
import static org.mockito.Mockito.mock;
41-
import static org.mockito.Mockito.times;
4241

4342
/**
4443
* Hazelcast specific tests for {@link SessionAutoConfiguration}.
@@ -81,7 +80,7 @@ private void validateDefaultConfig(AssertableWebApplicationContext context) {
8180
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
8281
(int) new ServerProperties().getServlet().getSession().getTimeout().getSeconds());
8382
HazelcastInstance hazelcastInstance = context.getBean(HazelcastInstance.class);
84-
then(hazelcastInstance).should(times(1)).getMap("spring:session:sessions");
83+
then(hazelcastInstance).should().getMap("spring:session:sessions");
8584
}
8685

8786
@Test
@@ -90,7 +89,7 @@ void customMapName() {
9089
"spring.session.hazelcast.map-name=foo:bar:biz").run((context) -> {
9190
validateSessionRepository(context, HazelcastIndexedSessionRepository.class);
9291
HazelcastInstance hazelcastInstance = context.getBean(HazelcastInstance.class);
93-
then(hazelcastInstance).should(times(1)).getMap("foo:bar:biz");
92+
then(hazelcastInstance).should().getMap("foo:bar:biz");
9493
});
9594
}
9695

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/template/TemplateAvailabilityProvidersTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ void getProviderShouldCacheMatchResult() {
166166
.willReturn(true);
167167
this.providers.getProvider(this.view, this.environment, this.classLoader, this.resourceLoader);
168168
this.providers.getProvider(this.view, this.environment, this.classLoader, this.resourceLoader);
169-
then(this.provider).should(times(1)).isTemplateAvailable(this.view, this.environment, this.classLoader,
169+
then(this.provider).should().isTemplateAvailable(this.view, this.environment, this.classLoader,
170170
this.resourceLoader);
171171
}
172172

173173
@Test
174174
void getProviderShouldCacheNoMatchResult() {
175175
this.providers.getProvider(this.view, this.environment, this.classLoader, this.resourceLoader);
176176
this.providers.getProvider(this.view, this.environment, this.classLoader, this.resourceLoader);
177-
then(this.provider).should(times(1)).isTemplateAvailable(this.view, this.environment, this.classLoader,
177+
then(this.provider).should().isTemplateAvailable(this.view, this.environment, this.classLoader,
178178
this.resourceLoader);
179179
}
180180

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidatorAdapterTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import static org.mockito.BDDMockito.then;
3737
import static org.mockito.Mockito.mock;
3838
import static org.mockito.Mockito.never;
39-
import static org.mockito.Mockito.times;
4039

4140
/**
4241
* Tests for {@link ValidatorAdapter}.
@@ -64,11 +63,11 @@ void wrapLocalValidatorFactoryBean() {
6463
void wrapperInvokesCallbackOnNonManagedBean() {
6564
this.contextRunner.withUserConfiguration(NonManagedBeanConfig.class).run((context) -> {
6665
LocalValidatorFactoryBean validator = context.getBean(NonManagedBeanConfig.class).validator;
67-
then(validator).should(times(1)).setApplicationContext(any(ApplicationContext.class));
68-
then(validator).should(times(1)).afterPropertiesSet();
66+
then(validator).should().setApplicationContext(any(ApplicationContext.class));
67+
then(validator).should().afterPropertiesSet();
6968
then(validator).should(never()).destroy();
7069
context.close();
71-
then(validator).should(times(1)).destroy();
70+
then(validator).should().destroy();
7271
});
7372
}
7473

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void configureHttpRequestDecoder() {
127127
nettyProperties.setMaxInitialLineLength(DataSize.ofKilobytes(32));
128128
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
129129
this.customizer.customize(factory);
130-
then(factory).should(times(1)).addServerCustomizers(this.customizerCaptor.capture());
130+
then(factory).should().addServerCustomizers(this.customizerCaptor.capture());
131131
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getValue();
132132
HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
133133
HttpRequestDecoderSpec decoder = httpServer.configuration().decoder();

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryAutoConfigurationTests.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import static org.mockito.BDDMockito.given;
5656
import static org.mockito.BDDMockito.then;
5757
import static org.mockito.Mockito.mock;
58-
import static org.mockito.Mockito.times;
5958

6059
/**
6160
* Tests for {@link ReactiveWebServerFactoryAutoConfiguration}.
@@ -129,7 +128,7 @@ void tomcatConnectorCustomizerBeanIsAddedToFactory() {
129128
TomcatConnectorCustomizer customizer = context.getBean("connectorCustomizer",
130129
TomcatConnectorCustomizer.class);
131130
assertThat(factory.getTomcatConnectorCustomizers()).contains(customizer);
132-
then(customizer).should(times(1)).customize(any(Connector.class));
131+
then(customizer).should().customize(any(Connector.class));
133132
});
134133
}
135134

@@ -146,7 +145,7 @@ void tomcatConnectorCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
146145
TomcatConnectorCustomizer customizer = context.getBean("connectorCustomizer",
147146
TomcatConnectorCustomizer.class);
148147
assertThat(factory.getTomcatConnectorCustomizers()).contains(customizer);
149-
then(customizer).should(times(1)).customize(any(Connector.class));
148+
then(customizer).should().customize(any(Connector.class));
150149
});
151150
}
152151

@@ -162,7 +161,7 @@ void tomcatContextCustomizerBeanIsAddedToFactory() {
162161
TomcatReactiveWebServerFactory factory = context.getBean(TomcatReactiveWebServerFactory.class);
163162
TomcatContextCustomizer customizer = context.getBean("contextCustomizer", TomcatContextCustomizer.class);
164163
assertThat(factory.getTomcatContextCustomizers()).contains(customizer);
165-
then(customizer).should(times(1)).customize(any(Context.class));
164+
then(customizer).should().customize(any(Context.class));
166165
});
167166
}
168167

@@ -178,7 +177,7 @@ void tomcatContextCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
178177
TomcatReactiveWebServerFactory factory = context.getBean(TomcatReactiveWebServerFactory.class);
179178
TomcatContextCustomizer customizer = context.getBean("contextCustomizer", TomcatContextCustomizer.class);
180179
assertThat(factory.getTomcatContextCustomizers()).contains(customizer);
181-
then(customizer).should(times(1)).customize(any(Context.class));
180+
then(customizer).should().customize(any(Context.class));
182181
});
183182
}
184183

@@ -195,7 +194,7 @@ void tomcatProtocolHandlerCustomizerBeanIsAddedToFactory() {
195194
TomcatProtocolHandlerCustomizer<?> customizer = context.getBean("protocolHandlerCustomizer",
196195
TomcatProtocolHandlerCustomizer.class);
197196
assertThat(factory.getTomcatProtocolHandlerCustomizers()).contains(customizer);
198-
then(customizer).should(times(1)).customize(any());
197+
then(customizer).should().customize(any());
199198
});
200199
}
201200

@@ -212,7 +211,7 @@ void tomcatProtocolHandlerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnc
212211
TomcatProtocolHandlerCustomizer<?> customizer = context.getBean("protocolHandlerCustomizer",
213212
TomcatProtocolHandlerCustomizer.class);
214213
assertThat(factory.getTomcatProtocolHandlerCustomizers()).contains(customizer);
215-
then(customizer).should(times(1)).customize(any());
214+
then(customizer).should().customize(any());
216215
});
217216
}
218217

@@ -239,7 +238,7 @@ void jettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
239238
JettyReactiveWebServerFactory factory = context.getBean(JettyReactiveWebServerFactory.class);
240239
JettyServerCustomizer customizer = context.getBean("serverCustomizer", JettyServerCustomizer.class);
241240
assertThat(factory.getServerCustomizers()).contains(customizer);
242-
then(customizer).should(times(1)).customize(any(Server.class));
241+
then(customizer).should().customize(any(Server.class));
243242
});
244243
}
245244

@@ -267,7 +266,7 @@ void undertowBuilderCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
267266
UndertowBuilderCustomizer customizer = context.getBean("builderCustomizer",
268267
UndertowBuilderCustomizer.class);
269268
assertThat(factory.getBuilderCustomizers()).contains(customizer);
270-
then(customizer).should(times(1)).customize(any(Builder.class));
269+
then(customizer).should().customize(any(Builder.class));
271270
});
272271
}
273272

@@ -294,7 +293,7 @@ void nettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
294293
NettyReactiveWebServerFactory factory = context.getBean(NettyReactiveWebServerFactory.class);
295294
NettyServerCustomizer customizer = context.getBean("serverCustomizer", NettyServerCustomizer.class);
296295
assertThat(factory.getServerCustomizers()).contains(customizer);
297-
then(customizer).should(times(1)).apply(any(HttpServer.class));
296+
then(customizer).should().apply(any(HttpServer.class));
298297
});
299298
}
300299

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorAutoConfigurationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import static org.mockito.ArgumentMatchers.any;
3737
import static org.mockito.BDDMockito.then;
3838
import static org.mockito.Mockito.mock;
39-
import static org.mockito.Mockito.times;
4039

4140
/**
4241
* Tests for {@link ClientHttpConnectorAutoConfiguration}
@@ -95,7 +94,7 @@ void shouldCreateHttpClientBeans() {
9594
WebClientCustomizer clientCustomizer = context.getBean(WebClientCustomizer.class);
9695
WebClient.Builder builder = mock(WebClient.Builder.class);
9796
clientCustomizer.customize(builder);
98-
then(builder).should(times(1)).clientConnector(any(ReactorClientHttpConnector.class));
97+
then(builder).should().clientConnector(any(ReactorClientHttpConnector.class));
9998
});
10099
}
101100

@@ -107,7 +106,7 @@ void shouldNotOverrideCustomClientConnector() {
107106
WebClientCustomizer clientCustomizer = context.getBean(WebClientCustomizer.class);
108107
WebClient.Builder builder = mock(WebClient.Builder.class);
109108
clientCustomizer.customize(builder);
110-
then(builder).should(times(1)).clientConnector(any(ClientHttpConnector.class));
109+
then(builder).should().clientConnector(any(ClientHttpConnector.class));
111110
});
112111
}
113112

0 commit comments

Comments
 (0)