Skip to content

Commit bd2e992

Browse files
committed
Merge pull request #29178 from quaff
* pr/29178: Polish "Enforce use of BDDMockito" Enforce use of BDDMockito Closes gh-29178
2 parents f60af4d + 7f17f81 commit bd2e992

File tree

194 files changed

+1234
-1258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+1234
-1258
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundrySecurityInterceptorTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -35,7 +35,7 @@
3535

3636
import static org.assertj.core.api.Assertions.assertThat;
3737
import static org.mockito.BDDMockito.given;
38-
import static org.mockito.Mockito.verify;
38+
import static org.mockito.BDDMockito.then;
3939

4040
/**
4141
* Tests for {@link CloudFoundrySecurityInterceptor}.
@@ -115,7 +115,7 @@ void preHandleSuccessfulWithFullAccess() {
115115
given(this.securityService.getAccessLevel(accessToken, "my-app-id")).willReturn(AccessLevel.FULL);
116116
SecurityResponse response = this.interceptor.preHandle(this.request, EndpointId.of("test"));
117117
ArgumentCaptor<Token> tokenArgumentCaptor = ArgumentCaptor.forClass(Token.class);
118-
verify(this.tokenValidator).validate(tokenArgumentCaptor.capture());
118+
then(this.tokenValidator).should().validate(tokenArgumentCaptor.capture());
119119
Token token = tokenArgumentCaptor.getValue();
120120
assertThat(token.toString()).isEqualTo(accessToken);
121121
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK);
@@ -129,7 +129,7 @@ void preHandleSuccessfulWithRestrictedAccess() {
129129
given(this.securityService.getAccessLevel(accessToken, "my-app-id")).willReturn(AccessLevel.RESTRICTED);
130130
SecurityResponse response = this.interceptor.preHandle(this.request, EndpointId.of("info"));
131131
ArgumentCaptor<Token> tokenArgumentCaptor = ArgumentCaptor.forClass(Token.class);
132-
verify(this.tokenValidator).validate(tokenArgumentCaptor.capture());
132+
then(this.tokenValidator).should().validate(tokenArgumentCaptor.capture());
133133
Token token = tokenArgumentCaptor.getValue();
134134
assertThat(token.toString()).isEqualTo(accessToken);
135135
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK);

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/TokenValidatorTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -33,7 +33,6 @@
3333
import org.junit.jupiter.api.Test;
3434
import org.junit.jupiter.api.extension.ExtendWith;
3535
import org.mockito.Mock;
36-
import org.mockito.Mockito;
3736
import org.mockito.junit.jupiter.MockitoExtension;
3837

3938
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException;
@@ -46,7 +45,8 @@
4645
import static org.assertj.core.api.Assertions.assertThat;
4746
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4847
import static org.mockito.BDDMockito.given;
49-
import static org.mockito.Mockito.verify;
48+
import static org.mockito.BDDMockito.then;
49+
import static org.mockito.Mockito.never;
5050

5151
/**
5252
* Tests for {@link TokenValidator}.
@@ -109,7 +109,7 @@ void validateTokenWhenKidValidationSucceedsInTheSecondAttempt() throws Exception
109109
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
110110
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
111111
this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes())));
112-
verify(this.securityService).fetchTokenKeys();
112+
then(this.securityService).should().fetchTokenKeys();
113113
}
114114

115115
@Test
@@ -119,7 +119,7 @@ void validateTokenShouldFetchTokenKeysIfNull() throws Exception {
119119
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
120120
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
121121
this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes())));
122-
verify(this.securityService).fetchTokenKeys();
122+
then(this.securityService).should().fetchTokenKeys();
123123
}
124124

125125
@Test
@@ -129,7 +129,7 @@ void validateTokenWhenValidShouldNotFetchTokenKeys() throws Exception {
129129
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
130130
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
131131
this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes())));
132-
verify(this.securityService, Mockito.never()).fetchTokenKeys();
132+
then(this.securityService).should(never()).fetchTokenKeys();
133133
}
134134

135135
@Test

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -35,8 +35,8 @@
3535
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3636

3737
import static org.assertj.core.api.Assertions.assertThat;
38+
import static org.mockito.BDDMockito.then;
3839
import static org.mockito.Mockito.mock;
39-
import static org.mockito.Mockito.verify;
4040

4141
/**
4242
* Tests for {@link JmxEndpointAutoConfiguration}.
@@ -72,7 +72,7 @@ void jmxEndpointWithCustomEndpointObjectNameFactory() {
7272
.withBean(EndpointObjectNameFactory.class, () -> factory).run((context) -> {
7373
ArgumentCaptor<ExposableJmxEndpoint> argumentCaptor = ArgumentCaptor
7474
.forClass(ExposableJmxEndpoint.class);
75-
verify(factory).getObjectName(argumentCaptor.capture());
75+
then(factory).should().getObjectName(argumentCaptor.capture());
7676
ExposableJmxEndpoint jmxEndpoint = argumentCaptor.getValue();
7777
assertThat(jmxEndpoint.getEndpointId().toLowerCaseString()).isEqualTo("test");
7878
});

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AuditEventsEndpointDocumentationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -33,7 +33,7 @@
3333

3434
import static org.mockito.ArgumentMatchers.any;
3535
import static org.mockito.BDDMockito.given;
36-
import static org.mockito.Mockito.verify;
36+
import static org.mockito.BDDMockito.then;
3737
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
3838
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
3939
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
@@ -83,7 +83,7 @@ void filteredAuditEvents() throws Exception {
8383
"Restricts the events to those with the given principal. Optional."),
8484
parameterWithName("type")
8585
.description("Restricts the events to those with the given type. Optional."))));
86-
verify(this.repository).find("alice", now.toInstant(), "logout");
86+
then(this.repository).should().find("alice", now.toInstant(), "logout");
8787
}
8888

8989
@Configuration(proxyBeanMethods = false)

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/LoggersEndpointDocumentationTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -40,7 +40,7 @@
4040
import org.springframework.restdocs.payload.JsonFieldType;
4141

4242
import static org.mockito.BDDMockito.given;
43-
import static org.mockito.Mockito.verify;
43+
import static org.mockito.BDDMockito.then;
4444
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
4545
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
4646
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
@@ -114,7 +114,7 @@ void setLogLevel() throws Exception {
114114
.andExpect(status().isNoContent())
115115
.andDo(MockMvcRestDocumentation.document("loggers/set", requestFields(fieldWithPath("configuredLevel")
116116
.description("Level for the logger. May be omitted to clear the level.").optional())));
117-
verify(this.loggingSystem).setLogLevel("com.example", LogLevel.DEBUG);
117+
then(this.loggingSystem).should().setLogLevel("com.example", LogLevel.DEBUG);
118118
}
119119

120120
@Test
@@ -127,8 +127,8 @@ void setLogLevelOfLoggerGroup() throws Exception {
127127
requestFields(fieldWithPath("configuredLevel").description(
128128
"Level for the logger group. May be omitted to clear the level of the loggers.")
129129
.optional())));
130-
verify(this.loggingSystem).setLogLevel("test.member1", LogLevel.DEBUG);
131-
verify(this.loggingSystem).setLogLevel("test.member2", LogLevel.DEBUG);
130+
then(this.loggingSystem).should().setLogLevel("test.member1", LogLevel.DEBUG);
131+
then(this.loggingSystem).should().setLogLevel("test.member2", LogLevel.DEBUG);
132132
resetLogger();
133133
}
134134

@@ -142,7 +142,7 @@ void clearLogLevel() throws Exception {
142142
this.mockMvc
143143
.perform(post("/actuator/loggers/com.example").content("{}").contentType(MediaType.APPLICATION_JSON))
144144
.andExpect(status().isNoContent()).andDo(MockMvcRestDocumentation.document("loggers/clear"));
145-
verify(this.loggingSystem).setLogLevel("com.example", null);
145+
then(this.loggingSystem).should().setLogLevel("com.example", null);
146146
}
147147

148148
@Configuration(proxyBeanMethods = false)

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/SessionsEndpointDocumentationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 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,7 @@
3838
import org.springframework.test.context.TestPropertySource;
3939

4040
import static org.mockito.BDDMockito.given;
41-
import static org.mockito.Mockito.verify;
41+
import static org.mockito.BDDMockito.then;
4242
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
4343
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
4444
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
@@ -102,7 +102,7 @@ void sessionWithId() throws Exception {
102102
void deleteASession() throws Exception {
103103
this.mockMvc.perform(delete("/actuator/sessions/{id}", sessionTwo.getId())).andExpect(status().isNoContent())
104104
.andDo(document("sessions/delete"));
105-
verify(this.sessionRepository).deleteById(sessionTwo.getId());
105+
then(this.sessionRepository).should().deleteById(sessionTwo.getId());
106106
}
107107

108108
private static MapSession createSession(Instant creationTime, Instant lastAccessedTime) {

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurerTests.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -35,10 +35,9 @@
3535

3636
import static org.assertj.core.api.Assertions.assertThat;
3737
import static org.mockito.BDDMockito.given;
38+
import static org.mockito.BDDMockito.then;
3839
import static org.mockito.Mockito.inOrder;
3940
import static org.mockito.Mockito.mock;
40-
import static org.mockito.Mockito.verify;
41-
import static org.mockito.Mockito.verifyNoInteractions;
4241

4342
/**
4443
* Tests for {@link MeterRegistryConfigurer}.
@@ -77,7 +76,7 @@ void configureWhenCompositeShouldApplyCustomizer() {
7776
createObjectProvider(this.filters), createObjectProvider(this.binders), false, false);
7877
CompositeMeterRegistry composite = new CompositeMeterRegistry();
7978
configurer.configure(composite);
80-
verify(this.mockCustomizer).customize(composite);
79+
then(this.mockCustomizer).should().customize(composite);
8180
}
8281

8382
@Test
@@ -87,7 +86,7 @@ void configureShouldApplyCustomizer() {
8786
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers),
8887
createObjectProvider(this.filters), createObjectProvider(this.binders), false, false);
8988
configurer.configure(this.mockRegistry);
90-
verify(this.mockCustomizer).customize(this.mockRegistry);
89+
then(this.mockCustomizer).should().customize(this.mockRegistry);
9190
}
9291

9392
@Test
@@ -97,7 +96,7 @@ void configureShouldApplyFilter() {
9796
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers),
9897
createObjectProvider(this.filters), createObjectProvider(this.binders), false, false);
9998
configurer.configure(this.mockRegistry);
100-
verify(this.mockConfig).meterFilter(this.mockFilter);
99+
then(this.mockConfig).should().meterFilter(this.mockFilter);
101100
}
102101

103102
@Test
@@ -107,7 +106,7 @@ void configureShouldApplyBinder() {
107106
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers),
108107
createObjectProvider(this.filters), createObjectProvider(this.binders), false, false);
109108
configurer.configure(this.mockRegistry);
110-
verify(this.mockBinder).bindTo(this.mockRegistry);
109+
then(this.mockBinder).should().bindTo(this.mockRegistry);
111110
}
112111

113112
@Test
@@ -117,7 +116,7 @@ void configureShouldApplyBinderToComposite() {
117116
createObjectProvider(this.filters), createObjectProvider(this.binders), false, true);
118117
CompositeMeterRegistry composite = new CompositeMeterRegistry();
119118
configurer.configure(composite);
120-
verify(this.mockBinder).bindTo(composite);
119+
then(this.mockBinder).should().bindTo(composite);
121120
}
122121

123122
@Test
@@ -126,7 +125,7 @@ void configureShouldNotApplyBinderWhenCompositeExists() {
126125
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers),
127126
createObjectProvider(this.filters), null, false, true);
128127
configurer.configure(this.mockRegistry);
129-
verifyNoInteractions(this.mockBinder);
128+
then(this.mockBinder).shouldHaveNoInteractions();
130129
}
131130

132131
@Test
@@ -139,9 +138,9 @@ void configureShouldBeCalledInOrderCustomizerFilterBinder() {
139138
createObjectProvider(this.filters), createObjectProvider(this.binders), false, false);
140139
configurer.configure(this.mockRegistry);
141140
InOrder ordered = inOrder(this.mockBinder, this.mockConfig, this.mockCustomizer);
142-
ordered.verify(this.mockCustomizer).customize(this.mockRegistry);
143-
ordered.verify(this.mockConfig).meterFilter(this.mockFilter);
144-
ordered.verify(this.mockBinder).bindTo(this.mockRegistry);
141+
then(this.mockCustomizer).should(ordered).customize(this.mockRegistry);
142+
then(this.mockConfig).should(ordered).meterFilter(this.mockFilter);
143+
then(this.mockBinder).should(ordered).bindTo(this.mockRegistry);
145144
}
146145

147146
@Test

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -33,8 +33,8 @@
3333
import org.springframework.test.util.ReflectionTestUtils;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
36+
import static org.mockito.BDDMockito.then;
3637
import static org.mockito.Mockito.mock;
37-
import static org.mockito.Mockito.verify;
3838

3939
/**
4040
* Tests for {@link MetricsAutoConfiguration}.
@@ -67,8 +67,8 @@ void configuresMeterRegistries() {
6767
assertThat(filters[0].accept((Meter.Id) null)).isEqualTo(MeterFilterReply.DENY);
6868
assertThat(filters[1]).isInstanceOf(PropertiesMeterFilter.class);
6969
assertThat(filters[2].accept((Meter.Id) null)).isEqualTo(MeterFilterReply.ACCEPT);
70-
verify((MeterBinder) context.getBean("meterBinder")).bindTo(meterRegistry);
71-
verify(context.getBean(MeterRegistryCustomizer.class)).customize(meterRegistry);
70+
then((MeterBinder) context.getBean("meterBinder")).should().bindTo(meterRegistry);
71+
then(context.getBean(MeterRegistryCustomizer.class)).should().customize(meterRegistry);
7272
});
7373
}
7474

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/data/MetricsRepositoryMethodInvocationListenerBeanPostProcessorTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -26,8 +26,8 @@
2626
import org.springframework.util.function.SingletonSupplier;
2727

2828
import static org.assertj.core.api.Assertions.assertThat;
29+
import static org.mockito.BDDMockito.then;
2930
import static org.mockito.Mockito.mock;
30-
import static org.mockito.Mockito.verify;
3131

3232
/**
3333
* Tests for {@link MetricsRepositoryMethodInvocationListenerBeanPostProcessor} .
@@ -49,10 +49,10 @@ void postProcessBeforeInitializationWhenRepositoryFactoryBeanSupportAddsListener
4949
assertThat(result).isSameAs(bean);
5050
ArgumentCaptor<RepositoryFactoryCustomizer> customizer = ArgumentCaptor
5151
.forClass(RepositoryFactoryCustomizer.class);
52-
verify(bean).addRepositoryFactoryCustomizer(customizer.capture());
52+
then(bean).should().addRepositoryFactoryCustomizer(customizer.capture());
5353
RepositoryFactorySupport repositoryFactory = mock(RepositoryFactorySupport.class);
5454
customizer.getValue().customize(repositoryFactory);
55-
verify(repositoryFactory).addInvocationListener(this.listener);
55+
then(repositoryFactory).should().addInvocationListener(this.listener);
5656
}
5757

5858
@Test

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyChildManagementContextConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -31,8 +31,8 @@
3131
import org.springframework.context.annotation.Configuration;
3232

3333
import static org.assertj.core.api.Assertions.assertThat;
34+
import static org.mockito.BDDMockito.then;
3435
import static org.mockito.Mockito.mock;
35-
import static org.mockito.Mockito.verify;
3636

3737
/**
3838
* Tests for {@link JerseyChildManagementContextConfiguration}.
@@ -89,7 +89,7 @@ void resourceConfigIsCustomizedWithResourceConfigCustomizerBean() {
8989
ResourceConfig config = context.getBean(ResourceConfig.class);
9090
ManagementContextResourceConfigCustomizer customizer = context
9191
.getBean(ManagementContextResourceConfigCustomizer.class);
92-
verify(customizer).customize(config);
92+
then(customizer).should().customize(config);
9393
});
9494
}
9595

0 commit comments

Comments
 (0)