diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundrySecurityInterceptorTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundrySecurityInterceptorTests.java index c45a66e15b..b1b3e4e981 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundrySecurityInterceptorTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundrySecurityInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ import org.springframework.util.Base64Utils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link CloudFoundrySecurityInterceptor}. @@ -115,7 +115,7 @@ class CloudFoundrySecurityInterceptorTests { given(this.securityService.getAccessLevel(accessToken, "my-app-id")).willReturn(AccessLevel.FULL); SecurityResponse response = this.interceptor.preHandle(this.request, EndpointId.of("test")); ArgumentCaptor tokenArgumentCaptor = ArgumentCaptor.forClass(Token.class); - verify(this.tokenValidator).validate(tokenArgumentCaptor.capture()); + then(this.tokenValidator).should().validate(tokenArgumentCaptor.capture()); Token token = tokenArgumentCaptor.getValue(); assertThat(token.toString()).isEqualTo(accessToken); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK); @@ -129,7 +129,7 @@ class CloudFoundrySecurityInterceptorTests { given(this.securityService.getAccessLevel(accessToken, "my-app-id")).willReturn(AccessLevel.RESTRICTED); SecurityResponse response = this.interceptor.preHandle(this.request, EndpointId.of("info")); ArgumentCaptor tokenArgumentCaptor = ArgumentCaptor.forClass(Token.class); - verify(this.tokenValidator).validate(tokenArgumentCaptor.capture()); + then(this.tokenValidator).should().validate(tokenArgumentCaptor.capture()); Token token = tokenArgumentCaptor.getValue(); assertThat(token.toString()).isEqualTo(accessToken); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/TokenValidatorTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/TokenValidatorTests.java index a7b568ecbd..cf469ce897 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/TokenValidatorTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/TokenValidatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException; @@ -46,7 +45,8 @@ import org.springframework.util.StreamUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.never; /** * Tests for {@link TokenValidator}. @@ -109,7 +109,7 @@ class TokenValidatorTests { String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}"; String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}"; this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes()))); - verify(this.securityService).fetchTokenKeys(); + then(this.securityService).should().fetchTokenKeys(); } @Test @@ -119,7 +119,7 @@ class TokenValidatorTests { String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}"; String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}"; this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes()))); - verify(this.securityService).fetchTokenKeys(); + then(this.securityService).should().fetchTokenKeys(); } @Test @@ -129,7 +129,7 @@ class TokenValidatorTests { String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}"; String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}"; this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes()))); - verify(this.securityService, Mockito.never()).fetchTokenKeys(); + then(this.securityService).should(never()).fetchTokenKeys(); } @Test diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfigurationTests.java index 7bb06ee23a..eedf2db398 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,8 @@ import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link JmxEndpointAutoConfiguration}. @@ -72,7 +72,7 @@ class JmxEndpointAutoConfigurationTests { .withBean(EndpointObjectNameFactory.class, () -> factory).run((context) -> { ArgumentCaptor argumentCaptor = ArgumentCaptor .forClass(ExposableJmxEndpoint.class); - verify(factory).getObjectName(argumentCaptor.capture()); + then(factory).should().getObjectName(argumentCaptor.capture()); ExposableJmxEndpoint jmxEndpoint = argumentCaptor.getValue(); assertThat(jmxEndpoint.getEndpointId().toLowerCaseString()).isEqualTo("test"); }); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AuditEventsEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AuditEventsEndpointDocumentationTests.java index 5b267f0430..d5c18d1735 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AuditEventsEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AuditEventsEndpointDocumentationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ import org.springframework.context.annotation.Import; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; @@ -83,7 +83,7 @@ class AuditEventsEndpointDocumentationTests extends MockMvcEndpointDocumentation "Restricts the events to those with the given principal. Optional."), parameterWithName("type") .description("Restricts the events to those with the given type. Optional.")))); - verify(this.repository).find("alice", now.toInstant(), "logout"); + then(this.repository).should().find("alice", now.toInstant(), "logout"); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/LoggersEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/LoggersEndpointDocumentationTests.java index 81ad2c352a..ff01109eb1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/LoggersEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/LoggersEndpointDocumentationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ import org.springframework.restdocs.payload.FieldDescriptor; import org.springframework.restdocs.payload.JsonFieldType; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; @@ -114,7 +114,7 @@ class LoggersEndpointDocumentationTests extends MockMvcEndpointDocumentationTest .andExpect(status().isNoContent()) .andDo(MockMvcRestDocumentation.document("loggers/set", requestFields(fieldWithPath("configuredLevel") .description("Level for the logger. May be omitted to clear the level.").optional()))); - verify(this.loggingSystem).setLogLevel("com.example", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("com.example", LogLevel.DEBUG); } @Test @@ -127,8 +127,8 @@ class LoggersEndpointDocumentationTests extends MockMvcEndpointDocumentationTest requestFields(fieldWithPath("configuredLevel").description( "Level for the logger group. May be omitted to clear the level of the loggers.") .optional()))); - verify(this.loggingSystem).setLogLevel("test.member1", LogLevel.DEBUG); - verify(this.loggingSystem).setLogLevel("test.member2", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("test.member1", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("test.member2", LogLevel.DEBUG); resetLogger(); } @@ -142,7 +142,7 @@ class LoggersEndpointDocumentationTests extends MockMvcEndpointDocumentationTest this.mockMvc .perform(post("/actuator/loggers/com.example").content("{}").contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isNoContent()).andDo(MockMvcRestDocumentation.document("loggers/clear")); - verify(this.loggingSystem).setLogLevel("com.example", null); + then(this.loggingSystem).should().setLogLevel("com.example", null); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/SessionsEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/SessionsEndpointDocumentationTests.java index d57c041e28..d2282f986d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/SessionsEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/SessionsEndpointDocumentationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ import org.springframework.session.Session; import org.springframework.test.context.TestPropertySource; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; @@ -102,7 +102,7 @@ class SessionsEndpointDocumentationTests extends MockMvcEndpointDocumentationTes void deleteASession() throws Exception { this.mockMvc.perform(delete("/actuator/sessions/{id}", sessionTwo.getId())).andExpect(status().isNoContent()) .andDo(document("sessions/delete")); - verify(this.sessionRepository).deleteById(sessionTwo.getId()); + then(this.sessionRepository).should().deleteById(sessionTwo.getId()); } private static MapSession createSession(Instant creationTime, Instant lastAccessedTime) { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurerTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurerTests.java index bb9dbe5d08..b7fbc5eaca 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurerTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,10 +35,9 @@ import org.springframework.beans.factory.ObjectProvider; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link MeterRegistryConfigurer}. @@ -77,7 +76,7 @@ class MeterRegistryConfigurerTests { createObjectProvider(this.filters), createObjectProvider(this.binders), false, false); CompositeMeterRegistry composite = new CompositeMeterRegistry(); configurer.configure(composite); - verify(this.mockCustomizer).customize(composite); + then(this.mockCustomizer).should().customize(composite); } @Test @@ -87,7 +86,7 @@ class MeterRegistryConfigurerTests { MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers), createObjectProvider(this.filters), createObjectProvider(this.binders), false, false); configurer.configure(this.mockRegistry); - verify(this.mockCustomizer).customize(this.mockRegistry); + then(this.mockCustomizer).should().customize(this.mockRegistry); } @Test @@ -97,7 +96,7 @@ class MeterRegistryConfigurerTests { MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers), createObjectProvider(this.filters), createObjectProvider(this.binders), false, false); configurer.configure(this.mockRegistry); - verify(this.mockConfig).meterFilter(this.mockFilter); + then(this.mockConfig).should().meterFilter(this.mockFilter); } @Test @@ -107,7 +106,7 @@ class MeterRegistryConfigurerTests { MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers), createObjectProvider(this.filters), createObjectProvider(this.binders), false, false); configurer.configure(this.mockRegistry); - verify(this.mockBinder).bindTo(this.mockRegistry); + then(this.mockBinder).should().bindTo(this.mockRegistry); } @Test @@ -117,7 +116,7 @@ class MeterRegistryConfigurerTests { createObjectProvider(this.filters), createObjectProvider(this.binders), false, true); CompositeMeterRegistry composite = new CompositeMeterRegistry(); configurer.configure(composite); - verify(this.mockBinder).bindTo(composite); + then(this.mockBinder).should().bindTo(composite); } @Test @@ -126,7 +125,7 @@ class MeterRegistryConfigurerTests { MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers), createObjectProvider(this.filters), null, false, true); configurer.configure(this.mockRegistry); - verifyNoInteractions(this.mockBinder); + then(this.mockBinder).shouldHaveNoInteractions(); } @Test @@ -139,9 +138,9 @@ class MeterRegistryConfigurerTests { createObjectProvider(this.filters), createObjectProvider(this.binders), false, false); configurer.configure(this.mockRegistry); InOrder ordered = inOrder(this.mockBinder, this.mockConfig, this.mockCustomizer); - ordered.verify(this.mockCustomizer).customize(this.mockRegistry); - ordered.verify(this.mockConfig).meterFilter(this.mockFilter); - ordered.verify(this.mockBinder).bindTo(this.mockRegistry); + then(this.mockCustomizer).should(ordered).customize(this.mockRegistry); + then(this.mockConfig).should(ordered).meterFilter(this.mockFilter); + then(this.mockBinder).should(ordered).bindTo(this.mockRegistry); } @Test diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java index 6737aba194..fd8f773084 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,8 +33,8 @@ import org.springframework.core.annotation.Order; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link MetricsAutoConfiguration}. @@ -67,8 +67,8 @@ class MetricsAutoConfigurationTests { assertThat(filters[0].accept((Meter.Id) null)).isEqualTo(MeterFilterReply.DENY); assertThat(filters[1]).isInstanceOf(PropertiesMeterFilter.class); assertThat(filters[2].accept((Meter.Id) null)).isEqualTo(MeterFilterReply.ACCEPT); - verify((MeterBinder) context.getBean("meterBinder")).bindTo(meterRegistry); - verify(context.getBean(MeterRegistryCustomizer.class)).customize(meterRegistry); + then((MeterBinder) context.getBean("meterBinder")).should().bindTo(meterRegistry); + then(context.getBean(MeterRegistryCustomizer.class)).should().customize(meterRegistry); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/data/MetricsRepositoryMethodInvocationListenerBeanPostProcessorTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/data/MetricsRepositoryMethodInvocationListenerBeanPostProcessorTests.java index b3c528054f..2077bfeefa 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/data/MetricsRepositoryMethodInvocationListenerBeanPostProcessorTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/data/MetricsRepositoryMethodInvocationListenerBeanPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,8 @@ import org.springframework.data.repository.core.support.RepositoryFactorySupport import org.springframework.util.function.SingletonSupplier; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link MetricsRepositoryMethodInvocationListenerBeanPostProcessor} . @@ -49,10 +49,10 @@ class MetricsRepositoryMethodInvocationListenerBeanPostProcessorTests { assertThat(result).isSameAs(bean); ArgumentCaptor customizer = ArgumentCaptor .forClass(RepositoryFactoryCustomizer.class); - verify(bean).addRepositoryFactoryCustomizer(customizer.capture()); + then(bean).should().addRepositoryFactoryCustomizer(customizer.capture()); RepositoryFactorySupport repositoryFactory = mock(RepositoryFactorySupport.class); customizer.getValue().customize(repositoryFactory); - verify(repositoryFactory).addInvocationListener(this.listener); + then(repositoryFactory).should().addInvocationListener(this.listener); } @Test diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyChildManagementContextConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyChildManagementContextConfigurationTests.java index d19975c9a8..cca272741d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyChildManagementContextConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyChildManagementContextConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link JerseyChildManagementContextConfiguration}. @@ -89,7 +89,7 @@ class JerseyChildManagementContextConfigurationTests { ResourceConfig config = context.getBean(ResourceConfig.class); ManagementContextResourceConfigCustomizer customizer = context .getBean(ManagementContextResourceConfigCustomizer.class); - verify(customizer).customize(config); + then(customizer).should().customize(config); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseySameManagementContextConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseySameManagementContextConfigurationTests.java index e15bdbb46e..e8c8120d35 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseySameManagementContextConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseySameManagementContextConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link JerseySameManagementContextConfiguration}. @@ -99,7 +99,7 @@ class JerseySameManagementContextConfigurationTests { ResourceConfig config = context.getBean(ResourceConfig.class); ManagementContextResourceConfigCustomizer customizer = context .getBean(ManagementContextResourceConfigCustomizer.class); - verify(customizer).customize(config); + then(customizer).should().customize(config); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/listener/AuditListenerTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/listener/AuditListenerTests.java index f241a4f031..6984a24a8a 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/listener/AuditListenerTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/listener/AuditListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.actuate.audit.AuditEvent; import org.springframework.boot.actuate.audit.AuditEventRepository; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link AuditListener}. @@ -39,7 +39,7 @@ class AuditListenerTests { AuditEvent event = new AuditEvent("principal", "type", Collections.emptyMap()); AuditListener listener = new AuditListener(repository); listener.onApplicationEvent(new AuditApplicationEvent(event)); - verify(repository).add(event); + then(repository).should().add(event); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointTests.java index e05af5ad1e..bbbd0e5b42 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,9 +34,9 @@ import org.springframework.cache.support.SimpleCacheManager; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link CachesEndpoint}. @@ -126,8 +126,8 @@ class CachesEndpointTests { Cache b = mockCache("b"); CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test", cacheManager(a, b))); endpoint.clearCaches(); - verify(a).clear(); - verify(b).clear(); + then(a).should().clear(); + then(b).should().clear(); } @Test @@ -136,8 +136,8 @@ class CachesEndpointTests { Cache b = mockCache("b"); CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test", cacheManager(a, b))); assertThat(endpoint.clearCache("a", null)).isTrue(); - verify(a).clear(); - verify(b, never()).clear(); + then(a).should().clear(); + then(b).should(never()).clear(); } @Test @@ -161,9 +161,9 @@ class CachesEndpointTests { cacheManagers.put("another", cacheManager(anotherA)); CachesEndpoint endpoint = new CachesEndpoint(cacheManagers); assertThat(endpoint.clearCache("a", "another")).isTrue(); - verify(a, never()).clear(); - verify(anotherA).clear(); - verify(b, never()).clear(); + then(a).should(never()).clear(); + then(anotherA).should().clear(); + then(b).should(never()).clear(); } @Test @@ -171,7 +171,7 @@ class CachesEndpointTests { Cache a = mockCache("a"); CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test", cacheManager(a))); assertThat(endpoint.clearCache("unknown", null)).isFalse(); - verify(a, never()).clear(); + then(a).should(never()).clear(); } @Test @@ -179,7 +179,7 @@ class CachesEndpointTests { Cache a = mockCache("a"); CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test", cacheManager(a))); assertThat(endpoint.clearCache("a", "unknown")).isFalse(); - verify(a, never()).clear(); + then(a).should(never()).clear(); } private CacheManager cacheManager(Cache... caches) { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicatorTests.java index 5a3928d392..e3345aa878 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,8 +34,8 @@ import org.springframework.boot.actuate.health.Status; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link CouchbaseHealthIndicator} @@ -61,7 +61,7 @@ class CouchbaseHealthIndicatorTests { assertThat(health.getDetails()).containsEntry("sdk", "test-sdk"); assertThat(health.getDetails()).containsKey("endpoints"); assertThat((List>) health.getDetails().get("endpoints")).hasSize(1); - verify(cluster).diagnostics(); + then(cluster).should().diagnostics(); } @Test @@ -82,7 +82,7 @@ class CouchbaseHealthIndicatorTests { assertThat(health.getDetails()).containsEntry("sdk", "test-sdk"); assertThat(health.getDetails()).containsKey("endpoints"); assertThat((List>) health.getDetails().get("endpoints")).hasSize(2); - verify(cluster).diagnostics(); + then(cluster).should().diagnostics(); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java index f2f13535cc..adc00a8751 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,8 @@ import org.springframework.boot.actuate.health.Status; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link CouchbaseReactiveHealthIndicator}. @@ -58,7 +58,7 @@ class CouchbaseReactiveHealthIndicatorTests { assertThat(health.getDetails()).containsEntry("sdk", "test-sdk"); assertThat(health.getDetails()).containsKey("endpoints"); assertThat((List>) health.getDetails().get("endpoints")).hasSize(1); - verify(cluster).diagnostics(); + then(cluster).should().diagnostics(); } @Test @@ -79,7 +79,7 @@ class CouchbaseReactiveHealthIndicatorTests { assertThat(health.getDetails()).containsEntry("sdk", "test-sdk"); assertThat(health.getDetails()).containsKey("endpoints"); assertThat((List>) health.getDetails().get("endpoints")).hasSize(2); - verify(cluster).diagnostics(); + then(cluster).should().diagnostics(); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoke/convert/ConversionServiceParameterValueMapperTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoke/convert/ConversionServiceParameterValueMapperTests.java index 3b82e15475..c2edffcee8 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoke/convert/ConversionServiceParameterValueMapperTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoke/convert/ConversionServiceParameterValueMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +30,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Tests for {@link ConversionServiceParameterValueMapper}. @@ -47,7 +47,7 @@ class ConversionServiceParameterValueMapperTests { ConversionServiceParameterValueMapper mapper = new ConversionServiceParameterValueMapper(conversionService); Object mapped = mapper.mapParameterValue(new TestOperationParameter(Integer.class), "123"); assertThat(mapped).isEqualTo(123); - verify(conversionService).convert("123", Integer.class); + then(conversionService).should().convert("123", Integer.class); } @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerAdvisorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerAdvisorTests.java index e25d26f089..63b4d50226 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerAdvisorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerAdvisorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link CachingOperationInvokerAdvisor}. @@ -86,7 +86,7 @@ class CachingOperationInvokerAdvisorTests { OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"), OperationType.READ, parameters, this.invoker); assertThat(advised).isSameAs(this.invoker); - verify(this.timeToLive).apply(EndpointId.of("foo")); + then(this.timeToLive).should().apply(EndpointId.of("foo")); } @Test @@ -96,7 +96,7 @@ class CachingOperationInvokerAdvisorTests { OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"), OperationType.READ, parameters, this.invoker); assertThat(advised).isSameAs(this.invoker); - verify(this.timeToLive).apply(EndpointId.of("foo")); + then(this.timeToLive).should().apply(EndpointId.of("foo")); } @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerTests.java index b4bb802eb1..27e242874d 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,10 +39,9 @@ import static org.assertj.core.api.Assertions.as; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link CachingOperationInvoker}. @@ -144,10 +143,10 @@ class CachingOperationInvokerTests { CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL); Object response = invoker.invoke(context); assertThat(response).isSameAs(expected); - verify(target, times(1)).invoke(context); + then(target).should().invoke(context); Object cachedResponse = invoker.invoke(context); assertThat(cachedResponse).isSameAs(response); - verifyNoMoreInteractions(target); + then(target).shouldHaveNoMoreInteractions(); } @Test @@ -162,7 +161,7 @@ class CachingOperationInvokerTests { invoker.invoke(context); invoker.invoke(context); invoker.invoke(context); - verify(target, times(3)).invoke(context); + then(target).should(times(3)).invoke(context); } @Test @@ -181,7 +180,7 @@ class CachingOperationInvokerTests { assertThat(invoker.invoke(context)).isEqualTo(result1); assertThat(invoker.invoke(context)).isEqualTo(result2); assertThat(invoker.invoke(context)).isEqualTo(result3); - verify(target, times(3)).invoke(context); + then(target).should(times(3)).invoke(context); } @Test @@ -202,8 +201,8 @@ class CachingOperationInvokerTests { assertThat(invoker.invoke(authenticatedContext)).isEqualTo(authenticatedResult); assertThat(invoker.invoke(anonymousContext)).isEqualTo(anonymousResult); assertThat(invoker.invoke(authenticatedContext)).isEqualTo(authenticatedResult); - verify(target, times(1)).invoke(anonymousContext); - verify(target, times(1)).invoke(authenticatedContext); + then(target).should().invoke(anonymousContext); + then(target).should().invoke(authenticatedContext); } @Test @@ -219,7 +218,7 @@ class CachingOperationInvokerTests { Thread.sleep(10); } invoker.invoke(context); - verify(target, times(2)).invoke(context); + then(target).should(times(2)).invoke(context); } @Test @@ -236,10 +235,10 @@ class CachingOperationInvokerTests { CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL); Object responseV2 = invoker.invoke(contextV2); assertThat(responseV2).isSameAs(expectedV2); - verify(target, times(1)).invoke(contextV2); + then(target).should().invoke(contextV2); Object responseV3 = invoker.invoke(contextV3); assertThat(responseV3).isNotSameAs(responseV2); - verify(target, times(1)).invoke(contextV3); + then(target).should().invoke(contextV3); } @Test @@ -256,10 +255,10 @@ class CachingOperationInvokerTests { CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL); Object responseServer = invoker.invoke(contextServer); assertThat(responseServer).isSameAs(expectedServer); - verify(target, times(1)).invoke(contextServer); + then(target).should(times(1)).invoke(contextServer); Object responseManagement = invoker.invoke(contextManagement); assertThat(responseManagement).isNotSameAs(responseServer); - verify(target, times(1)).invoke(contextManagement); + then(target).should(times(1)).invoke(contextManagement); } private static class MonoOperationInvoker implements OperationInvoker { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanTests.java index 21f7f7ce84..bcebfa49a3 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,9 +37,9 @@ import org.springframework.util.ClassUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Tests for {@link EndpointMBean}. @@ -160,8 +160,8 @@ class EndpointMBeanTests { TestJmxOperationResponseMapper responseMapper = spy(this.responseMapper); EndpointMBean bean = new EndpointMBean(responseMapper, null, this.endpoint); bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE); - verify(responseMapper).mapResponseType(String.class); - verify(responseMapper).mapResponse("result"); + then(responseMapper).should().mapResponseType(String.class); + then(responseMapper).should().mapResponse("result"); } @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JacksonJmxOperationResponseMapperTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JacksonJmxOperationResponseMapperTests.java index 09fbc96a41..2b3b7273f7 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JacksonJmxOperationResponseMapperTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JacksonJmxOperationResponseMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,8 @@ import org.springframework.boot.test.json.BasicJsonTester; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Tests for {@link JacksonJmxOperationResponseMapper} @@ -59,7 +59,7 @@ class JacksonJmxOperationResponseMapperTests { JacksonJmxOperationResponseMapper mapper = new JacksonJmxOperationResponseMapper(objectMapper); Set response = Collections.singleton("test"); mapper.mapResponse(response); - verify(objectMapper).convertValue(eq(response), any(JavaType.class)); + then(objectMapper).should().convertValue(eq(response), any(JavaType.class)); } @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JmxEndpointExporterTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JmxEndpointExporterTests.java index b58b9f56ec..b4765c6882 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JmxEndpointExporterTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JmxEndpointExporterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,8 +43,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Mockito.verify; /** * Tests for {@link JmxEndpointExporter}. @@ -112,7 +112,7 @@ class JmxEndpointExporterTests { void afterPropertiesSetShouldRegisterMBeans() throws Exception { this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation())); this.exporter.afterPropertiesSet(); - verify(this.mBeanServer).registerMBean(this.objectCaptor.capture(), this.objectNameCaptor.capture()); + then(this.mBeanServer).should().registerMBean(this.objectCaptor.capture(), this.objectNameCaptor.capture()); assertThat(this.objectCaptor.getValue()).isInstanceOf(EndpointMBean.class); assertThat(this.objectNameCaptor.getValue().getKeyProperty("name")).isEqualTo("test"); } @@ -121,7 +121,7 @@ class JmxEndpointExporterTests { void registerShouldUseObjectNameFactory() throws Exception { this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation())); this.exporter.afterPropertiesSet(); - verify(this.objectNameFactory).getObjectName(any(ExposableJmxEndpoint.class)); + then(this.objectNameFactory).should().getObjectName(any(ExposableJmxEndpoint.class)); } @Test @@ -147,7 +147,7 @@ class JmxEndpointExporterTests { this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation())); this.exporter.afterPropertiesSet(); this.exporter.destroy(); - verify(this.mBeanServer).unregisterMBean(this.objectNameCaptor.capture()); + then(this.mBeanServer).should().unregisterMBean(this.objectNameCaptor.capture()); assertThat(this.objectNameCaptor.getValue().getKeyProperty("name")).isEqualTo("test"); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/ServletEndpointRegistrarTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/ServletEndpointRegistrarTests.java index e4e2a419c5..cbbc52befe 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/ServletEndpointRegistrarTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/ServletEndpointRegistrarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,8 +40,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link ServletEndpointRegistrar}. @@ -92,9 +92,9 @@ class ServletEndpointRegistrarTests { ExposableServletEndpoint endpoint = mockEndpoint(new EndpointServlet(TestServlet.class)); ServletEndpointRegistrar registrar = new ServletEndpointRegistrar(basePath, Collections.singleton(endpoint)); registrar.onStartup(this.servletContext); - verify(this.servletContext).addServlet(eq("test-actuator-endpoint"), this.servlet.capture()); + then(this.servletContext).should().addServlet(eq("test-actuator-endpoint"), this.servlet.capture()); assertThat(this.servlet.getValue()).isInstanceOf(TestServlet.class); - verify(this.dynamic).addMapping(expectedMapping); + then(this.dynamic).should().addMapping(expectedMapping); } @Test @@ -104,7 +104,7 @@ class ServletEndpointRegistrarTests { new EndpointServlet(TestServlet.class).withInitParameter("a", "b")); ServletEndpointRegistrar registrar = new ServletEndpointRegistrar("/actuator", Collections.singleton(endpoint)); registrar.onStartup(this.servletContext); - verify(this.dynamic).setInitParameters(Collections.singletonMap("a", "b")); + then(this.dynamic).should().setInitParameters(Collections.singletonMap("a", "b")); } @Test @@ -113,7 +113,7 @@ class ServletEndpointRegistrarTests { ExposableServletEndpoint endpoint = mockEndpoint(new EndpointServlet(TestServlet.class).withLoadOnStartup(7)); ServletEndpointRegistrar registrar = new ServletEndpointRegistrar("/actuator", Collections.singleton(endpoint)); registrar.onStartup(this.servletContext); - verify(this.dynamic).setLoadOnStartup(7); + then(this.dynamic).should().setLoadOnStartup(7); } @Test @@ -122,7 +122,7 @@ class ServletEndpointRegistrarTests { ExposableServletEndpoint endpoint = mockEndpoint(new EndpointServlet(TestServlet.class)); ServletEndpointRegistrar registrar = new ServletEndpointRegistrar("/actuator", Collections.singleton(endpoint)); registrar.onStartup(this.servletContext); - verify(this.dynamic).setLoadOnStartup(-1); + then(this.dynamic).should().setLoadOnStartup(-1); } private ExposableServletEndpoint mockEndpoint(EndpointServlet endpointServlet) { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java index db7e96b8be..ad0f889bb4 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,7 +54,7 @@ import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Abstract base class for web endpoint integration tests. @@ -188,7 +188,7 @@ public abstract class AbstractWebEndpointIntegrationTests { client.post().uri("/voidwrite").exchange().expectStatus().isNoContent().expectBody().isEmpty(); - verify(context.getBean(EndpointDelegate.class)).write(); + then(context.getBean(EndpointDelegate.class)).should().write(); }); } @@ -202,7 +202,7 @@ public abstract class AbstractWebEndpointIntegrationTests { client.delete().uri("/voiddelete").exchange().expectStatus().isNoContent().expectBody().isEmpty(); - verify(context.getBean(EndpointDelegate.class)).delete(); + then(context.getBean(EndpointDelegate.class)).should().delete(); }); } @@ -212,7 +212,7 @@ public abstract class AbstractWebEndpointIntegrationTests body = new HashMap<>(); body.put("foo", "one"); client.post().uri("/test").bodyValue(body).exchange().expectStatus().isNoContent().expectBody().isEmpty(); - verify(context.getBean(EndpointDelegate.class)).write("one", null); + then(context.getBean(EndpointDelegate.class)).should().write("one", null); }); } @@ -221,7 +221,7 @@ public abstract class AbstractWebEndpointIntegrationTests { client.post().uri("/test").contentType(MediaType.APPLICATION_JSON).exchange().expectStatus().isNoContent() .expectBody().isEmpty(); - verify(context.getBean(EndpointDelegate.class)).write(null, null); + then(context.getBean(EndpointDelegate.class)).should().write(null, null); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/influx/InfluxDbHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/influx/InfluxDbHealthIndicatorTests.java index 068f4c29d1..b991ceb5e0 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/influx/InfluxDbHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/influx/InfluxDbHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import org.springframework.boot.actuate.health.Status; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link InfluxDbHealthIndicator}. @@ -48,7 +48,7 @@ class InfluxDbHealthIndicatorTests { Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails().get("version")).isEqualTo("0.9"); - verify(influxDb).ping(); + then(influxDb).should().ping(); } @Test @@ -59,7 +59,7 @@ class InfluxDbHealthIndicatorTests { Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.DOWN); assertThat((String) health.getDetails().get("error")).contains("Connection failed"); - verify(influxDb).ping(); + then(influxDb).should().ping(); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/integration/IntegrationGraphEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/integration/IntegrationGraphEndpointTests.java index fc9468b71f..c832b2d054 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/integration/IntegrationGraphEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/integration/IntegrationGraphEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ import org.springframework.integration.graph.IntegrationGraphServer; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link IntegrationGraphEndpoint}. @@ -42,14 +42,14 @@ class IntegrationGraphEndpointTests { Graph mockedGraph = mock(Graph.class); given(this.server.getGraph()).willReturn(mockedGraph); Graph graph = this.endpoint.graph(); - verify(this.server).getGraph(); + then(this.server).should().getGraph(); assertThat(graph).isEqualTo(mockedGraph); } @Test void writeOperationShouldRebuildGraph() { this.endpoint.rebuild(); - verify(this.server).rebuild(); + then(this.server).should().rebuild(); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jdbc/DataSourceHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jdbc/DataSourceHealthIndicatorTests.java index c7af6e5e1f..df69e11813 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jdbc/DataSourceHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jdbc/DataSourceHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,9 +34,9 @@ import org.springframework.jdbc.datasource.SingleConnectionDataSource; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link DataSourceHealthIndicator}. @@ -106,7 +106,7 @@ class DataSourceHealthIndicatorTests { this.indicator.setDataSource(dataSource); Health health = this.indicator.health(); assertThat(health.getDetails().get("database")).isNotNull(); - verify(connection, times(2)).close(); + then(connection).should(times(2)).close(); } @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jms/JmsHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jms/JmsHealthIndicatorTests.java index 93d39f95c6..151dc70778 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jms/JmsHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jms/JmsHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,11 +30,10 @@ import org.springframework.boot.actuate.health.Status; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willAnswer; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link JmsHealthIndicator}. @@ -55,7 +54,7 @@ class JmsHealthIndicatorTests { Health health = indicator.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails().get("provider")).isEqualTo("JMS test provider"); - verify(connection, times(1)).close(); + then(connection).should().close(); } @Test @@ -80,7 +79,7 @@ class JmsHealthIndicatorTests { Health health = indicator.health(); assertThat(health.getStatus()).isEqualTo(Status.DOWN); assertThat(health.getDetails().get("provider")).isNull(); - verify(connection, times(1)).close(); + then(connection).should().close(); } @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/ldap/LdapHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/ldap/LdapHealthIndicatorTests.java index 76e93fe177..9af6b7950a 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/ldap/LdapHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/ldap/LdapHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,8 @@ import org.springframework.ldap.core.LdapTemplate; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link LdapHealthIndicator} @@ -46,7 +46,7 @@ class LdapHealthIndicatorTests { Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails().get("version")).isEqualTo("3"); - verify(ldapTemplate).executeReadOnly((ContextExecutor) any()); + then(ldapTemplate).should().executeReadOnly((ContextExecutor) any()); } @Test @@ -59,7 +59,7 @@ class LdapHealthIndicatorTests { Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.DOWN); assertThat((String) health.getDetails().get("error")).contains("Connection failed"); - verify(ldapTemplate).executeReadOnly((ContextExecutor) any()); + then(ldapTemplate).should().executeReadOnly((ContextExecutor) any()); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointTests.java index 7ced35e133..5c7515e3b2 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,8 @@ import org.springframework.boot.logging.LoggingSystem; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link LoggersEndpoint}. @@ -120,25 +120,25 @@ class LoggersEndpointTests { @Test void configureLogLevelShouldSetLevelOnLoggingSystem() { new LoggersEndpoint(this.loggingSystem, this.loggerGroups).configureLogLevel("ROOT", LogLevel.DEBUG); - verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("ROOT", LogLevel.DEBUG); } @Test void configureLogLevelWithNullSetsLevelOnLoggingSystemToNull() { new LoggersEndpoint(this.loggingSystem, this.loggerGroups).configureLogLevel("ROOT", null); - verify(this.loggingSystem).setLogLevel("ROOT", null); + then(this.loggingSystem).should().setLogLevel("ROOT", null); } @Test void configureLogLevelInLoggerGroupShouldSetLevelOnLoggingSystem() { new LoggersEndpoint(this.loggingSystem, this.loggerGroups).configureLogLevel("test", LogLevel.DEBUG); - verify(this.loggingSystem).setLogLevel("test.member", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("test.member", LogLevel.DEBUG); } @Test void configureLogLevelWithNullInLoggerGroupShouldSetLevelOnLoggingSystem() { new LoggersEndpoint(this.loggingSystem, this.loggerGroups).configureLogLevel("test", null); - verify(this.loggingSystem).setLogLevel("test.member", null); + then(this.loggingSystem).should().setLogLevel("test.member", null); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointWebIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointWebIntegrationTests.java index 6364b144b4..254df61e22 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointWebIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointWebIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,9 +43,8 @@ import org.springframework.http.MediaType; import org.springframework.test.web.reactive.server.WebTestClient; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Integration tests for {@link LoggersEndpoint} when exposed via Jersey, Spring MVC, and @@ -124,7 +123,7 @@ class LoggersEndpointWebIntegrationTests { this.client.post().uri("/actuator/loggers/ROOT").contentType(MediaType.APPLICATION_JSON) .bodyValue(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus() .isNoContent(); - verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("ROOT", LogLevel.DEBUG); } @WebEndpointTest @@ -132,7 +131,7 @@ class LoggersEndpointWebIntegrationTests { this.client.post().uri("/actuator/loggers/ROOT").contentType(MediaType.parseMediaType(V2_JSON)) .bodyValue(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus() .isNoContent(); - verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("ROOT", LogLevel.DEBUG); } @WebEndpointTest @@ -140,7 +139,7 @@ class LoggersEndpointWebIntegrationTests { this.client.post().uri("/actuator/loggers/ROOT").contentType(MediaType.parseMediaType(V3_JSON)) .bodyValue(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus() .isNoContent(); - verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("ROOT", LogLevel.DEBUG); } @WebEndpointTest @@ -148,8 +147,8 @@ class LoggersEndpointWebIntegrationTests { this.client.post().uri("/actuator/loggers/test").contentType(MediaType.parseMediaType(V2_JSON)) .bodyValue(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus() .isNoContent(); - verify(this.loggingSystem).setLogLevel("test.member1", LogLevel.DEBUG); - verify(this.loggingSystem).setLogLevel("test.member2", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("test.member1", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("test.member2", LogLevel.DEBUG); } @WebEndpointTest @@ -157,8 +156,8 @@ class LoggersEndpointWebIntegrationTests { this.client.post().uri("/actuator/loggers/test").contentType(MediaType.APPLICATION_JSON) .bodyValue(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus() .isNoContent(); - verify(this.loggingSystem).setLogLevel("test.member1", LogLevel.DEBUG); - verify(this.loggingSystem).setLogLevel("test.member2", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("test.member1", LogLevel.DEBUG); + then(this.loggingSystem).should().setLogLevel("test.member2", LogLevel.DEBUG); } @WebEndpointTest @@ -166,37 +165,37 @@ class LoggersEndpointWebIntegrationTests { this.client.post().uri("/actuator/loggers/ROOT").contentType(MediaType.APPLICATION_JSON) .bodyValue(Collections.singletonMap("configuredLevel", "other")).exchange().expectStatus() .isBadRequest(); - verifyNoInteractions(this.loggingSystem); + then(this.loggingSystem).shouldHaveNoInteractions(); } @WebEndpointTest void setLoggerWithNullLogLevel() { this.client.post().uri("/actuator/loggers/ROOT").contentType(MediaType.parseMediaType(V3_JSON)) .bodyValue(Collections.singletonMap("configuredLevel", null)).exchange().expectStatus().isNoContent(); - verify(this.loggingSystem).setLogLevel("ROOT", null); + then(this.loggingSystem).should().setLogLevel("ROOT", null); } @WebEndpointTest void setLoggerWithNoLogLevel() { this.client.post().uri("/actuator/loggers/ROOT").contentType(MediaType.parseMediaType(V3_JSON)) .bodyValue(Collections.emptyMap()).exchange().expectStatus().isNoContent(); - verify(this.loggingSystem).setLogLevel("ROOT", null); + then(this.loggingSystem).should().setLogLevel("ROOT", null); } @WebEndpointTest void setLoggerGroupWithNullLogLevel() { this.client.post().uri("/actuator/loggers/test").contentType(MediaType.parseMediaType(V3_JSON)) .bodyValue(Collections.singletonMap("configuredLevel", null)).exchange().expectStatus().isNoContent(); - verify(this.loggingSystem).setLogLevel("test.member1", null); - verify(this.loggingSystem).setLogLevel("test.member2", null); + then(this.loggingSystem).should().setLogLevel("test.member1", null); + then(this.loggingSystem).should().setLogLevel("test.member2", null); } @WebEndpointTest void setLoggerGroupWithNoLogLevel() { this.client.post().uri("/actuator/loggers/test").contentType(MediaType.parseMediaType(V3_JSON)) .bodyValue(Collections.emptyMap()).exchange().expectStatus().isNoContent(); - verify(this.loggingSystem).setLogLevel("test.member1", null); - verify(this.loggingSystem).setLogLevel("test.member2", null); + then(this.loggingSystem).should().setLogLevel("test.member1", null); + then(this.loggingSystem).should().setLogLevel("test.member2", null); } @WebEndpointTest diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManagerTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManagerTests.java index 2ef0342240..7bb3ceef2f 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManagerTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,11 +39,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link PrometheusPushGatewayManager}. @@ -110,9 +109,9 @@ class PrometheusPushGatewayManagerTests { void createShouldSchedulePushAsFixedRate() throws Exception { new PrometheusPushGatewayManager(this.pushGateway, this.registry, this.scheduler, this.pushRate, "job", this.groupingKey, null); - verify(this.scheduler).scheduleAtFixedRate(this.task.capture(), eq(this.pushRate)); + then(this.scheduler).should().scheduleAtFixedRate(this.task.capture(), eq(this.pushRate)); this.task.getValue().run(); - verify(this.pushGateway).pushAdd(this.registry, "job", this.groupingKey); + then(this.pushGateway).should().pushAdd(this.registry, "job", this.groupingKey); } @Test @@ -122,7 +121,7 @@ class PrometheusPushGatewayManagerTests { PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager(this.pushGateway, this.registry, ownedScheduler, this.pushRate, "job", this.groupingKey, null); manager.shutdown(); - verify(ownedScheduler).shutdown(); + then(ownedScheduler).should().shutdown(); } @Test @@ -132,7 +131,7 @@ class PrometheusPushGatewayManagerTests { PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager(this.pushGateway, this.registry, otherScheduler, this.pushRate, "job", this.groupingKey, null); manager.shutdown(); - verify(otherScheduler, never()).shutdown(); + then(otherScheduler).should(never()).shutdown(); } @Test @@ -141,8 +140,8 @@ class PrometheusPushGatewayManagerTests { PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager(this.pushGateway, this.registry, this.scheduler, this.pushRate, "job", this.groupingKey, ShutdownOperation.PUSH); manager.shutdown(); - verify(this.future).cancel(false); - verify(this.pushGateway).pushAdd(this.registry, "job", this.groupingKey); + then(this.future).should().cancel(false); + then(this.pushGateway).should().pushAdd(this.registry, "job", this.groupingKey); } @Test @@ -151,8 +150,8 @@ class PrometheusPushGatewayManagerTests { PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager(this.pushGateway, this.registry, this.scheduler, this.pushRate, "job", this.groupingKey, ShutdownOperation.DELETE); manager.shutdown(); - verify(this.future).cancel(false); - verify(this.pushGateway).delete("job", this.groupingKey); + then(this.future).should().cancel(false); + then(this.pushGateway).should().delete("job", this.groupingKey); } @Test @@ -161,15 +160,15 @@ class PrometheusPushGatewayManagerTests { PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager(this.pushGateway, this.registry, this.scheduler, this.pushRate, "job", this.groupingKey, ShutdownOperation.NONE); manager.shutdown(); - verify(this.future).cancel(false); - verifyNoInteractions(this.pushGateway); + then(this.future).should().cancel(false); + then(this.pushGateway).shouldHaveNoInteractions(); } @Test void pushDoesNotThrowException() throws Exception { new PrometheusPushGatewayManager(this.pushGateway, this.registry, this.scheduler, this.pushRate, "job", this.groupingKey, null); - verify(this.scheduler).scheduleAtFixedRate(this.task.capture(), eq(this.pushRate)); + then(this.scheduler).should().scheduleAtFixedRate(this.task.capture(), eq(this.pushRate)); willThrow(RuntimeException.class).given(this.pushGateway).pushAdd(this.registry, "job", this.groupingKey); this.task.getValue().run(); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListenerTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListenerTests.java index c713930302..34763a6fbc 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListenerTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationStartedEvent; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.doReturn; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; /** @@ -99,14 +99,14 @@ class StartupTimeMetricsListenerTests { private ApplicationStartedEvent applicationStartedEvent(Long startupTimeMs) { SpringApplication application = mock(SpringApplication.class); - doReturn(TestMainApplication.class).when(application).getMainApplicationClass(); + given(application.getMainApplicationClass()).willAnswer((invocation) -> TestMainApplication.class); return new ApplicationStartedEvent(application, null, null, (startupTimeMs != null) ? Duration.ofMillis(startupTimeMs) : null); } private ApplicationReadyEvent applicationReadyEvent(Long startupTimeMs) { SpringApplication application = mock(SpringApplication.class); - doReturn(TestMainApplication.class).when(application).getMainApplicationClass(); + given(application.getMainApplicationClass()).willAnswer((invocation) -> TestMainApplication.class); return new ApplicationReadyEvent(application, null, null, (startupTimeMs != null) ? Duration.ofMillis(startupTimeMs) : null); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/mongo/MongoHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/mongo/MongoHealthIndicatorTests.java index 27b23247a5..0ad1de2b2c 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/mongo/MongoHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/mongo/MongoHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,8 @@ import org.springframework.data.mongodb.core.MongoTemplate; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link MongoHealthIndicator}. @@ -46,8 +46,8 @@ class MongoHealthIndicatorTests { Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails().get("version")).isEqualTo("2.6.4"); - verify(commandResult).getString("version"); - verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); + then(commandResult).should().getString("version"); + then(mongoTemplate).should().executeCommand("{ buildInfo: 1 }"); } @Test @@ -58,7 +58,7 @@ class MongoHealthIndicatorTests { Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.DOWN); assertThat((String) health.getDetails().get("error")).contains("Connection failed"); - verify(mongoTemplate).executeCommand("{ buildInfo: 1 }"); + then(mongoTemplate).should().executeCommand("{ buildInfo: 1 }"); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/neo4j/Neo4jHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/neo4j/Neo4jHealthIndicatorTests.java index dd89d5b6cf..88c0bcc73d 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/neo4j/Neo4jHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/neo4j/Neo4jHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,9 +36,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link Neo4jHealthIndicator}. @@ -100,7 +100,7 @@ class Neo4jHealthIndicatorTests { Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getDetails()).containsEntry("server", "4711@My Home"); - verify(session, times(2)).close(); + then(session).should(times(2)).close(); } @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/neo4j/Neo4jReactiveHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/neo4j/Neo4jReactiveHealthIndicatorTests.java index 48af288c9d..01104dbc8d 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/neo4j/Neo4jReactiveHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/neo4j/Neo4jReactiveHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,9 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link Neo4jReactiveHealthIndicator}. @@ -81,7 +81,7 @@ class Neo4jReactiveHealthIndicatorTests { assertThat(health.getDetails()).containsEntry("server", "4711@My Home"); assertThat(health.getDetails()).containsEntry("edition", "some edition"); }).verifyComplete(); - verify(session, times(2)).close(); + then(session).should(times(2)).close(); } @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/quartz/QuartzEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/quartz/QuartzEndpointTests.java index 8f9787af00..2d51fca356 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/quartz/QuartzEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/quartz/QuartzEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,9 +75,8 @@ import org.springframework.util.MultiValueMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link QuartzEndpoint}. @@ -118,9 +117,9 @@ class QuartzEndpointTests { QuartzReport quartzReport = this.endpoint.quartzReport(); assertThat(quartzReport.getJobs().getGroups()).containsOnly("jobSamples", "DEFAULT"); assertThat(quartzReport.getTriggers().getGroups()).containsOnly("triggerSamples"); - verify(this.scheduler).getJobGroupNames(); - verify(this.scheduler).getTriggerGroupNames(); - verifyNoMoreInteractions(this.scheduler); + then(this.scheduler).should().getJobGroupNames(); + then(this.scheduler).should().getTriggerGroupNames(); + then(this.scheduler).shouldHaveNoMoreInteractions(); } @Test @@ -669,9 +668,9 @@ class QuartzEndpointTests { given(sanitizer.sanitize("secret", "value")).willReturn("----"); QuartzJobDetails jobDetails = new QuartzEndpoint(this.scheduler, sanitizer).quartzJob("samples", "hello"); assertThat(jobDetails.getData()).containsOnly(entry("test", "value"), entry("secret", "----")); - verify(sanitizer).sanitize("test", "value"); - verify(sanitizer).sanitize("secret", "value"); - verifyNoMoreInteractions(sanitizer); + then(sanitizer).should().sanitize("test", "value"); + then(sanitizer).should().sanitize("secret", "value"); + then(sanitizer).shouldHaveNoMoreInteractions(); } private void mockJobs(JobDetail... jobs) throws SchedulerException { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java index 0dfd4f2672..564f68e070 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,9 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link RedisHealthIndicator}. @@ -77,7 +77,7 @@ class RedisHealthIndicatorTests { assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L); assertThat(health.getDetails().get("slots_up")).isEqualTo(4L); assertThat(health.getDetails().get("slots_fail")).isEqualTo(0L); - verify(redisConnectionFactory, atLeastOnce()).getConnection(); + then(redisConnectionFactory).should(atLeastOnce()).getConnection(); } @Test @@ -89,7 +89,7 @@ class RedisHealthIndicatorTests { assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L); assertThat(health.getDetails().get("slots_up")).isEqualTo(4L); assertThat(health.getDetails().get("slots_fail")).isEqualTo(0L); - verify(redisConnectionFactory, atLeastOnce()).getConnection(); + then(redisConnectionFactory).should(atLeastOnce()).getConnection(); } @Test @@ -101,7 +101,7 @@ class RedisHealthIndicatorTests { assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L); assertThat(health.getDetails().get("slots_up")).isEqualTo(3L); assertThat(health.getDetails().get("slots_fail")).isEqualTo(1L); - verify(redisConnectionFactory, atLeastOnce()).getConnection(); + then(redisConnectionFactory).should(atLeastOnce()).getConnection(); } private RedisHealthIndicator createHealthIndicator(RedisConnection redisConnection) { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java index cb45f42bfe..f45b25eb92 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/redis/RedisReactiveHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,8 +34,8 @@ import org.springframework.data.redis.connection.ReactiveServerCommands; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link RedisReactiveHealthIndicator}. @@ -63,7 +63,7 @@ class RedisReactiveHealthIndicatorTests { assertThat(h.getDetails()).containsOnlyKeys("version"); assertThat(h.getDetails().get("version")).isEqualTo("2.8.9"); }).verifyComplete(); - verify(redisConnection).closeLater(); + then(redisConnection).should().closeLater(); } @Test @@ -77,7 +77,7 @@ class RedisReactiveHealthIndicatorTests { assertThat(h.getDetails().get("slots_up")).isEqualTo(4L); assertThat(h.getDetails().get("slots_fail")).isEqualTo(0L); }).verifyComplete(); - verify(redisConnectionFactory.getReactiveConnection()).closeLater(); + then(redisConnectionFactory.getReactiveConnection()).should().closeLater(); } @Test @@ -115,7 +115,7 @@ class RedisReactiveHealthIndicatorTests { Mono health = healthIndicator.health(); StepVerifier.create(health).consumeNextWith((h) -> assertThat(h.getStatus()).isEqualTo(Status.DOWN)) .verifyComplete(); - verify(redisConnection).closeLater(); + then(redisConnection).should().closeLater(); } @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java index e74db11946..77f973c656 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,9 @@ import org.springframework.security.web.authentication.switchuser.Authentication import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link AuthenticationAuditListener}. @@ -65,7 +65,7 @@ class AuthenticationAuditListenerTests { this.listener.onApplicationEvent(new InteractiveAuthenticationSuccessEvent( new UsernamePasswordAuthenticationToken("user", "password"), getClass())); // No need to audit this one (it shadows a regular AuthenticationSuccessEvent) - verify(this.publisher, never()).publishEvent(any(ApplicationEvent.class)); + then(this.publisher).should(never()).publishEvent(any(ApplicationEvent.class)); } @Test @@ -105,7 +105,7 @@ class AuthenticationAuditListenerTests { private AuditApplicationEvent handleAuthenticationEvent(AbstractAuthenticationEvent event) { ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(AuditApplicationEvent.class); this.listener.onApplicationEvent(event); - verify(this.publisher).publishEvent(eventCaptor.capture()); + then(this.publisher).should().publishEvent(eventCaptor.capture()); return eventCaptor.getValue(); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthorizationAuditListenerTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthorizationAuditListenerTests.java index 3fb709256e..cbda5c70b1 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthorizationAuditListenerTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthorizationAuditListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,8 +33,8 @@ import org.springframework.security.authentication.AuthenticationCredentialsNotF import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link AuthorizationAuditListener}. @@ -82,7 +82,7 @@ class AuthorizationAuditListenerTests { private AuditApplicationEvent handleAuthorizationEvent(AbstractAuthorizationEvent event) { ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(AuditApplicationEvent.class); this.listener.onApplicationEvent(event); - verify(this.publisher).publishEvent(eventCaptor.capture()); + then(this.publisher).should().publishEvent(eventCaptor.capture()); return eventCaptor.getValue(); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointTests.java index 32a48b4abf..5095187a56 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import org.springframework.session.Session; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link SessionsEndpoint}. @@ -80,7 +80,7 @@ class SessionsEndpointTests { @Test void deleteSession() { this.endpoint.deleteSession(session.getId()); - verify(this.repository).deleteById(session.getId()); + then(this.repository).should().deleteById(session.getId()); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/solr/SolrHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/solr/SolrHealthIndicatorTests.java index 3b3ecb23f2..31223253ac 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/solr/SolrHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/solr/SolrHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,10 +32,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link SolrHealthIndicator} @@ -52,8 +51,8 @@ class SolrHealthIndicatorTests { given(solrClient.request(any(CoreAdminRequest.class), isNull())).willReturn(mockResponse(0)); SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient); assertHealth(healthIndicator, Status.UP, 0, "root"); - verify(solrClient, times(1)).request(any(CoreAdminRequest.class), isNull()); - verifyNoMoreInteractions(solrClient); + then(solrClient).should().request(any(CoreAdminRequest.class), isNull()); + then(solrClient).shouldHaveNoMoreInteractions(); } @Test @@ -62,8 +61,8 @@ class SolrHealthIndicatorTests { given(solrClient.request(any(CoreAdminRequest.class), isNull())).willReturn(mockResponse(400)); SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient); assertHealth(healthIndicator, Status.DOWN, 400, "root"); - verify(solrClient, times(1)).request(any(CoreAdminRequest.class), isNull()); - verifyNoMoreInteractions(solrClient); + then(solrClient).should().request(any(CoreAdminRequest.class), isNull()); + then(solrClient).shouldHaveNoMoreInteractions(); } @Test @@ -74,9 +73,9 @@ class SolrHealthIndicatorTests { given(solrClient.ping()).willReturn(mockPingResponse(0)); SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient); assertHealth(healthIndicator, Status.UP, 0, "particular core"); - verify(solrClient, times(1)).request(any(CoreAdminRequest.class), isNull()); - verify(solrClient, times(1)).ping(); - verifyNoMoreInteractions(solrClient); + then(solrClient).should().request(any(CoreAdminRequest.class), isNull()); + then(solrClient).should().ping(); + then(solrClient).shouldHaveNoMoreInteractions(); } @Test @@ -87,9 +86,9 @@ class SolrHealthIndicatorTests { given(solrClient.ping()).willReturn(mockPingResponse(400)); SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient); assertHealth(healthIndicator, Status.DOWN, 400, "particular core"); - verify(solrClient, times(1)).request(any(CoreAdminRequest.class), isNull()); - verify(solrClient, times(1)).ping(); - verifyNoMoreInteractions(solrClient); + then(solrClient).should().request(any(CoreAdminRequest.class), isNull()); + then(solrClient).should().ping(); + then(solrClient).shouldHaveNoMoreInteractions(); } @Test @@ -101,8 +100,8 @@ class SolrHealthIndicatorTests { Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.DOWN); assertThat((String) health.getDetails().get("error")).contains("Connection failed"); - verify(solrClient, times(1)).request(any(CoreAdminRequest.class), isNull()); - verifyNoMoreInteractions(solrClient); + then(solrClient).should().request(any(CoreAdminRequest.class), isNull()); + then(solrClient).shouldHaveNoMoreInteractions(); } @Test @@ -113,12 +112,12 @@ class SolrHealthIndicatorTests { given(solrClient.ping()).willReturn(mockPingResponse(0)); SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient); healthIndicator.health(); - verify(solrClient, times(1)).request(any(CoreAdminRequest.class), isNull()); - verify(solrClient, times(1)).ping(); - verifyNoMoreInteractions(solrClient); + then(solrClient).should().request(any(CoreAdminRequest.class), isNull()); + then(solrClient).should().ping(); + then(solrClient).shouldHaveNoMoreInteractions(); healthIndicator.health(); - verify(solrClient, times(2)).ping(); - verifyNoMoreInteractions(solrClient); + then(solrClient).should(times(2)).ping(); + then(solrClient).shouldHaveNoMoreInteractions(); } private void assertHealth(SolrHealthIndicator healthIndicator, Status expectedStatus, int expectedStatusCode, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/SharedMetadataReaderFactoryContextInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/SharedMetadataReaderFactoryContextInitializerTests.java index 5db77876fe..ba4f4aa661 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/SharedMetadataReaderFactoryContextInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/SharedMetadataReaderFactoryContextInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,8 +39,8 @@ import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link SharedMetadataReaderFactoryContextInitializer}. @@ -84,7 +84,7 @@ class SharedMetadataReaderFactoryContextInitializerTests { assertThat(bean).isSameAs(configurationAnnotationPostProcessor); ArgumentCaptor metadataReaderFactory = ArgumentCaptor .forClass(MetadataReaderFactory.class); - verify(configurationAnnotationPostProcessor).setMetadataReaderFactory(metadataReaderFactory.capture()); + then(configurationAnnotationPostProcessor).should().setMetadataReaderFactory(metadataReaderFactory.capture()); assertThat(metadataReaderFactory.getValue()) .isInstanceOf(ConcurrentReferenceCachingMetadataReaderFactory.class); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java index db625a906a..2a46639c3b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,9 +84,9 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link RabbitAutoConfiguration}. @@ -179,10 +179,10 @@ class RabbitAutoConfigurationTests { given(rcf.newConnection(isNull(), eq(addresses), anyString())).willReturn(mock(Connection.class)); ReflectionTestUtils.setField(connectionFactory, "rabbitConnectionFactory", rcf); connectionFactory.createConnection(); - verify(rcf).newConnection(isNull(), eq(addresses), eq("test#0")); + then(rcf).should().newConnection(isNull(), eq(addresses), eq("test#0")); connectionFactory.resetConnection(); connectionFactory.createConnection(); - verify(rcf).newConnection(isNull(), eq(addresses), eq("test#1")); + then(rcf).should().newConnection(isNull(), eq(addresses), eq("test#1")); }); } @@ -360,10 +360,11 @@ class RabbitAutoConfigurationTests { RabbitTemplate template = mock(RabbitTemplate.class); ConnectionFactory connectionFactory = mock(ConnectionFactory.class); configurer.configure(template, connectionFactory); - verify(template).setMessageConverter(context.getBean("myMessageConverter", MessageConverter.class)); - verify(template).setExchange("my-exchange"); - verify(template).setRoutingKey("my-routing-key"); - verify(template).setDefaultReceiveQueue("default-queue"); + then(template).should() + .setMessageConverter(context.getBean("myMessageConverter", MessageConverter.class)); + then(template).should().setExchange("my-exchange"); + then(template).should().setRoutingKey("my-routing-key"); + then(template).should().setDefaultReceiveQueue("default-queue"); }); } @@ -434,7 +435,7 @@ class RabbitAutoConfigurationTests { SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context .getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class); rabbitListenerContainerFactory.setBatchSize(10); - verify(rabbitListenerContainerFactory).setBatchSize(10); + then(rabbitListenerContainerFactory).should().setBatchSize(10); assertThat(rabbitListenerContainerFactory.getAdviceChain()).isNull(); }); } @@ -554,9 +555,9 @@ class RabbitAutoConfigurationTests { .getBean(SimpleRabbitListenerContainerFactoryConfigurer.class); SimpleRabbitListenerContainerFactory factory = mock(SimpleRabbitListenerContainerFactory.class); configurer.configure(factory, mock(ConnectionFactory.class)); - verify(factory).setConcurrentConsumers(5); - verify(factory).setMaxConcurrentConsumers(10); - verify(factory).setPrefetchCount(40); + then(factory).should().setConcurrentConsumers(5); + then(factory).should().setMaxConcurrentConsumers(10); + then(factory).should().setPrefetchCount(40); }); } @@ -568,7 +569,7 @@ class RabbitAutoConfigurationTests { .getBean(SimpleRabbitListenerContainerFactoryConfigurer.class); SimpleRabbitListenerContainerFactory factory = mock(SimpleRabbitListenerContainerFactory.class); configurer.configure(factory, mock(ConnectionFactory.class)); - verify(factory).setConsumerBatchEnabled(true); + then(factory).should().setConsumerBatchEnabled(true); }); } @@ -583,9 +584,9 @@ class RabbitAutoConfigurationTests { .getBean(DirectRabbitListenerContainerFactoryConfigurer.class); DirectRabbitListenerContainerFactory factory = mock(DirectRabbitListenerContainerFactory.class); configurer.configure(factory, mock(ConnectionFactory.class)); - verify(factory).setConsumersPerQueue(5); - verify(factory).setPrefetchCount(40); - verify(factory).setDeBatchingEnabled(false); + then(factory).should().setConsumersPerQueue(5); + then(factory).should().setPrefetchCount(40); + then(factory).should().setDeBatchingEnabled(false); }); } @@ -608,7 +609,7 @@ class RabbitAutoConfigurationTests { Message message = mock(Message.class); Exception ex = new Exception("test"); mir.recover(new Object[] { "foo", message }, ex); - verify(messageRecoverer).recover(message, ex); + then(messageRecoverer).should().recover(message, ex); RetryTemplate retryTemplate = (RetryTemplate) ReflectionTestUtils.getField(advice, "retryOperations"); assertThat(retryTemplate).isNotNull(); SimpleRetryPolicy retryPolicy = (SimpleRetryPolicy) ReflectionTestUtils.getField(retryTemplate, "retryPolicy"); @@ -849,8 +850,8 @@ class RabbitAutoConfigurationTests { ConnectionFactoryCustomizer.class); InOrder inOrder = inOrder(firstCustomizer, secondCustomizer); com.rabbitmq.client.ConnectionFactory targetConnectionFactory = getTargetConnectionFactory(context); - inOrder.verify(firstCustomizer).customize(targetConnectionFactory); - inOrder.verify(secondCustomizer).customize(targetConnectionFactory); + then(firstCustomizer).should(inOrder).customize(targetConnectionFactory); + then(secondCustomizer).should(inOrder).customize(targetConnectionFactory); inOrder.verifyNoMoreInteractions(); }); } @@ -859,7 +860,7 @@ class RabbitAutoConfigurationTests { @SuppressWarnings("unchecked") void whenASimpleContainerCustomizerIsDefinedThenItIsCalledToConfigureTheContainer() { this.contextRunner.withUserConfiguration(SimpleContainerCustomizerConfiguration.class) - .run((context) -> verify(context.getBean(ContainerCustomizer.class)) + .run((context) -> then(context.getBean(ContainerCustomizer.class)).should() .configure(any(SimpleMessageListenerContainer.class))); } @@ -868,7 +869,7 @@ class RabbitAutoConfigurationTests { void whenADirectContainerCustomizerIsDefinedThenItIsCalledToConfigureTheContainer() { this.contextRunner.withUserConfiguration(DirectContainerCustomizerConfiguration.class) .withPropertyValues("spring.rabbitmq.listener.type:direct") - .run((context) -> verify(context.getBean(ContainerCustomizer.class)) + .run((context) -> then(context.getBean(ContainerCustomizer.class)).should() .configure(any(DirectMessageListenerContainer.class))); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfigurationTests.java index bd3b7ba736..aef791160e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitStreamConfigurationTests.java @@ -40,9 +40,8 @@ import org.springframework.rabbit.stream.producer.RabbitStreamTemplate; import org.springframework.rabbit.stream.support.converter.StreamMessageConverter; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link RabbitStreamConfiguration}. @@ -67,7 +66,7 @@ class RabbitStreamConfigurationTests { assertThat(listenerContainer).extracting("consumerCustomizer").isNotNull(); assertThat(context.getBean(StreamRabbitListenerContainerFactory.class)) .extracting("nativeListener", InstanceOfAssertFactories.BOOLEAN).isFalse(); - verify(context.getBean(ContainerCustomizer.class)).configure(listenerContainer); + then(context.getBean(ContainerCustomizer.class)).should().configure(listenerContainer); assertThat(context).hasSingleBean(Environment.class); }); } @@ -105,12 +104,12 @@ class RabbitStreamConfigurationTests { EnvironmentBuilder builder = mock(EnvironmentBuilder.class); RabbitProperties properties = new RabbitProperties(); RabbitStreamConfiguration.configure(builder, properties); - verify(builder).port(5552); - verify(builder).host("localhost"); - verify(builder).lazyInitialization(true); - verify(builder).username("guest"); - verify(builder).password("guest"); - verifyNoMoreInteractions(builder); + then(builder).should().port(5552); + then(builder).should().host("localhost"); + then(builder).should().lazyInitialization(true); + then(builder).should().username("guest"); + then(builder).should().password("guest"); + then(builder).shouldHaveNoMoreInteractions(); } @Test @@ -119,7 +118,7 @@ class RabbitStreamConfigurationTests { RabbitProperties properties = new RabbitProperties(); properties.getStream().setPort(5553); RabbitStreamConfiguration.configure(builder, properties); - verify(builder).port(5553); + then(builder).should().port(5553); } @Test @@ -128,7 +127,7 @@ class RabbitStreamConfigurationTests { RabbitProperties properties = new RabbitProperties(); properties.getStream().setHost("stream.rabbit.example.com"); RabbitStreamConfiguration.configure(builder, properties); - verify(builder).host("stream.rabbit.example.com"); + then(builder).should().host("stream.rabbit.example.com"); } @Test @@ -138,8 +137,8 @@ class RabbitStreamConfigurationTests { properties.setUsername("alice"); properties.setPassword("secret"); RabbitStreamConfiguration.configure(builder, properties); - verify(builder).username("alice"); - verify(builder).password("secret"); + then(builder).should().username("alice"); + then(builder).should().password("secret"); } @Test @@ -151,8 +150,8 @@ class RabbitStreamConfigurationTests { properties.getStream().setUsername("bob"); properties.getStream().setPassword("confidential"); RabbitStreamConfiguration.configure(builder, properties); - verify(builder).username("bob"); - verify(builder).password("confidential"); + then(builder).should().username("bob"); + then(builder).should().password("confidential"); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceInitializerTests.java index 88fabb00d1..15d00f526c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ import org.junit.jupiter.api.Test; import org.springframework.core.io.DefaultResourceLoader; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link BatchDataSourceInitializer}. @@ -42,7 +42,7 @@ class BatchDataSourceInitializerTests { BatchDataSourceInitializer initializer = new BatchDataSourceInitializer(dataSource, new DefaultResourceLoader(), properties); assertThat(initializer.getDatabaseName()).isEqualTo("test"); - verifyNoInteractions(dataSource); + then(dataSource).shouldHaveNoInteractions(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceScriptDatabaseInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceScriptDatabaseInitializerTests.java index d5c230d0d2..51367e65a8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceScriptDatabaseInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceScriptDatabaseInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.sql.init.DatabaseInitializationSettings; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link BatchDataSourceScriptDatabaseInitializer}. @@ -42,7 +42,7 @@ class BatchDataSourceScriptDatabaseInitializerTests { properties.getJdbc()); assertThat(settings.getSchemaLocations()) .containsOnly("classpath:org/springframework/batch/core/schema-test.sql"); - verifyNoInteractions(dataSource); + then(dataSource).shouldHaveNoInteractions(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java index 25e96b44b8..a7740adcb1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,9 +74,9 @@ import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link CacheAutoConfiguration}. @@ -573,7 +573,7 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { .run((context) -> { assertThat(getCacheManager(context, SpringEmbeddedCacheManager.class).getCacheNames()) .containsOnly("foo", "bar"); - verify(context.getBean(ConfigurationBuilder.class), times(2)).build(); + then(context.getBean(ConfigurationBuilder.class)).should(times(2)).build(); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationIntegrationTests.java index fb31156f8a..2f4aa175f3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Integration tests for {@link CassandraAutoConfiguration}. @@ -61,7 +61,7 @@ class CassandraAutoConfigurationIntegrationTests { context.getBean(CqlSession.class); DriverConfigLoader driverConfigLoader = context.getBean(DriverConfigLoader.class); context.close(); - verify(driverConfigLoader).close(); + then(driverConfigLoader).should().close(); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/domain/EntityScannerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/domain/EntityScannerTests.java index 36c2cc3160..a06d3ac9c1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/domain/EntityScannerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/domain/EntityScannerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,9 +41,8 @@ import org.springframework.core.type.filter.AnnotationTypeFilter; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link EntityScanner}. @@ -112,10 +111,10 @@ class EntityScannerTests { TestEntityScanner scanner = new TestEntityScanner(context, candidateComponentProvider); scanner.scan(Entity.class); ArgumentCaptor annotationTypeFilter = ArgumentCaptor.forClass(AnnotationTypeFilter.class); - verify(candidateComponentProvider).addIncludeFilter(annotationTypeFilter.capture()); - verify(candidateComponentProvider) + then(candidateComponentProvider).should().addIncludeFilter(annotationTypeFilter.capture()); + then(candidateComponentProvider).should() .findCandidateComponents("org.springframework.boot.autoconfigure.domain.scan"); - verifyNoMoreInteractions(candidateComponentProvider); + then(candidateComponentProvider).shouldHaveNoMoreInteractions(); assertThat(annotationTypeFilter.getValue().getAnnotationType()).isEqualTo(Entity.class); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java index ed75a571f8..d1f3049ebc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java @@ -45,8 +45,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link ElasticsearchRestClientAutoConfiguration}. @@ -268,7 +268,7 @@ class ElasticsearchRestClientAutoConfigurationTests { assertThat(context).hasSingleBean(Sniffer.class); Sniffer sniffer = context.getBean(Sniffer.class); assertThat(sniffer).isSameAs(customSniffer); - verifyNoInteractions(customSniffer); + then(customSniffer).shouldHaveNoInteractions(); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/Flyway7xAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/Flyway7xAutoConfigurationTests.java index 2a36759620..f37c7fb6a9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/Flyway7xAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/Flyway7xAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,9 @@ import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link FlywayAutoConfiguration} with Flyway 7.x. @@ -70,8 +70,8 @@ class Flyway7xAutoConfigurationTests { assertThat(flyway.getConfiguration().getCallbacks()).hasSize(2); assertThat(flyway.getConfiguration().getCallbacks()).containsExactlyInAnyOrder(callbackTwo, callbackOne); - verify(callbackOne, atLeastOnce()).handle(any(Event.class), any(Context.class)); - verify(callbackTwo, atLeastOnce()).handle(any(Event.class), any(Context.class)); + then(callbackOne).should(atLeastOnce()).handle(any(Event.class), any(Context.class)); + then(callbackTwo).should(atLeastOnce()).handle(any(Event.class), any(Context.class)); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationDataSourceInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationDataSourceInitializerTests.java index c98814cf00..41b0559786 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationDataSourceInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationDataSourceInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ import org.junit.jupiter.api.Test; import org.springframework.core.io.DefaultResourceLoader; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link IntegrationDataSourceInitializer}. @@ -42,7 +42,7 @@ class IntegrationDataSourceInitializerTests { IntegrationDataSourceInitializer initializer = new IntegrationDataSourceInitializer(dataSource, new DefaultResourceLoader(), properties); assertThat(initializer.getDatabaseName()).isEqualTo("test"); - verifyNoInteractions(dataSource); + then(dataSource).shouldHaveNoInteractions(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationDataSourceScriptDatabaseInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationDataSourceScriptDatabaseInitializerTests.java index 6e6a719f86..8ee28ad832 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationDataSourceScriptDatabaseInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationDataSourceScriptDatabaseInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.sql.init.DatabaseInitializationSettings; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link IntegrationDataSourceScriptDatabaseInitializer}. @@ -42,7 +42,7 @@ class IntegrationDataSourceScriptDatabaseInitializerTests { properties.getJdbc()); assertThat(settings.getSchemaLocations()) .containsOnly("classpath:org/springframework/integration/jdbc/schema-test.sql"); - verifyNoInteractions(dataSource); + then(dataSource).shouldHaveNoInteractions(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslatorTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslatorTests.java index d405bb7f0b..f0dae1359e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslatorTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqExceptionTranslatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,9 +31,9 @@ import org.springframework.jdbc.BadSqlGrammarException; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.never; /** * Tests for {@link JooqExceptionTranslator} @@ -54,7 +54,7 @@ class JooqExceptionTranslatorTests { given(context.sqlException()).willReturn(sqlException); this.exceptionTranslator.exception(context); ArgumentCaptor captor = ArgumentCaptor.forClass(RuntimeException.class); - verify(context).exception(captor.capture()); + then(context).should().exception(captor.capture()); assertThat(captor.getValue()).isInstanceOf(BadSqlGrammarException.class); } @@ -66,7 +66,7 @@ class JooqExceptionTranslatorTests { given(configuration.dialect()).willReturn(SQLDialect.POSTGRES); given(context.sqlException()).willReturn(new SQLException(null, null, 123456789)); this.exceptionTranslator.exception(context); - verify(context, times(0)).exception(any()); + then(context).should(never()).exception(any()); } static Object[] exceptionTranslation() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqPropertiesTests.java index 98d10be1db..88263b4bb3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,9 @@ import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link JooqProperties}. @@ -59,7 +59,7 @@ class JooqPropertiesTests { DataSource dataSource = mockStandaloneDataSource(); SQLDialect sqlDialect = properties.determineSqlDialect(dataSource); assertThat(sqlDialect).isEqualTo(SQLDialect.POSTGRES); - verify(dataSource, never()).getConnection(); + then(dataSource).should(never()).getConnection(); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java index c9305cf486..87050a7ab7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java @@ -76,9 +76,9 @@ import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link KafkaAutoConfiguration}. @@ -333,10 +333,10 @@ class KafkaAutoConfigurationTests { .asProperties(); assertThat((List) configs.get(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG)) .containsExactly("localhost:9092", "localhost:9093"); - verify(context.getBean("&firstStreamsBuilderFactoryBean", StreamsBuilderFactoryBean.class), never()) - .setAutoStartup(false); - verify(context.getBean("&secondStreamsBuilderFactoryBean", StreamsBuilderFactoryBean.class), - never()).setAutoStartup(false); + then(context.getBean("&firstStreamsBuilderFactoryBean", StreamsBuilderFactoryBean.class)) + .should(never()).setAutoStartup(false); + then(context.getBean("&secondStreamsBuilderFactoryBean", StreamsBuilderFactoryBean.class)) + .should(never()).setAutoStartup(false); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mail/MailSenderAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mail/MailSenderAutoConfigurationTests.java index b8eede2a23..3b4089357d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mail/MailSenderAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mail/MailSenderAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,10 +37,9 @@ import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.JavaMailSenderImpl; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link MailSenderAutoConfiguration}. @@ -223,7 +222,7 @@ class MailSenderAutoConfigurationTests { .withPropertyValues("spring.mail.host:10.0.0.23", "spring.mail.test-connection:true").run((context) -> { assertThat(context).hasSingleBean(JavaMailSenderImpl.class); JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class); - verify(mailSender, times(1)).testConnection(); + then(mailSender).should().testConnection(); }); } @@ -234,7 +233,7 @@ class MailSenderAutoConfigurationTests { .run((context) -> { assertThat(context).hasSingleBean(JavaMailSenderImpl.class); JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class); - verify(mailSender, never()).testConnection(); + then(mailSender).should(never()).testConnection(); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactorySupportTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactorySupportTests.java index 6e697ea881..1829ec803c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactorySupportTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactorySupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,8 @@ import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link MongoClientFactorySupport}. @@ -97,7 +97,7 @@ abstract class MongoClientFactorySupportTests { void customizerIsInvoked() { MongoClientSettingsBuilderCustomizer customizer = mock(MongoClientSettingsBuilderCustomizer.class); createMongoClient(customizer); - verify(customizer).customize(any(MongoClientSettings.Builder.class)); + then(customizer).should().customize(any(MongoClientSettings.Builder.class)); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java index f33dc26f63..2813367feb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,8 @@ import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link HibernateProperties}. @@ -141,14 +141,14 @@ class HibernatePropertiesTests { assertThat(hibernateProperties).doesNotContainKey(AvailableSettings.HBM2DDL_AUTO); assertThat(hibernateProperties).containsEntry(AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop-and-create"); - verify(this.ddlAutoSupplier, never()).get(); + then(this.ddlAutoSupplier).should(never()).get(); })); } private ContextConsumer assertDefaultDdlAutoNotInvoked(String expectedDdlAuto) { return assertHibernateProperties((hibernateProperties) -> { assertThat(hibernateProperties).containsEntry(AvailableSettings.HBM2DDL_AUTO, expectedDdlAuto); - verify(this.ddlAutoSupplier, never()).get(); + then(this.ddlAutoSupplier).should(never()).get(); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java index e0f891b3d4..f307b04c11 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,8 +73,8 @@ import org.springframework.transaction.PlatformTransactionManager; import org.springframework.util.Assert; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link QuartzAutoConfiguration}. @@ -165,7 +165,7 @@ class QuartzAutoConfigurationTests { Scheduler scheduler = context.getBean(Scheduler.class); assertThat(scheduler.getMetaData().getThreadPoolSize()).isEqualTo(50); Executor executor = context.getBean(Executor.class); - verifyNoInteractions(executor); + then(executor).shouldHaveNoInteractions(); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializerTests.java index 488118cb92..be5656f172 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,8 @@ import org.springframework.core.io.ResourceLoader; import org.springframework.jdbc.core.JdbcTemplate; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link QuartzDataSourceInitializer}. @@ -60,7 +60,7 @@ class QuartzDataSourceInitializerTests { QuartzDataSourceInitializer initializer = new QuartzDataSourceInitializer(dataSource, new DefaultResourceLoader(), properties); assertThat(initializer.getDatabaseName()).isEqualTo("test"); - verifyNoInteractions(dataSource); + then(dataSource).shouldHaveNoInteractions(); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceScriptDatabaseInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceScriptDatabaseInitializerTests.java index dcfc5db18e..c1408c97f5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceScriptDatabaseInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceScriptDatabaseInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +26,8 @@ import org.springframework.boot.sql.init.DatabaseInitializationSettings; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link QuartzDataSourceScriptDatabaseInitializer}. @@ -46,7 +45,7 @@ class QuartzDataSourceScriptDatabaseInitializerTests { properties); assertThat(settings.getSchemaLocations()) .containsOnly("classpath:org/quartz/impl/jdbcjobstore/tables_test.sql"); - verifyNoInteractions(dataSource); + then(dataSource).shouldHaveNoInteractions(); } @Test @@ -58,7 +57,7 @@ class QuartzDataSourceScriptDatabaseInitializerTests { mock(DataSource.class), properties); ResourceDatabasePopulator populator = mock(ResourceDatabasePopulator.class); initializer.customize(populator); - verify(populator).setCommentPrefixes("##", "--"); + then(populator).should().setCommentPrefixes("##", "--"); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/JdbcSessionDataSourceInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/JdbcSessionDataSourceInitializerTests.java index 1dc3a67120..a02429a9c1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/JdbcSessionDataSourceInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/JdbcSessionDataSourceInitializerTests.java @@ -23,8 +23,8 @@ import org.junit.jupiter.api.Test; import org.springframework.core.io.DefaultResourceLoader; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link JdbcSessionDataSourceInitializer}. @@ -42,7 +42,7 @@ class JdbcSessionDataSourceInitializerTests { JdbcSessionDataSourceInitializer initializer = new JdbcSessionDataSourceInitializer(dataSource, new DefaultResourceLoader(), properties); assertThat(initializer.getDatabaseName()).isEqualTo("test"); - verifyNoInteractions(dataSource); + then(dataSource).shouldHaveNoInteractions(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/JdbcSessionDataSourceScriptDatabaseInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/JdbcSessionDataSourceScriptDatabaseInitializerTests.java index 0a7e0bf9b0..3b78e05e73 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/JdbcSessionDataSourceScriptDatabaseInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/JdbcSessionDataSourceScriptDatabaseInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.sql.init.DatabaseInitializationSettings; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link JdbcSessionDataSourceScriptDatabaseInitializer}. @@ -42,7 +42,7 @@ class JdbcSessionDataSourceScriptDatabaseInitializerTests { properties); assertThat(settings.getSchemaLocations()) .containsOnly("classpath:org/springframework/session/jdbc/schema-test.sql"); - verifyNoInteractions(dataSource); + then(dataSource).shouldHaveNoInteractions(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java index d21ad5c84b..857a04505a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,9 +36,8 @@ import org.springframework.session.jdbc.JdbcIndexedSessionRepository; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Hazelcast specific tests for {@link SessionAutoConfiguration}. @@ -80,7 +79,7 @@ class SessionAutoConfigurationHazelcastTests extends AbstractSessionAutoConfigur assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", (int) new ServerProperties().getServlet().getSession().getTimeout().getSeconds()); HazelcastInstance hazelcastInstance = context.getBean(HazelcastInstance.class); - verify(hazelcastInstance, times(1)).getMap("spring:session:sessions"); + then(hazelcastInstance).should().getMap("spring:session:sessions"); } @Test @@ -89,7 +88,7 @@ class SessionAutoConfigurationHazelcastTests extends AbstractSessionAutoConfigur "spring.session.hazelcast.map-name=foo:bar:biz").run((context) -> { validateSessionRepository(context, Hazelcast4IndexedSessionRepository.class); HazelcastInstance hazelcastInstance = context.getBean(HazelcastInstance.class); - verify(hazelcastInstance, times(1)).getMap("foo:bar:biz"); + then(hazelcastInstance).should().getMap("foo:bar:biz"); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionPropertiesTests.java index 7d7286b1c3..4dc24f60aa 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ import java.util.function.Supplier; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link SessionProperties}. @@ -39,7 +39,7 @@ class SessionPropertiesTests { properties.setTimeout(Duration.ofMinutes(1)); Supplier fallback = mock(Supplier.class); assertThat(properties.determineTimeout(fallback)).isEqualTo(Duration.ofMinutes(1)); - verifyNoInteractions(fallback); + then(fallback).shouldHaveNoInteractions(); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfigurationTests.java index da16bf270e..5b1c97250b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,8 +43,8 @@ import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link TaskExecutionAutoConfiguration}. @@ -119,7 +119,7 @@ class TaskExecutionAutoConfigurationTests { this.contextRunner.withUserConfiguration(TaskExecutorCustomizerConfig.class).run((context) -> { TaskExecutorCustomizer customizer = context.getBean(TaskExecutorCustomizer.class); ThreadPoolTaskExecutor executor = context.getBean(TaskExecutorBuilder.class).build(); - verify(customizer).customize(executor); + then(customizer).should().customize(executor); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/template/TemplateAvailabilityProvidersTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/template/TemplateAvailabilityProvidersTests.java index e89efe4468..903e04463f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/template/TemplateAvailabilityProvidersTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/template/TemplateAvailabilityProvidersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,9 +32,9 @@ import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link TemplateAvailabilityProviders}. @@ -76,7 +76,7 @@ class TemplateAvailabilityProvidersTests { given(applicationContext.getClassLoader()).willReturn(this.classLoader); TemplateAvailabilityProviders providers = new TemplateAvailabilityProviders(applicationContext); assertThat(providers.getProviders()).isNotEmpty(); - verify(applicationContext).getClassLoader(); + then(applicationContext).should().getClassLoader(); } @Test @@ -145,7 +145,8 @@ class TemplateAvailabilityProvidersTests { TemplateAvailabilityProvider found = this.providers.getProvider(this.view, this.environment, this.classLoader, this.resourceLoader); assertThat(found).isNull(); - verify(this.provider).isTemplateAvailable(this.view, this.environment, this.classLoader, this.resourceLoader); + then(this.provider).should().isTemplateAvailable(this.view, this.environment, this.classLoader, + this.resourceLoader); } @Test @@ -164,7 +165,7 @@ class TemplateAvailabilityProvidersTests { .willReturn(true); this.providers.getProvider(this.view, this.environment, this.classLoader, this.resourceLoader); this.providers.getProvider(this.view, this.environment, this.classLoader, this.resourceLoader); - verify(this.provider, times(1)).isTemplateAvailable(this.view, this.environment, this.classLoader, + then(this.provider).should().isTemplateAvailable(this.view, this.environment, this.classLoader, this.resourceLoader); } @@ -172,7 +173,7 @@ class TemplateAvailabilityProvidersTests { void getProviderShouldCacheNoMatchResult() { this.providers.getProvider(this.view, this.environment, this.classLoader, this.resourceLoader); this.providers.getProvider(this.view, this.environment, this.classLoader, this.resourceLoader); - verify(this.provider, times(1)).isTemplateAvailable(this.view, this.environment, this.classLoader, + then(this.provider).should().isTemplateAvailable(this.view, this.environment, this.classLoader, this.resourceLoader); } @@ -183,7 +184,7 @@ class TemplateAvailabilityProvidersTests { this.environment.setProperty("spring.template.provider.cache", "false"); this.providers.getProvider(this.view, this.environment, this.classLoader, this.resourceLoader); this.providers.getProvider(this.view, this.environment, this.classLoader, this.resourceLoader); - verify(this.provider, times(2)).isTemplateAvailable(this.view, this.environment, this.classLoader, + then(this.provider).should(times(2)).isTemplateAvailable(this.view, this.environment, this.classLoader, this.resourceLoader); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidatorAdapterTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidatorAdapterTests.java index ba698845ee..f11535abfe 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidatorAdapterTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidatorAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,10 +33,9 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link ValidatorAdapter}. @@ -63,11 +62,11 @@ class ValidatorAdapterTests { void wrapperInvokesCallbackOnNonManagedBean() { this.contextRunner.withUserConfiguration(NonManagedBeanConfig.class).run((context) -> { LocalValidatorFactoryBean validator = context.getBean(NonManagedBeanConfig.class).validator; - verify(validator, times(1)).setApplicationContext(any(ApplicationContext.class)); - verify(validator, times(1)).afterPropertiesSet(); - verify(validator, never()).destroy(); + then(validator).should().setApplicationContext(any(ApplicationContext.class)); + then(validator).should().afterPropertiesSet(); + then(validator).should(never()).destroy(); context.close(); - verify(validator, times(1)).destroy(); + then(validator).should().destroy(); }); } @@ -75,11 +74,11 @@ class ValidatorAdapterTests { void wrapperDoesNotInvokeCallbackOnManagedBean() { this.contextRunner.withUserConfiguration(ManagedBeanConfig.class).run((context) -> { LocalValidatorFactoryBean validator = context.getBean(ManagedBeanConfig.class).validator; - verify(validator, never()).setApplicationContext(any(ApplicationContext.class)); - verify(validator, never()).afterPropertiesSet(); - verify(validator, never()).destroy(); + then(validator).should(never()).setApplicationContext(any(ApplicationContext.class)); + then(validator).should(never()).afterPropertiesSet(); + then(validator).should(never()).destroy(); context.close(); - verify(validator, never()).destroy(); + then(validator).should(never()).destroy(); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java index ed5767c4e5..72b592b971 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,9 +44,8 @@ import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link RestTemplateAutoConfiguration} @@ -115,7 +114,7 @@ class RestTemplateAutoConfigurationTests { assertThat(context).hasSingleBean(RestTemplate.class); RestTemplate restTemplate = context.getBean(RestTemplate.class); RestTemplateCustomizer customizer = context.getBean(RestTemplateCustomizer.class); - verify(customizer).customize(restTemplate); + then(customizer).should().customize(restTemplate); }); } @@ -128,7 +127,7 @@ class RestTemplateAutoConfigurationTests { assertThat(restTemplate.getMessageConverters()).hasSize(1); assertThat(restTemplate.getMessageConverters().get(0)) .isInstanceOf(CustomHttpMessageConverter.class); - verifyNoInteractions(context.getBean(RestTemplateCustomizer.class)); + then(context.getBean(RestTemplateCustomizer.class)).shouldHaveNoInteractions(); }); } @@ -143,7 +142,7 @@ class RestTemplateAutoConfigurationTests { assertThat(restTemplate.getMessageConverters().get(0)) .isInstanceOf(CustomHttpMessageConverter.class); RestTemplateCustomizer customizer = context.getBean(RestTemplateCustomizer.class); - verify(customizer).customize(restTemplate); + then(customizer).should().customize(restTemplate); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java index 04330276d6..db30924210 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,8 +54,8 @@ import org.springframework.test.context.support.TestPropertySourceUtils; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link JettyWebServerFactoryCustomizer}. @@ -85,14 +85,14 @@ class JettyWebServerFactoryCustomizerTests { this.environment.setProperty("DYNO", "-"); ConfigurableJettyWebServerFactory factory = mock(ConfigurableJettyWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(true); + then(factory).should().setUseForwardHeaders(true); } @Test void defaultUseForwardHeaders() { ConfigurableJettyWebServerFactory factory = mock(ConfigurableJettyWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(false); + then(factory).should().setUseForwardHeaders(false); } @Test @@ -100,7 +100,7 @@ class JettyWebServerFactoryCustomizerTests { this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE); ConfigurableJettyWebServerFactory factory = mock(ConfigurableJettyWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(true); + then(factory).should().setUseForwardHeaders(true); } @Test @@ -109,7 +109,7 @@ class JettyWebServerFactoryCustomizerTests { this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NONE); ConfigurableJettyWebServerFactory factory = mock(ConfigurableJettyWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(false); + then(factory).should().setUseForwardHeaders(false); } @Test @@ -256,7 +256,7 @@ class JettyWebServerFactoryCustomizerTests { this.serverProperties.setForwardHeadersStrategy(ForwardHeadersStrategy.NATIVE); ConfigurableJettyWebServerFactory factory = mock(ConfigurableJettyWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(true); + then(factory).should().setUseForwardHeaders(true); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java index 9304603f38..dbb9785edc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java @@ -38,10 +38,10 @@ import org.springframework.util.unit.DataSize; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link NettyWebServerFactoryCustomizer}. @@ -75,14 +75,14 @@ class NettyWebServerFactoryCustomizerTests { this.environment.setProperty("DYNO", "-"); NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(true); + then(factory).should().setUseForwardHeaders(true); } @Test void defaultUseForwardHeaders() { NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(false); + then(factory).should().setUseForwardHeaders(false); } @Test @@ -90,7 +90,7 @@ class NettyWebServerFactoryCustomizerTests { this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE); NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(true); + then(factory).should().setUseForwardHeaders(true); } @Test @@ -99,7 +99,7 @@ class NettyWebServerFactoryCustomizerTests { this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NONE); NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(false); + then(factory).should().setUseForwardHeaders(false); } @Test @@ -136,7 +136,7 @@ class NettyWebServerFactoryCustomizerTests { nettyProperties.setMaxInitialLineLength(DataSize.ofKilobytes(32)); NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class); this.customizer.customize(factory); - verify(factory, times(1)).addServerCustomizers(this.customizerCaptor.capture()); + then(factory).should().addServerCustomizers(this.customizerCaptor.capture()); NettyServerCustomizer serverCustomizer = this.customizerCaptor.getValue(); HttpServer httpServer = serverCustomizer.apply(HttpServer.create()); HttpRequestDecoderSpec decoder = httpServer.configuration().decoder(); @@ -149,10 +149,10 @@ class NettyWebServerFactoryCustomizerTests { private void verifyConnectionTimeout(NettyReactiveWebServerFactory factory, Integer expected) { if (expected == null) { - verify(factory, never()).addServerCustomizers(any(NettyServerCustomizer.class)); + then(factory).should(never()).addServerCustomizers(any(NettyServerCustomizer.class)); return; } - verify(factory, times(2)).addServerCustomizers(this.customizerCaptor.capture()); + then(factory).should(times(2)).addServerCustomizers(this.customizerCaptor.capture()); NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0); HttpServer httpServer = serverCustomizer.apply(HttpServer.create()); Map, ?> options = httpServer.configuration().options(); @@ -161,10 +161,10 @@ class NettyWebServerFactoryCustomizerTests { private void verifyIdleTimeout(NettyReactiveWebServerFactory factory, Duration expected) { if (expected == null) { - verify(factory, never()).addServerCustomizers(any(NettyServerCustomizer.class)); + then(factory).should(never()).addServerCustomizers(any(NettyServerCustomizer.class)); return; } - verify(factory, times(2)).addServerCustomizers(this.customizerCaptor.capture()); + then(factory).should(times(2)).addServerCustomizers(this.customizerCaptor.capture()); NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0); HttpServer httpServer = serverCustomizer.apply(HttpServer.create()); Duration idleTimeout = httpServer.configuration().idleTimeout(); @@ -172,7 +172,7 @@ class NettyWebServerFactoryCustomizerTests { } private void verifyMaxKeepAliveRequests(NettyReactiveWebServerFactory factory, int expected) { - verify(factory, times(2)).addServerCustomizers(this.customizerCaptor.capture()); + then(factory).should(times(2)).addServerCustomizers(this.customizerCaptor.capture()); NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0); HttpServer httpServer = serverCustomizer.apply(HttpServer.create()); int maxKeepAliveRequests = httpServer.configuration().maxKeepAliveRequests(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizerTests.java index 956868162b..7b544fb3e6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,9 +41,9 @@ import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willAnswer; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link UndertowWebServerFactoryCustomizer}. @@ -77,12 +77,12 @@ class UndertowWebServerFactoryCustomizerTests { "server.undertow.accesslog.dir=test-logs", "server.undertow.accesslog.rotate=false"); ConfigurableUndertowWebServerFactory factory = mock(ConfigurableUndertowWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setAccessLogEnabled(true); - verify(factory).setAccessLogPattern("foo"); - verify(factory).setAccessLogPrefix("test_log"); - verify(factory).setAccessLogSuffix("txt"); - verify(factory).setAccessLogDirectory(new File("test-logs")); - verify(factory).setAccessLogRotate(false); + then(factory).should().setAccessLogEnabled(true); + then(factory).should().setAccessLogPattern("foo"); + then(factory).should().setAccessLogPrefix("test_log"); + then(factory).should().setAccessLogSuffix("txt"); + then(factory).should().setAccessLogDirectory(new File("test-logs")); + then(factory).should().setAccessLogRotate(false); } @Test @@ -138,7 +138,7 @@ class UndertowWebServerFactoryCustomizerTests { bind("server.undertow.threads.io=4"); ConfigurableUndertowWebServerFactory factory = mock(ConfigurableUndertowWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setIoThreads(4); + then(factory).should().setIoThreads(4); } @Test @@ -146,7 +146,7 @@ class UndertowWebServerFactoryCustomizerTests { bind("server.undertow.threads.worker=10"); ConfigurableUndertowWebServerFactory factory = mock(ConfigurableUndertowWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setWorkerThreads(10); + then(factory).should().setWorkerThreads(10); } @Test @@ -202,14 +202,14 @@ class UndertowWebServerFactoryCustomizerTests { this.environment.setProperty("DYNO", "-"); ConfigurableUndertowWebServerFactory factory = mock(ConfigurableUndertowWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(true); + then(factory).should().setUseForwardHeaders(true); } @Test void defaultUseForwardHeaders() { ConfigurableUndertowWebServerFactory factory = mock(ConfigurableUndertowWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(false); + then(factory).should().setUseForwardHeaders(false); } @Test @@ -217,7 +217,7 @@ class UndertowWebServerFactoryCustomizerTests { this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE); ConfigurableUndertowWebServerFactory factory = mock(ConfigurableUndertowWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(true); + then(factory).should().setUseForwardHeaders(true); } @Test @@ -226,7 +226,7 @@ class UndertowWebServerFactoryCustomizerTests { this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NONE); ConfigurableUndertowWebServerFactory factory = mock(ConfigurableUndertowWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setUseForwardHeaders(false); + then(factory).should().setUseForwardHeaders(false); } private T boundServerOption(Option option) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryAutoConfigurationTests.java index e41159b4d5..4b549494d6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,9 +53,8 @@ import org.springframework.web.server.adapter.ForwardedHeaderTransformer; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link ReactiveWebServerFactoryAutoConfiguration}. @@ -128,7 +127,7 @@ class ReactiveWebServerFactoryAutoConfigurationTests { TomcatConnectorCustomizer customizer = context.getBean("connectorCustomizer", TomcatConnectorCustomizer.class); assertThat(factory.getTomcatConnectorCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Connector.class)); + then(customizer).should().customize(any(Connector.class)); }); } @@ -145,7 +144,7 @@ class ReactiveWebServerFactoryAutoConfigurationTests { TomcatConnectorCustomizer customizer = context.getBean("connectorCustomizer", TomcatConnectorCustomizer.class); assertThat(factory.getTomcatConnectorCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Connector.class)); + then(customizer).should().customize(any(Connector.class)); }); } @@ -161,7 +160,7 @@ class ReactiveWebServerFactoryAutoConfigurationTests { TomcatReactiveWebServerFactory factory = context.getBean(TomcatReactiveWebServerFactory.class); TomcatContextCustomizer customizer = context.getBean("contextCustomizer", TomcatContextCustomizer.class); assertThat(factory.getTomcatContextCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Context.class)); + then(customizer).should().customize(any(Context.class)); }); } @@ -177,7 +176,7 @@ class ReactiveWebServerFactoryAutoConfigurationTests { TomcatReactiveWebServerFactory factory = context.getBean(TomcatReactiveWebServerFactory.class); TomcatContextCustomizer customizer = context.getBean("contextCustomizer", TomcatContextCustomizer.class); assertThat(factory.getTomcatContextCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Context.class)); + then(customizer).should().customize(any(Context.class)); }); } @@ -194,7 +193,7 @@ class ReactiveWebServerFactoryAutoConfigurationTests { TomcatProtocolHandlerCustomizer customizer = context.getBean("protocolHandlerCustomizer", TomcatProtocolHandlerCustomizer.class); assertThat(factory.getTomcatProtocolHandlerCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any()); + then(customizer).should().customize(any()); }); } @@ -211,7 +210,7 @@ class ReactiveWebServerFactoryAutoConfigurationTests { TomcatProtocolHandlerCustomizer customizer = context.getBean("protocolHandlerCustomizer", TomcatProtocolHandlerCustomizer.class); assertThat(factory.getTomcatProtocolHandlerCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any()); + then(customizer).should().customize(any()); }); } @@ -238,7 +237,7 @@ class ReactiveWebServerFactoryAutoConfigurationTests { JettyReactiveWebServerFactory factory = context.getBean(JettyReactiveWebServerFactory.class); JettyServerCustomizer customizer = context.getBean("serverCustomizer", JettyServerCustomizer.class); assertThat(factory.getServerCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Server.class)); + then(customizer).should().customize(any(Server.class)); }); } @@ -266,7 +265,7 @@ class ReactiveWebServerFactoryAutoConfigurationTests { UndertowBuilderCustomizer customizer = context.getBean("builderCustomizer", UndertowBuilderCustomizer.class); assertThat(factory.getBuilderCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Builder.class)); + then(customizer).should().customize(any(Builder.class)); }); } @@ -293,7 +292,7 @@ class ReactiveWebServerFactoryAutoConfigurationTests { NettyReactiveWebServerFactory factory = context.getBean(NettyReactiveWebServerFactory.class); NettyServerCustomizer customizer = context.getBean("serverCustomizer", NettyServerCustomizer.class); assertThat(factory.getServerCustomizers()).contains(customizer); - verify(customizer, times(1)).apply(any(HttpServer.class)); + then(customizer).should().apply(any(HttpServer.class)); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryCustomizerTests.java index dba8b407f1..63a7344911 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryCustomizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import org.springframework.boot.web.server.Shutdown; import org.springframework.boot.web.server.Ssl; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link ReactiveWebServerFactoryCustomizer}. @@ -53,7 +53,7 @@ class ReactiveWebServerFactoryCustomizerTests { ConfigurableReactiveWebServerFactory factory = mock(ConfigurableReactiveWebServerFactory.class); this.properties.setPort(9000); this.customizer.customize(factory); - verify(factory).setPort(9000); + then(factory).should().setPort(9000); } @Test @@ -62,7 +62,7 @@ class ReactiveWebServerFactoryCustomizerTests { InetAddress address = mock(InetAddress.class); this.properties.setAddress(address); this.customizer.customize(factory); - verify(factory).setAddress(address); + then(factory).should().setAddress(address); } @Test @@ -71,7 +71,7 @@ class ReactiveWebServerFactoryCustomizerTests { Ssl ssl = mock(Ssl.class); this.properties.setSsl(ssl); this.customizer.customize(factory); - verify(factory).setSsl(ssl); + then(factory).should().setSsl(ssl); } @Test @@ -80,7 +80,7 @@ class ReactiveWebServerFactoryCustomizerTests { ConfigurableReactiveWebServerFactory factory = mock(ConfigurableReactiveWebServerFactory.class); this.customizer.customize(factory); ArgumentCaptor shutdownCaptor = ArgumentCaptor.forClass(Shutdown.class); - verify(factory).setShutdown(shutdownCaptor.capture()); + then(factory).should().setShutdown(shutdownCaptor.capture()); assertThat(shutdownCaptor.getValue()).isEqualTo(Shutdown.GRACEFUL); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java index 31c071ae25..95a37e8c32 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -98,8 +98,8 @@ import org.springframework.web.util.pattern.PathPattern; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link WebFluxAutoConfiguration}. @@ -155,7 +155,7 @@ class WebFluxAutoConfigurationTests { this.contextRunner.withUserConfiguration(CustomCodecCustomizers.class).run((context) -> { CodecCustomizer codecCustomizer = context.getBean("firstCodecCustomizer", CodecCustomizer.class); assertThat(codecCustomizer).isNotNull(); - verify(codecCustomizer).customize(any(ServerCodecConfigurer.class)); + then(codecCustomizer).should().customize(any(ServerCodecConfigurer.class)); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorAutoConfigurationTests.java index 4826257c9b..e329138a31 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,9 +34,8 @@ import org.springframework.web.reactive.function.client.WebClient; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link ClientHttpConnectorAutoConfiguration} @@ -94,7 +93,7 @@ class ClientHttpConnectorAutoConfigurationTests { WebClientCustomizer clientCustomizer = context.getBean(WebClientCustomizer.class); WebClient.Builder builder = mock(WebClient.Builder.class); clientCustomizer.customize(builder); - verify(builder, times(1)).clientConnector(any(ReactorClientHttpConnector.class)); + then(builder).should().clientConnector(any(ReactorClientHttpConnector.class)); }); } @@ -106,7 +105,7 @@ class ClientHttpConnectorAutoConfigurationTests { WebClientCustomizer clientCustomizer = context.getBean(WebClientCustomizer.class); WebClient.Builder builder = mock(WebClient.Builder.class); clientCustomizer.customize(builder); - verify(builder, times(1)).clientConnector(any(ClientHttpConnector.class)); + then(builder).should().clientConnector(any(ClientHttpConnector.class)); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java index 98e6081a65..9059dd3b06 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,9 +40,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link WebClientAutoConfiguration} @@ -71,7 +71,7 @@ class WebClientAutoConfigurationTests { WebClientCodecCustomizer clientCustomizer = context.getBean(WebClientCodecCustomizer.class); builder.build(); assertThat(clientCustomizer).isNotNull(); - verify(codecCustomizer).customize(any(CodecConfigurer.class)); + then(codecCustomizer).should().customize(any(CodecConfigurer.class)); }); } @@ -81,7 +81,7 @@ class WebClientAutoConfigurationTests { WebClient.Builder builder = context.getBean(WebClient.Builder.class); WebClientCustomizer customizer = context.getBean("webClientCustomizer", WebClientCustomizer.class); builder.build(); - verify(customizer).customize(any(WebClient.Builder.class)); + then(customizer).should().customize(any(WebClient.Builder.class)); }); } @@ -102,11 +102,12 @@ class WebClientAutoConfigurationTests { assertThat(firstBuilder).isNotEqualTo(secondBuilder); firstBuilder.build().get().uri("/foo").retrieve().toBodilessEntity().block(Duration.ofSeconds(30)); secondBuilder.build().get().uri("/foo").retrieve().toBodilessEntity().block(Duration.ofSeconds(30)); - verify(firstConnector).connect(eq(HttpMethod.GET), eq(URI.create("https://first.example.org/foo")), any()); - verify(secondConnector).connect(eq(HttpMethod.GET), eq(URI.create("https://second.example.org/foo")), + then(firstConnector).should().connect(eq(HttpMethod.GET), eq(URI.create("https://first.example.org/foo")), + any()); + then(secondConnector).should().connect(eq(HttpMethod.GET), eq(URI.create("https://second.example.org/foo")), any()); WebClientCustomizer customizer = context.getBean("webClientCustomizer", WebClientCustomizer.class); - verify(customizer, times(2)).customize(any(WebClient.Builder.class)); + then(customizer).should(times(2)).customize(any(WebClient.Builder.class)); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryAutoConfigurationTests.java index d4c963ecaf..158b2c9153 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,9 +65,8 @@ import org.springframework.web.servlet.FrameworkServlet; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link ServletWebServerFactoryAutoConfiguration}. @@ -178,7 +177,7 @@ class ServletWebServerFactoryAutoConfigurationTests { JettyServletWebServerFactory factory = context.getBean(JettyServletWebServerFactory.class); JettyServerCustomizer customizer = context.getBean("serverCustomizer", JettyServerCustomizer.class); assertThat(factory.getServerCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Server.class)); + then(customizer).should().customize(any(Server.class)); }); } @@ -209,7 +208,7 @@ class ServletWebServerFactoryAutoConfigurationTests { UndertowDeploymentInfoCustomizer customizer = context.getBean("deploymentInfoCustomizer", UndertowDeploymentInfoCustomizer.class); assertThat(factory.getDeploymentInfoCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(DeploymentInfo.class)); + then(customizer).should().customize(any(DeploymentInfo.class)); }); } @@ -226,7 +225,7 @@ class ServletWebServerFactoryAutoConfigurationTests { UndertowBuilderCustomizer customizer = context.getBean("builderCustomizer", UndertowBuilderCustomizer.class); assertThat(factory.getBuilderCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Builder.class)); + then(customizer).should().customize(any(Builder.class)); }); } @@ -267,7 +266,7 @@ class ServletWebServerFactoryAutoConfigurationTests { TomcatConnectorCustomizer customizer = context.getBean("connectorCustomizer", TomcatConnectorCustomizer.class); assertThat(factory.getTomcatConnectorCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Connector.class)); + then(customizer).should().customize(any(Connector.class)); }); } @@ -283,7 +282,7 @@ class ServletWebServerFactoryAutoConfigurationTests { TomcatConnectorCustomizer customizer = context.getBean("connectorCustomizer", TomcatConnectorCustomizer.class); assertThat(factory.getTomcatConnectorCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Connector.class)); + then(customizer).should().customize(any(Connector.class)); }); } @@ -298,7 +297,7 @@ class ServletWebServerFactoryAutoConfigurationTests { TomcatServletWebServerFactory factory = context.getBean(TomcatServletWebServerFactory.class); TomcatContextCustomizer customizer = context.getBean("contextCustomizer", TomcatContextCustomizer.class); assertThat(factory.getTomcatContextCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Context.class)); + then(customizer).should().customize(any(Context.class)); }); } @@ -313,7 +312,7 @@ class ServletWebServerFactoryAutoConfigurationTests { TomcatServletWebServerFactory factory = context.getBean(TomcatServletWebServerFactory.class); TomcatContextCustomizer customizer = context.getBean("contextCustomizer", TomcatContextCustomizer.class); assertThat(factory.getTomcatContextCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any(Context.class)); + then(customizer).should().customize(any(Context.class)); }); } @@ -329,7 +328,7 @@ class ServletWebServerFactoryAutoConfigurationTests { TomcatProtocolHandlerCustomizer customizer = context.getBean("protocolHandlerCustomizer", TomcatProtocolHandlerCustomizer.class); assertThat(factory.getTomcatProtocolHandlerCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any()); + then(customizer).should().customize(any()); }); } @@ -345,7 +344,7 @@ class ServletWebServerFactoryAutoConfigurationTests { TomcatProtocolHandlerCustomizer customizer = context.getBean("protocolHandlerCustomizer", TomcatProtocolHandlerCustomizer.class); assertThat(factory.getTomcatProtocolHandlerCustomizers()).contains(customizer); - verify(customizer, times(1)).customize(any()); + then(customizer).should().customize(any()); }); } @@ -387,7 +386,7 @@ class ServletWebServerFactoryAutoConfigurationTests { MockServletWebServerFactory factory = context.getBean(MockServletWebServerFactory.class); Servlet servlet = context.getBean(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, Servlet.class); - verify(factory.getServletContext()).addServlet("dispatcherServlet", servlet); + then(factory.getServletContext()).should().addServlet("dispatcherServlet", servlet); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizerTests.java index 6ff4a99028..17230ade14 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,8 @@ import org.springframework.boot.web.servlet.server.Session.Cookie; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link ServletWebServerFactoryCustomizer}. @@ -62,7 +62,7 @@ class ServletWebServerFactoryCustomizerTests { void testDefaultDisplayName() { ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setDisplayName("application"); + then(factory).should().setDisplayName("application"); } @Test @@ -70,7 +70,7 @@ class ServletWebServerFactoryCustomizerTests { ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class); this.properties.getServlet().setApplicationDisplayName("TestName"); this.customizer.customize(factory); - verify(factory).setDisplayName("TestName"); + then(factory).should().setDisplayName("TestName"); } @Test @@ -78,7 +78,7 @@ class ServletWebServerFactoryCustomizerTests { ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class); this.properties.getServlet().setRegisterDefaultServlet(false); this.customizer.customize(factory); - verify(factory).setRegisterDefaultServlet(false); + then(factory).should().setRegisterDefaultServlet(false); } @Test @@ -87,14 +87,14 @@ class ServletWebServerFactoryCustomizerTests { Ssl ssl = mock(Ssl.class); this.properties.setSsl(ssl); this.customizer.customize(factory); - verify(factory).setSsl(ssl); + then(factory).should().setSsl(ssl); } @Test void testCustomizeJsp() { ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setJsp(any(Jsp.class)); + then(factory).should().setJsp(any(Jsp.class)); } @Test @@ -113,7 +113,7 @@ class ServletWebServerFactoryCustomizerTests { ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class); this.customizer.customize(factory); ArgumentCaptor sessionCaptor = ArgumentCaptor.forClass(Session.class); - verify(factory).setSession(sessionCaptor.capture()); + then(factory).should().setSession(sessionCaptor.capture()); assertThat(sessionCaptor.getValue().getTimeout()).hasSeconds(123); Cookie cookie = sessionCaptor.getValue().getCookie(); assertThat(cookie.getName()).isEqualTo("testname"); @@ -129,7 +129,7 @@ class ServletWebServerFactoryCustomizerTests { ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class); this.properties.setPort(8080); this.customizer.customize(factory); - verify(factory).setPort(8080); + then(factory).should().setPort(8080); } @Test @@ -139,7 +139,7 @@ class ServletWebServerFactoryCustomizerTests { bindProperties(map); ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class); this.customizer.customize(factory); - verify(factory).setDisplayName("MyBootApp"); + then(factory).should().setDisplayName("MyBootApp"); } @Test @@ -158,7 +158,7 @@ class ServletWebServerFactoryCustomizerTests { ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class); this.customizer.customize(factory); ArgumentCaptor sessionCaptor = ArgumentCaptor.forClass(Session.class); - verify(factory).setSession(sessionCaptor.capture()); + then(factory).should().setSession(sessionCaptor.capture()); assertThat(sessionCaptor.getValue().getStoreDir()).isEqualTo(new File("mydirectory")); } @@ -170,7 +170,7 @@ class ServletWebServerFactoryCustomizerTests { ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class); this.customizer.customize(factory); ArgumentCaptor shutdownCaptor = ArgumentCaptor.forClass(Shutdown.class); - verify(factory).setShutdown(shutdownCaptor.capture()); + then(factory).should().setShutdown(shutdownCaptor.capture()); assertThat(shutdownCaptor.getValue()).isEqualTo(Shutdown.GRACEFUL); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerServletContextListenerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerServletContextListenerTests.java index b40d7557c7..f462da8cc8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerServletContextListenerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerServletContextListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link WebServer}s driving {@link ServletContextListener}s correctly @@ -77,7 +77,7 @@ class ServletWebServerServletContextListenerTests { ServletContextListenerBeanConfiguration.class, configuration); ServletContextListener servletContextListener = context.getBean("servletContextListener", ServletContextListener.class); - verify(servletContextListener).contextInitialized(any(ServletContextEvent.class)); + then(servletContextListener).should().contextInitialized(any(ServletContextEvent.class)); context.close(); } @@ -86,7 +86,7 @@ class ServletWebServerServletContextListenerTests { ServletListenerRegistrationBeanConfiguration.class, configuration); ServletContextListener servletContextListener = (ServletContextListener) context .getBean("registration", ServletListenerRegistrationBean.class).getListener(); - verify(servletContextListener).contextInitialized(any(ServletContextEvent.class)); + then(servletContextListener).should().contextInitialized(any(ServletContextEvent.class)); context.close(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/DefaultErrorViewResolverTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/DefaultErrorViewResolverTests.java index 98781dc002..a22d7707dd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/DefaultErrorViewResolverTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/DefaultErrorViewResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,9 +47,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link DefaultErrorViewResolver}. @@ -108,9 +107,9 @@ class DefaultErrorViewResolverTests { ModelAndView resolved = this.resolver.resolveErrorView(this.request, HttpStatus.NOT_FOUND, this.model); assertThat(resolved).isNotNull(); assertThat(resolved.getViewName()).isEqualTo("error/404"); - verify(this.templateAvailabilityProvider).isTemplateAvailable(eq("error/404"), any(Environment.class), + then(this.templateAvailabilityProvider).should().isTemplateAvailable(eq("error/404"), any(Environment.class), any(ClassLoader.class), any(ResourceLoader.class)); - verifyNoMoreInteractions(this.templateAvailabilityProvider); + then(this.templateAvailabilityProvider).shouldHaveNoMoreInteractions(); } @Test @@ -177,7 +176,7 @@ class DefaultErrorViewResolverTests { given(this.templateAvailabilityProvider.isTemplateAvailable(eq("error/404"), any(Environment.class), any(ClassLoader.class), any(ResourceLoader.class))).willReturn(false); ModelAndView resolved = this.resolver.resolveErrorView(this.request, HttpStatus.NOT_FOUND, this.model); - verifyNoMoreInteractions(this.templateAvailabilityProvider); + then(this.templateAvailabilityProvider).shouldHaveNoMoreInteractions(); MockHttpServletResponse response = render(resolved); assertThat(response.getContentAsString().trim()).isEqualTo("exact/404"); assertThat(response.getContentType()).isEqualTo(MediaType.TEXT_HTML_VALUE); diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerTests.java index 88ba197774..462cd0c2cf 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,9 +31,9 @@ import org.springframework.boot.cli.command.core.HintCommand; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.lenient; -import static org.mockito.Mockito.verify; /** * Tests for {@link CommandRunner}. @@ -101,7 +101,7 @@ class CommandRunnerTests { @Test void runCommand() throws Exception { this.commandRunner.run("command", "--arg1", "arg2"); - verify(this.regularCommand).run("--arg1", "arg2"); + then(this.regularCommand).should().run("--arg1", "arg2"); } @Test @@ -112,7 +112,7 @@ class CommandRunnerTests { @Test void appArguments() throws Exception { this.commandRunner.runAndHandleErrors("command", "--", "--debug", "bar"); - verify(this.regularCommand).run("--", "--debug", "bar"); + then(this.regularCommand).should().run("--", "--debug", "bar"); // When handled by the command itself it shouldn't cause the system property to be // set assertThat(System.getProperty("debug")).isNull(); @@ -166,7 +166,7 @@ class CommandRunnerTests { @Test void help() throws Exception { this.commandRunner.run("help", "command"); - verify(this.regularCommand).getHelp(); + then(this.regularCommand).should().getHelp(); } @Test diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/encodepassword/EncodePasswordCommandTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/encodepassword/EncodePasswordCommandTests.java index dbe11c77c7..2980ae3b08 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/encodepassword/EncodePasswordCommandTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/encodepassword/EncodePasswordCommandTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import org.springframework.security.crypto.factory.PasswordEncoderFactories; import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link EncodePasswordCommand}. @@ -60,7 +60,7 @@ class EncodePasswordCommandTests { void encodeWithNoAlgorithmShouldUseBcrypt() throws Exception { EncodePasswordCommand command = new EncodePasswordCommand(); ExitStatus status = command.run("boot"); - verify(this.log).info(this.message.capture()); + then(this.log).should().info(this.message.capture()); assertThat(this.message.getValue()).startsWith("{bcrypt}"); assertThat(PasswordEncoderFactories.createDelegatingPasswordEncoder().matches("boot", this.message.getValue())) .isTrue(); @@ -71,7 +71,7 @@ class EncodePasswordCommandTests { void encodeWithBCryptShouldUseBCrypt() throws Exception { EncodePasswordCommand command = new EncodePasswordCommand(); ExitStatus status = command.run("-a", "bcrypt", "boot"); - verify(this.log).info(this.message.capture()); + then(this.log).should().info(this.message.capture()); assertThat(this.message.getValue()).doesNotStartWith("{"); assertThat(new BCryptPasswordEncoder().matches("boot", this.message.getValue())).isTrue(); assertThat(status).isEqualTo(ExitStatus.OK); @@ -81,7 +81,7 @@ class EncodePasswordCommandTests { void encodeWithPbkdf2ShouldUsePbkdf2() throws Exception { EncodePasswordCommand command = new EncodePasswordCommand(); ExitStatus status = command.run("-a", "pbkdf2", "boot"); - verify(this.log).info(this.message.capture()); + then(this.log).should().info(this.message.capture()); assertThat(this.message.getValue()).doesNotStartWith("{"); assertThat(new Pbkdf2PasswordEncoder().matches("boot", this.message.getValue())).isTrue(); assertThat(status).isEqualTo(ExitStatus.OK); @@ -91,7 +91,7 @@ class EncodePasswordCommandTests { void encodeWithUnknownAlgorithmShouldExitWithError() throws Exception { EncodePasswordCommand command = new EncodePasswordCommand(); ExitStatus status = command.run("--algorithm", "bad", "boot"); - verify(this.log).error("Unknown algorithm, valid options are: default,bcrypt,pbkdf2"); + then(this.log).should().error("Unknown algorithm, valid options are: default,bcrypt,pbkdf2"); assertThat(status).isEqualTo(ExitStatus.ERROR); } diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java index 571ed67201..37c3280afd 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.boot.cli.command.status.ExitStatus; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link InitCommand} @@ -393,7 +393,7 @@ class InitCommandTests extends AbstractHttpClientMockTests { @Test void userAgent() throws Exception { this.command.run("--list", "--target=https://fake-service"); - verify(this.http).execute(this.requestCaptor.capture()); + then(this.http).should().execute(this.requestCaptor.capture()); Header agent = this.requestCaptor.getValue().getHeaders("User-Agent")[0]; assertThat(agent.getValue()).startsWith("SpringBootCli/"); } diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagementArtifactCoordinatesResolverTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagementArtifactCoordinatesResolverTests.java index b47e18ff27..abe2756b4d 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagementArtifactCoordinatesResolverTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/DependencyManagementArtifactCoordinatesResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,9 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link DependencyManagementArtifactCoordinatesResolver}. @@ -49,7 +49,7 @@ class DependencyManagementArtifactCoordinatesResolverTests { @Test void getGroupIdForBootArtifact() { assertThat(this.resolver.getGroupId("spring-boot-something")).isEqualTo("org.springframework.boot"); - verify(this.dependencyManagement, never()).find(anyString()); + then(this.dependencyManagement).should(never()).find(anyString()); } @Test diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/GrapeRootRepositorySystemSessionAutoConfigurationTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/GrapeRootRepositorySystemSessionAutoConfigurationTests.java index 9c2125181b..001c79e642 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/GrapeRootRepositorySystemSessionAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/GrapeRootRepositorySystemSessionAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link GrapeRootRepositorySystemSessionAutoConfiguration} @@ -55,7 +54,8 @@ class GrapeRootRepositorySystemSessionAutoConfigurationTests { @Test void noLocalRepositoryWhenNoGrapeRoot() { new GrapeRootRepositorySystemSessionAutoConfiguration().apply(this.session, this.repositorySystem); - verify(this.repositorySystem, never()).newLocalRepositoryManager(eq(this.session), any(LocalRepository.class)); + then(this.repositorySystem).should(never()).newLocalRepositoryManager(eq(this.session), + any(LocalRepository.class)); assertThat(this.session.getLocalRepository()).isNull(); } @@ -72,7 +72,7 @@ class GrapeRootRepositorySystemSessionAutoConfigurationTests { System.clearProperty("grape.root"); } - verify(this.repositorySystem, times(1)).newLocalRepositoryManager(eq(this.session), any(LocalRepository.class)); + then(this.repositorySystem).should().newLocalRepositoryManager(eq(this.session), any(LocalRepository.class)); assertThat(this.session.getLocalRepository()).isNotNull(); assertThat(this.session.getLocalRepository().getBasedir().getAbsolutePath()) diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/AbstractDevToolsDataSourceAutoConfigurationTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/AbstractDevToolsDataSourceAutoConfigurationTests.java index d2f94d484d..432298e17e 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/AbstractDevToolsDataSourceAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/AbstractDevToolsDataSourceAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,11 +36,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.doReturn; +import static org.mockito.BDDMockito.then; +import static org.mockito.BDDMockito.willReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Base class for tests for {@link DevToolsDataSourceAutoConfiguration}. @@ -54,7 +54,7 @@ abstract class AbstractDevToolsDataSourceAutoConfigurationTests { ConfigurableApplicationContext context = getContext(() -> createContext(SingleDataSourceConfiguration.class)); DataSource dataSource = context.getBean(DataSource.class); Statement statement = configureDataSourceBehavior(dataSource); - verify(statement, never()).execute("SHUTDOWN"); + then(statement).should(never()).execute("SHUTDOWN"); } @Test @@ -64,7 +64,7 @@ abstract class AbstractDevToolsDataSourceAutoConfigurationTests { Collection dataSources = context.getBeansOfType(DataSource.class).values(); for (DataSource dataSource : dataSources) { Statement statement = configureDataSourceBehavior(dataSource); - verify(statement, never()).execute("SHUTDOWN"); + then(statement).should(never()).execute("SHUTDOWN"); } } @@ -82,7 +82,7 @@ abstract class AbstractDevToolsDataSourceAutoConfigurationTests { protected final Statement configureDataSourceBehavior(DataSource dataSource) throws SQLException { Connection connection = mock(Connection.class); Statement statement = mock(Statement.class); - doReturn(connection).when(dataSource).getConnection(); + willReturn(connection).given(dataSource).getConnection(); given(connection.createStatement()).willReturn(statement); return statement; } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java index 60dab61010..dbd1d2030f 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,8 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; import org.springframework.context.ConfigurableApplicationContext; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link DevToolsDataSourceAutoConfiguration} with an embedded data source. @@ -44,7 +44,7 @@ class DevToolsEmbeddedDataSourceAutoConfigurationTests extends AbstractDevToolsD DataSourceSpyConfiguration.class); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); context.close(); - verify(statement, never()).execute("SHUTDOWN"); + then(statement).should(never()).execute("SHUTDOWN"); } } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsPooledDataSourceAutoConfigurationTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsPooledDataSourceAutoConfigurationTests.java index 74f0b29e2e..0db015da50 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsPooledDataSourceAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsPooledDataSourceAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,9 +39,8 @@ import org.springframework.jdbc.core.JdbcTemplate; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link DevToolsDataSourceAutoConfiguration} with a pooled data source. @@ -66,7 +65,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat () -> createContext(DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); context.close(); - verify(statement).execute("SHUTDOWN"); + then(statement).should().execute("SHUTDOWN"); } @Test @@ -75,7 +74,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); context.close(); - verify(statement, never()).execute("SHUTDOWN"); + then(statement).should(never()).execute("SHUTDOWN"); } @Test @@ -84,7 +83,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat "jdbc:h2:hsql://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); context.close(); - verify(statement, never()).execute("SHUTDOWN"); + then(statement).should(never()).execute("SHUTDOWN"); } @Test @@ -93,7 +92,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); context.close(); - verify(statement, times(1)).execute("SHUTDOWN"); + then(statement).should().execute("SHUTDOWN"); } @Test @@ -102,7 +101,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat "jdbc:hsqldb:hsql://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); context.close(); - verify(statement, never()).execute("SHUTDOWN"); + then(statement).should(never()).execute("SHUTDOWN"); } @Test @@ -111,7 +110,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat "jdbc:hsqldb:mem:test", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); context.close(); - verify(statement, times(1)).execute("SHUTDOWN"); + then(statement).should().execute("SHUTDOWN"); } @Test @@ -120,7 +119,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat "jdbc:derby://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); context.close(); - verify(statement, never()).execute("SHUTDOWN"); + then(statement).should(never()).execute("SHUTDOWN"); } @Test diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java index 481f496b9a..9155b232d8 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,10 +59,10 @@ import org.springframework.web.servlet.view.AbstractTemplateViewResolver; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.verify; /** * Tests for {@link LocalDevToolsAutoConfiguration}. @@ -124,7 +124,7 @@ class LocalDevToolsAutoConfigurationTests { LiveReloadServer server = this.context.getBean(LiveReloadServer.class); reset(server); this.context.publishEvent(new ContextRefreshedEvent(this.context)); - verify(server).triggerReload(); + then(server).should().triggerReload(); } @Test @@ -134,7 +134,7 @@ class LocalDevToolsAutoConfigurationTests { reset(server); ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.emptySet(), false); this.context.publishEvent(event); - verify(server).triggerReload(); + then(server).should().triggerReload(); } @Test @@ -144,7 +144,7 @@ class LocalDevToolsAutoConfigurationTests { reset(server); ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.emptySet(), true); this.context.publishEvent(event); - verify(server, never()).triggerReload(); + then(server).should(never()).triggerReload(); } @Test @@ -161,7 +161,7 @@ class LocalDevToolsAutoConfigurationTests { this.context = getContext(() -> initializeAndRun(Config.class)); ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.emptySet(), true); this.context.publishEvent(event); - verify(restarter).restart(any(FailureHandler.class)); + then(restarter).should().restart(any(FailureHandler.class)); } @Test @@ -169,7 +169,7 @@ class LocalDevToolsAutoConfigurationTests { this.context = getContext(() -> initializeAndRun(Config.class)); ClassPathChangedEvent event = new ClassPathChangedEvent(this.context, Collections.emptySet(), false); this.context.publishEvent(event); - verify(restarter, never()).restart(); + then(restarter).should(never()).restart(); } @Test diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/OptionalLiveReloadServerTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/OptionalLiveReloadServerTests.java index ffc91b262e..dfae3b454e 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/OptionalLiveReloadServerTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/OptionalLiveReloadServerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,10 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.devtools.livereload.LiveReloadServer; +import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link OptionalLiveReloadServer}. @@ -46,7 +46,7 @@ class OptionalLiveReloadServerTests { willThrow(new RuntimeException("Error")).given(delegate).start(); server.startServer(); server.triggerReload(); - verify(delegate, never()).triggerReload(); + then(delegate).should(never()).triggerReload(); } } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileChangeListenerTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileChangeListenerTests.java index bb465eb5c1..10d24c88ea 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileChangeListenerTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileChangeListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,8 @@ import org.springframework.context.ApplicationEventPublisher; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link ClassPathFileChangeListener}. @@ -77,13 +77,13 @@ class ClassPathFileChangeListenerTests { @Test void sendsEventWithoutRestart() { testSendsEvent(false); - verify(this.fileSystemWatcher, never()).stop(); + then(this.fileSystemWatcher).should(never()).stop(); } @Test void sendsEventWithRestart() { testSendsEvent(true); - verify(this.fileSystemWatcher).stop(); + then(this.fileSystemWatcher).should().stop(); } private void testSendsEvent(boolean restart) { @@ -102,7 +102,7 @@ class ClassPathFileChangeListenerTests { given(this.restartStrategy.isRestartRequired(file2)).willReturn(true); } listener.onChange(changeSet); - verify(this.eventPublisher).publishEvent(this.eventCaptor.capture()); + then(this.eventPublisher).should().publishEvent(this.eventCaptor.capture()); ClassPathChangedEvent actualEvent = (ClassPathChangedEvent) this.eventCaptor.getValue(); assertThat(actualEvent.getChangeSet()).isEqualTo(changeSet); assertThat(actualEvent.isRestartRequired()).isEqualTo(restart); diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/ConnectionOutputStreamTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/ConnectionOutputStreamTests.java index e4a663daf2..ec80f8c64d 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/ConnectionOutputStreamTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/ConnectionOutputStreamTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ import java.io.OutputStream; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link ConnectionOutputStream}. @@ -40,7 +40,7 @@ class ConnectionOutputStreamTests { ConnectionOutputStream outputStream = new ConnectionOutputStream(out); byte[] b = new byte[100]; outputStream.write(b, 1, 2); - verify(out).write(b, 1, 2); + then(out).should().write(b, 1, 2); } @Test diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/DelayedLiveReloadTriggerTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/DelayedLiveReloadTriggerTests.java index 45e986ba59..5845181f60 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/DelayedLiveReloadTriggerTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/DelayedLiveReloadTriggerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,8 @@ import org.springframework.http.client.ClientHttpResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link DelayedLiveReloadTrigger}. @@ -113,7 +113,7 @@ class DelayedLiveReloadTriggerTests { this.trigger.setTimings(10, 200, 30000); this.trigger.run(); assertThat(System.currentTimeMillis() - startTime).isGreaterThan(300L); - verify(this.liveReloadServer).triggerReload(); + then(this.liveReloadServer).should().triggerReload(); } @Test @@ -121,7 +121,7 @@ class DelayedLiveReloadTriggerTests { given(this.requestFactory.createRequest(new URI(URL), HttpMethod.GET)).willThrow(new IOException()); this.trigger.setTimings(10, 0, 10); this.trigger.run(); - verify(this.liveReloadServer, never()).triggerReload(); + then(this.liveReloadServer).should(never()).triggerReload(); } } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java index 64dbdb80ed..824f5e911e 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,8 +52,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link RemoteClientConfiguration}. @@ -108,7 +108,7 @@ class RemoteClientConfigurationTests { ClassPathChangedEvent event = new ClassPathChangedEvent(this, changeSet, false); this.clientContext.publishEvent(event); LiveReloadServer server = this.clientContext.getBean(LiveReloadServer.class); - Awaitility.await().atMost(Duration.ofMinutes(1)).untilAsserted(() -> verify(server).triggerReload()); + Awaitility.await().atMost(Duration.ofMinutes(1)).untilAsserted(() -> then(server).should().triggerReload()); } @Test diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/server/DispatcherFilterTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/server/DispatcherFilterTests.java index 03826f5b4a..5f24095117 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/server/DispatcherFilterTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/server/DispatcherFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,10 +40,9 @@ import org.springframework.mock.web.MockHttpServletResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willReturn; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link DispatcherFilter}. @@ -83,8 +82,8 @@ class DispatcherFilterTests { ServletRequest request = mock(ServletRequest.class); ServletResponse response = mock(ServletResponse.class); this.filter.doFilter(request, response, this.chain); - verifyNoInteractions(this.dispatcher); - verify(this.chain).doFilter(request, response); + then(this.dispatcher).shouldHaveNoInteractions(); + then(this.chain).should().doFilter(request, response); } @Test @@ -92,7 +91,7 @@ class DispatcherFilterTests { HttpServletRequest request = new MockHttpServletRequest("GET", "/hello"); HttpServletResponse response = new MockHttpServletResponse(); this.filter.doFilter(request, response, this.chain); - verify(this.chain).doFilter(request, response); + then(this.chain).should().doFilter(request, response); } @Test @@ -101,8 +100,8 @@ class DispatcherFilterTests { HttpServletResponse response = new MockHttpServletResponse(); willReturn(true).given(this.dispatcher).handle(any(ServerHttpRequest.class), any(ServerHttpResponse.class)); this.filter.doFilter(request, response, this.chain); - verifyNoInteractions(this.chain); - verify(this.dispatcher).handle(this.serverRequestCaptor.capture(), this.serverResponseCaptor.capture()); + then(this.chain).shouldHaveNoInteractions(); + then(this.dispatcher).should().handle(this.serverRequestCaptor.capture(), this.serverResponseCaptor.capture()); ServerHttpRequest dispatcherRequest = this.serverRequestCaptor.getValue(); ServletServerHttpRequest actualRequest = (ServletServerHttpRequest) dispatcherRequest; ServerHttpResponse dispatcherResponse = this.serverResponseCaptor.getValue(); diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/server/DispatcherTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/server/DispatcherTests.java index 57289906f8..43b883149b 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/server/DispatcherTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/server/DispatcherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,10 +38,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.withSettings; /** @@ -81,7 +80,7 @@ class DispatcherTests { given(mapper.getHandler(any(ServerHttpRequest.class))).willReturn(handler); Dispatcher dispatcher = new Dispatcher(this.accessManager, Collections.singleton(mapper)); dispatcher.handle(this.serverRequest, this.serverResponse); - verifyNoInteractions(handler); + then(handler).shouldHaveNoInteractions(); assertThat(this.response.getStatus()).isEqualTo(403); } @@ -93,7 +92,7 @@ class DispatcherTests { given(mapper.getHandler(any(ServerHttpRequest.class))).willReturn(handler); Dispatcher dispatcher = new Dispatcher(this.accessManager, Collections.singleton(mapper)); dispatcher.handle(this.serverRequest, this.serverResponse); - verify(handler).handle(this.serverRequest, this.serverResponse); + then(handler).should().handle(this.serverRequest, this.serverResponse); } @Test @@ -106,8 +105,8 @@ class DispatcherTests { Dispatcher dispatcher = new Dispatcher(AccessManager.PERMIT_ALL, mappers); dispatcher.handle(this.serverRequest, this.serverResponse); InOrder inOrder = inOrder(mapper1, mapper2); - inOrder.verify(mapper1).getHandler(this.serverRequest); - inOrder.verify(mapper2).getHandler(this.serverRequest); + then(mapper1).should(inOrder).getHandler(this.serverRequest); + then(mapper2).should(inOrder).getHandler(this.serverRequest); } } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolverTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolverTests.java index b0171fa44a..6dff93e440 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolverTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,8 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link ClassLoaderFilesResourcePatternResolver}. @@ -112,7 +112,7 @@ class ClassLoaderFilesResourcePatternResolverTests { context.setResourceLoader(resourceLoader); this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files); this.resolver.getResource("foo.txt"); - verify(resourceLoader).getResource("foo.txt"); + then(resourceLoader).should().getResource("foo.txt"); } @Test @@ -124,7 +124,7 @@ class ClassLoaderFilesResourcePatternResolverTests { this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files); Resource actual = this.resolver.getResource("foo:some-file.txt"); assertThat(actual).isSameAs(resource); - verify(resolver).resolve(eq("foo:some-file.txt"), any(ResourceLoader.class)); + then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class)); } @Test @@ -136,7 +136,7 @@ class ClassLoaderFilesResourcePatternResolverTests { context.addProtocolResolver(resolver); Resource actual = this.resolver.getResource("foo:some-file.txt"); assertThat(actual).isSameAs(resource); - verify(resolver).resolve(eq("foo:some-file.txt"), any(ResourceLoader.class)); + then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class)); } @Test @@ -146,7 +146,7 @@ class ClassLoaderFilesResourcePatternResolverTests { context.setResourceLoader(resourceLoader); this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files); this.resolver.getResource("foo.txt"); - verify(resourceLoader).getResource("foo.txt"); + then(resourceLoader).should().getResource("foo.txt"); } @Test @@ -158,7 +158,7 @@ class ClassLoaderFilesResourcePatternResolverTests { this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files); Resource actual = this.resolver.getResource("foo:some-file.txt"); assertThat(actual).isSameAs(resource); - verify(resolver).resolve(eq("foo:some-file.txt"), any(ResourceLoader.class)); + then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class)); } @Test @@ -170,7 +170,7 @@ class ClassLoaderFilesResourcePatternResolverTests { context.addProtocolResolver(resolver); Resource actual = this.resolver.getResource("foo:some-file.txt"); assertThat(actual).isSameAs(resource); - verify(resolver).resolve(eq("foo:some-file.txt"), any(ResourceLoader.class)); + then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class)); } private ProtocolResolver mockProtocolResolver(String path, Resource resource) { diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java index 1f45b017f3..456b9539c2 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,8 +49,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link Restarter}. @@ -140,7 +140,7 @@ class RestarterTests { ObjectFactory objectFactory = mock(ObjectFactory.class); Object attribute = Restarter.getInstance().getOrAddAttribute("x", objectFactory); assertThat(attribute).isEqualTo("abc"); - verifyNoInteractions(objectFactory); + then(objectFactory).shouldHaveNoInteractions(); } @Test diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/server/HttpRestartServerHandlerTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/server/HttpRestartServerHandlerTests.java index 6bb4fbd0a7..25c6c7cb4c 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/server/HttpRestartServerHandlerTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/server/HttpRestartServerHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link HttpRestartServerHandler}. @@ -45,7 +45,7 @@ class HttpRestartServerHandlerTests { ServerHttpRequest request = mock(ServerHttpRequest.class); ServerHttpResponse response = mock(ServerHttpResponse.class); handler.handle(request, response); - verify(server).handle(request, response); + then(server).should().handle(request, response); } } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/server/HttpRestartServerTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/server/HttpRestartServerTests.java index b85fe3627f..7c70e4c11f 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/server/HttpRestartServerTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/server/HttpRestartServerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,7 @@ import org.springframework.mock.web.MockHttpServletResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.BDDMockito.then; /** * Tests for {@link HttpRestartServer}. @@ -83,7 +82,7 @@ class HttpRestartServerTests { byte[] bytes = serialize(files); request.setContent(bytes); this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response)); - verify(this.delegate).updateAndRestart(this.filesCaptor.capture()); + then(this.delegate).should().updateAndRestart(this.filesCaptor.capture()); assertThat(this.filesCaptor.getValue().getFile("name")).isNotNull(); assertThat(response.getStatus()).isEqualTo(200); } @@ -93,7 +92,7 @@ class HttpRestartServerTests { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response)); - verifyNoInteractions(this.delegate); + then(this.delegate).shouldHaveNoInteractions(); assertThat(response.getStatus()).isEqualTo(500); } @@ -104,7 +103,7 @@ class HttpRestartServerTests { MockHttpServletResponse response = new MockHttpServletResponse(); request.setContent(new byte[] { 0, 0, 0 }); this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response)); - verifyNoInteractions(this.delegate); + then(this.delegate).shouldHaveNoInteractions(); assertThat(response.getStatus()).isEqualTo(500); } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/client/HttpTunnelConnectionTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/client/HttpTunnelConnectionTests.java index e24580493d..717e778a43 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/client/HttpTunnelConnectionTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/client/HttpTunnelConnectionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,9 +39,8 @@ import org.springframework.http.HttpStatus; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link HttpTunnelConnection}. @@ -109,10 +108,10 @@ class HttpTunnelConnectionTests { void closeTunnelCallsCloseableOnce() throws Exception { this.requestFactory.willRespondAfterDelay(1000, HttpStatus.GONE); WritableByteChannel channel = openTunnel(false); - verify(this.closeable, never()).close(); + then(this.closeable).should(never()).close(); channel.close(); channel.close(); - verify(this.closeable, times(1)).close(); + then(this.closeable).should().close(); } @Test diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServerHandlerTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServerHandlerTests.java index c2c0a0ae71..50f8907fa8 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServerHandlerTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServerHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link HttpTunnelServerHandler}. @@ -45,7 +45,7 @@ class HttpTunnelServerHandlerTests { ServerHttpRequest request = mock(ServerHttpRequest.class); ServerHttpResponse response = mock(ServerHttpResponse.class); handler.handle(request, response); - verify(server).handle(request, response); + then(server).should().handle(request, response); } } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServerTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServerTests.java index 85676b0966..2f1304e3f6 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServerTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServerTests.java @@ -50,10 +50,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link HttpTunnelServer}. @@ -105,10 +104,10 @@ class HttpTunnelServerTests { @Test void serverConnectedOnFirstRequest() throws Exception { - verify(this.serverConnection, never()).open(anyInt()); + then(this.serverConnection).should(never()).open(anyInt()); givenServerConnectionOpenWillAnswerWithServerChannel(); this.server.handle(this.request, this.response); - verify(this.serverConnection, times(1)).open(DEFAULT_LONG_POLL_TIMEOUT); + then(this.serverConnection).should().open(DEFAULT_LONG_POLL_TIMEOUT); } @Test @@ -116,7 +115,7 @@ class HttpTunnelServerTests { givenServerConnectionOpenWillAnswerWithServerChannel(); this.server.setLongPollTimeout(800); this.server.handle(this.request, this.response); - verify(this.serverConnection, times(1)).open(800); + then(this.serverConnection).should().open(800); } @Test @@ -294,9 +293,9 @@ class HttpTunnelServerTests { given(request.getAsyncRequestControl(this.response)).willReturn(async); HttpConnection connection = new HttpConnection(request, this.response); connection.waitForResponse(); - verify(async).start(); + then(async).should().start(); connection.respond(HttpStatus.NO_CONTENT); - verify(async).complete(); + then(async).should().complete(); } @Test diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManagerTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManagerTests.java index 330f27b3a1..ed06824cbe 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManagerTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link TestEntityManager}. @@ -72,7 +72,7 @@ class TestEntityManagerTests { given(this.entityManagerFactory.getPersistenceUnitUtil()).willReturn(this.persistenceUnitUtil); given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123); Object result = this.testEntityManager.persistAndGetId(entity); - verify(this.entityManager).persist(entity); + then(this.entityManager).should().persist(entity); assertThat(result).isEqualTo(123); } @@ -83,7 +83,7 @@ class TestEntityManagerTests { given(this.entityManagerFactory.getPersistenceUnitUtil()).willReturn(this.persistenceUnitUtil); given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123); Integer result = this.testEntityManager.persistAndGetId(entity, Integer.class); - verify(this.entityManager).persist(entity); + then(this.entityManager).should().persist(entity); assertThat(result).isEqualTo(123); } @@ -92,7 +92,7 @@ class TestEntityManagerTests { bindEntityManager(); TestEntity entity = new TestEntity(); TestEntity result = this.testEntityManager.persist(entity); - verify(this.entityManager).persist(entity); + then(this.entityManager).should().persist(entity); assertThat(result).isSameAs(entity); } @@ -101,8 +101,8 @@ class TestEntityManagerTests { bindEntityManager(); TestEntity entity = new TestEntity(); TestEntity result = this.testEntityManager.persistAndFlush(entity); - verify(this.entityManager).persist(entity); - verify(this.entityManager).flush(); + then(this.entityManager).should().persist(entity); + then(this.entityManager).should().flush(); assertThat(result).isSameAs(entity); } @@ -115,8 +115,8 @@ class TestEntityManagerTests { given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123); given(this.entityManager.find(TestEntity.class, 123)).willReturn(found); TestEntity result = this.testEntityManager.persistFlushFind(entity); - verify(this.entityManager).persist(entity); - verify(this.entityManager).flush(); + then(this.entityManager).should().persist(entity); + then(this.entityManager).should().flush(); assertThat(result).isSameAs(found); } @@ -126,7 +126,7 @@ class TestEntityManagerTests { TestEntity entity = new TestEntity(); given(this.entityManager.merge(entity)).willReturn(entity); TestEntity result = this.testEntityManager.merge(entity); - verify(this.entityManager).merge(entity); + then(this.entityManager).should().merge(entity); assertThat(result).isSameAs(entity); } @@ -135,7 +135,7 @@ class TestEntityManagerTests { bindEntityManager(); TestEntity entity = new TestEntity(); this.testEntityManager.remove(entity); - verify(this.entityManager).remove(entity); + then(this.entityManager).should().remove(entity); } @Test @@ -151,7 +151,7 @@ class TestEntityManagerTests { void flushShouldFlush() { bindEntityManager(); this.testEntityManager.flush(); - verify(this.entityManager).flush(); + then(this.entityManager).should().flush(); } @Test @@ -159,14 +159,14 @@ class TestEntityManagerTests { bindEntityManager(); TestEntity entity = new TestEntity(); this.testEntityManager.refresh(entity); - verify(this.entityManager).refresh(entity); + then(this.entityManager).should().refresh(entity); } @Test void clearShouldClear() { bindEntityManager(); this.testEntityManager.clear(); - verify(this.entityManager).clear(); + then(this.entityManager).should().clear(); } @Test @@ -174,7 +174,7 @@ class TestEntityManagerTests { bindEntityManager(); TestEntity entity = new TestEntity(); this.testEntityManager.detach(entity); - verify(this.entityManager).detach(entity); + then(this.entityManager).should().detach(entity); } @Test diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizerFactoryTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizerFactoryTests.java index a2d5197ae0..535d8f6f99 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizerFactoryTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizerFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,8 @@ import org.springframework.test.context.ContextCustomizer; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link PropertyMappingContextCustomizerFactory}. @@ -53,7 +53,7 @@ class PropertyMappingContextCustomizerFactoryTests { given(context.getEnvironment()).willReturn(environment); given(context.getBeanFactory()).willReturn(beanFactory); customizer.customizeContext(context, null); - verifyNoInteractions(environment); + then(environment).shouldHaveNoInteractions(); } @Test diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java index 61be82c7d2..df78ddd033 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,8 @@ import org.springframework.web.server.adapter.WebHttpHandlerBuilder; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link WebTestClientAutoConfiguration} @@ -65,7 +65,7 @@ class WebTestClientAutoConfigurationTests { this.contextRunner.withUserConfiguration(CodecConfiguration.class).run((context) -> { assertThat(context).hasSingleBean(WebTestClient.class); assertThat(context).hasSingleBean(CodecCustomizer.class); - verify(context.getBean(CodecCustomizer.class)).customize(any(CodecConfigurer.class)); + then(context.getBean(CodecCustomizer.class)).should().customize(any(CodecConfigurer.class)); }); } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfigurationTests.java index e7371fdd90..73feb850ca 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,8 @@ import org.springframework.web.servlet.DispatcherServlet; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link MockMvcAutoConfiguration}. @@ -70,7 +70,7 @@ class MockMvcAutoConfigurationTests { this.contextRunner.withUserConfiguration(WebTestClientCustomConfig.class).run((context) -> { assertThat(context).hasSingleBean(WebTestClient.class); assertThat(context).hasBean("myWebTestClientCustomizer"); - verify(context.getBean("myWebTestClientCustomizer", WebTestClientBuilderCustomizer.class)) + then(context.getBean("myWebTestClientCustomizer", WebTestClientBuilderCustomizer.class)).should() .customize(any(WebTestClient.Builder.class)); }); } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProviderTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProviderTests.java index 7e84cc6a04..b77726ec5f 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProviderTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import org.springframework.context.support.StaticApplicationContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link ApplicationContextAssertProvider} and @@ -102,7 +102,7 @@ class ApplicationContextAssertProviderTests { ApplicationContextAssertProvider context = get(this.mockContextSupplier); assertThat((Object) context).isNotNull(); context.getBean("foo"); - verify(this.mockContext).getBean("foo"); + then(this.mockContext).should().getBean("foo"); } @Test @@ -186,7 +186,7 @@ class ApplicationContextAssertProviderTests { void closeShouldCloseContext() { ApplicationContextAssertProvider context = get(this.mockContextSupplier); context.close(); - verify(this.mockContext).close(); + then(this.mockContext).should().close(); } private ApplicationContextAssertProvider get(Supplier contextSupplier) { diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/nestedtests/InheritedNestedTestConfigurationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/nestedtests/InheritedNestedTestConfigurationTests.java index 528a8ae355..c898c6cbfd 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/nestedtests/InheritedNestedTestConfigurationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/nestedtests/InheritedNestedTestConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import org.springframework.stereotype.Component; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for nested test configuration when the configuration is inherited from the @@ -50,14 +50,14 @@ class InheritedNestedTestConfigurationTests { @Test void mockWasInvokedOnce() { this.performer.run(); - verify(this.action, times(1)).perform(); + then(this.action).should().perform(); } @Test void mockWasInvokedTwice() { this.performer.run(); this.performer.run(); - verify(this.action, times(2)).perform(); + then(this.action).should(times(2)).perform(); } @Nested @@ -66,14 +66,14 @@ class InheritedNestedTestConfigurationTests { @Test void mockWasInvokedOnce() { InheritedNestedTestConfigurationTests.this.performer.run(); - verify(InheritedNestedTestConfigurationTests.this.action, times(1)).perform(); + then(InheritedNestedTestConfigurationTests.this.action).should().perform(); } @Test void mockWasInvokedTwice() { InheritedNestedTestConfigurationTests.this.performer.run(); InheritedNestedTestConfigurationTests.this.performer.run(); - verify(InheritedNestedTestConfigurationTests.this.action, times(2)).perform(); + then(InheritedNestedTestConfigurationTests.this.action).should(times(2)).perform(); } } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/ContextConsumerTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/ContextConsumerTests.java index 62bd0b5810..5c19d70a6f 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/ContextConsumerTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/ContextConsumerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,10 +27,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link ContextConsumer}. @@ -62,8 +61,8 @@ class ContextConsumerTests { ContextConsumer secondConsumer = (context) -> assertThat(predicate.test(24)).isFalse(); assertThatThrownBy(() -> firstConsumer.andThen(secondConsumer).accept(mock(ApplicationContext.class))) .isInstanceOf(AssertionError.class); - verify(predicate).test(42); - verifyNoMoreInteractions(predicate); + then(predicate).should().test(42); + then(predicate).shouldHaveNoMoreInteractions(); } @Test diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests.java index f86d587772..30a54cab0e 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link MockBean @MockBean} on a test class field can be used to replace existing @@ -56,7 +56,7 @@ class MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests { @Test void testMocking() { this.caller.sayGreeting(); - verify(this.service).greeting(); + then(this.service).should().greeting(); } @Test diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanWithAopProxyTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanWithAopProxyTests.java index cb9d4d16d1..32c9577625 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanWithAopProxyTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanWithAopProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Test {@link MockBean @MockBean} when mixed with Spring AOP. @@ -60,9 +60,9 @@ class MockBeanWithAopProxyTests { given(this.dateService.getDate(false)).willReturn(2L); Long d2 = this.dateService.getDate(false); assertThat(d2).isEqualTo(2L); - verify(this.dateService, times(2)).getDate(false); - verify(this.dateService, times(2)).getDate(eq(false)); - verify(this.dateService, times(2)).getDate(anyBoolean()); + then(this.dateService).should(times(2)).getDate(false); + then(this.dateService).should(times(2)).getDate(eq(false)); + then(this.dateService).should(times(2)).getDate(anyBoolean()); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListenerTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListenerTests.java index 40b9762c55..05d8ed51fa 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListenerTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,9 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link MockitoTestExecutionListener}. @@ -72,14 +71,14 @@ class MockitoTestExecutionListenerTests { TestContext testContext = mockTestContext(instance); given(testContext.getApplicationContext()).willReturn(this.applicationContext); this.listener.prepareTestInstance(testContext); - verify(this.postProcessor).inject(this.fieldCaptor.capture(), eq(instance), any(MockDefinition.class)); + then(this.postProcessor).should().inject(this.fieldCaptor.capture(), eq(instance), any(MockDefinition.class)); assertThat(this.fieldCaptor.getValue().getName()).isEqualTo("mockBean"); } @Test void beforeTestMethodShouldDoNothingWhenDirtiesContextAttributeIsNotSet() throws Exception { this.listener.beforeTestMethod(mock(TestContext.class)); - verifyNoMoreInteractions(this.postProcessor); + then(this.postProcessor).shouldHaveNoMoreInteractions(); } @Test @@ -91,7 +90,7 @@ class MockitoTestExecutionListenerTests { given(mockTestContext.getAttribute(DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE)) .willReturn(Boolean.TRUE); this.listener.beforeTestMethod(mockTestContext); - verify(this.postProcessor).inject(this.fieldCaptor.capture(), eq(instance), any(MockDefinition.class)); + then(this.postProcessor).should().inject(this.fieldCaptor.capture(), eq(instance), any(MockDefinition.class)); assertThat(this.fieldCaptor.getValue().getName()).isEqualTo("mockBean"); } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/QualifierDefinitionTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/QualifierDefinitionTests.java index 2d7abb01a6..53272bd00b 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/QualifierDefinitionTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/QualifierDefinitionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link QualifierDefinition}. @@ -81,7 +81,7 @@ class QualifierDefinitionTests { Field field = ReflectionUtils.findField(ConfigA.class, "directQualifier"); QualifierDefinition qualifierDefinition = QualifierDefinition.forElement(field); qualifierDefinition.matches(this.beanFactory, "bean"); - verify(this.beanFactory).isAutowireCandidate(eq("bean"), this.descriptorCaptor.capture()); + then(this.beanFactory).should().isAutowireCandidate(eq("bean"), this.descriptorCaptor.capture()); assertThat(this.descriptorCaptor.getValue().getAnnotatedElement()).isEqualTo(field); } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationClassForExistingBeanIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationClassForExistingBeanIntegrationTests.java index 924a39b7cf..e39877a322 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationClassForExistingBeanIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationClassForExistingBeanIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a configuration class can be used to spy existing @@ -44,7 +44,7 @@ class SpyBeanOnConfigurationClassForExistingBeanIntegrationTests { @Test void testSpying() { assertThat(this.caller.sayGreeting()).isEqualTo("I say simple"); - verify(this.caller.getService()).greeting(); + then(this.caller.getService()).should().greeting(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationClassForNewBeanIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationClassForNewBeanIntegrationTests.java index 312de6761c..3bccd8ead1 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationClassForNewBeanIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationClassForNewBeanIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a configuration class can be used to inject new spy @@ -44,7 +44,7 @@ class SpyBeanOnConfigurationClassForNewBeanIntegrationTests { @Test void testSpying() { assertThat(this.caller.sayGreeting()).isEqualTo("I say simple"); - verify(this.caller.getService()).greeting(); + then(this.caller.getService()).should().greeting(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationFieldForExistingBeanIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationFieldForExistingBeanIntegrationTests.java index bab4a63935..3b8a2163b1 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationFieldForExistingBeanIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationFieldForExistingBeanIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a field on a {@code @Configuration} class can be used @@ -48,7 +48,7 @@ class SpyBeanOnConfigurationFieldForExistingBeanIntegrationTests { @Test void testSpying() { assertThat(this.caller.sayGreeting()).isEqualTo("I say simple"); - verify(this.config.exampleService).greeting(); + then(this.config.exampleService).should().greeting(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationFieldForNewBeanIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationFieldForNewBeanIntegrationTests.java index 4faca40b21..447022fc65 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationFieldForNewBeanIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnConfigurationFieldForNewBeanIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a field on a {@code @Configuration} class can be used @@ -47,7 +47,7 @@ class SpyBeanOnConfigurationFieldForNewBeanIntegrationTests { @Test void testSpying() { assertThat(this.caller.sayGreeting()).isEqualTo("I say simple"); - verify(this.config.exampleService).greeting(); + then(this.config.exampleService).should().greeting(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestClassForExistingBeanIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestClassForExistingBeanIntegrationTests.java index 702d6b642c..d35570810b 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestClassForExistingBeanIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestClassForExistingBeanIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a test class can be used to replace existing beans. @@ -44,7 +44,7 @@ class SpyBeanOnTestClassForExistingBeanIntegrationTests { @Test void testSpying() { assertThat(this.caller.sayGreeting()).isEqualTo("I say simple"); - verify(this.caller.getService()).greeting(); + then(this.caller.getService()).should().greeting(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestClassForNewBeanIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestClassForNewBeanIntegrationTests.java index 1e73eb2982..ddc2fed148 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestClassForNewBeanIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestClassForNewBeanIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a test class can be used to inject new spy instances. @@ -44,7 +44,7 @@ class SpyBeanOnTestClassForNewBeanIntegrationTests { @Test void testSpying() { assertThat(this.caller.sayGreeting()).isEqualTo("I say simple"); - verify(this.caller.getService()).greeting(); + then(this.caller.getService()).should().greeting(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanCacheIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanCacheIntegrationTests.java index 83392ea4b5..45cd5879ba 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanCacheIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanCacheIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a test class field can be used to replace existing @@ -50,7 +50,7 @@ class SpyBeanOnTestFieldForExistingBeanCacheIntegrationTests { @Test void testSpying() { assertThat(this.caller.sayGreeting()).isEqualTo("I say simple"); - verify(this.caller.getService()).greeting(); + then(this.caller.getService()).should().greeting(); } } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanIntegrationTests.java index e66f351809..0043abd197 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a test class field can be used to replace existing @@ -48,7 +48,7 @@ class SpyBeanOnTestFieldForExistingBeanIntegrationTests { @Test void testSpying() { assertThat(this.caller.sayGreeting()).isEqualTo("I say simple"); - verify(this.caller.getService()).greeting(); + then(this.caller.getService()).should().greeting(); } } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests.java index 8470a405bc..a758fdb8c3 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a test class field can be used to replace existing @@ -55,7 +55,7 @@ class SpyBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests { @Test void testMocking() throws Exception { this.caller.sayGreeting(); - verify(this.service).greeting(); + then(this.service).should().greeting(); } @Test diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingGenericBeanIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingGenericBeanIntegrationTests.java index c656bc13f8..d3034b61c8 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingGenericBeanIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingGenericBeanIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a test class field can be used to replace existing @@ -53,7 +53,7 @@ class SpyBeanOnTestFieldForExistingGenericBeanIntegrationTests { @Test void testSpying() { assertThat(this.caller.sayGreeting()).isEqualTo("I say 123 simple"); - verify(this.exampleService).greeting(); + then(this.exampleService).should().greeting(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForMultipleExistingBeansWithOnePrimaryIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForMultipleExistingBeansWithOnePrimaryIntegrationTests.java index 83276bb8f1..6751f49f0c 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForMultipleExistingBeansWithOnePrimaryIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForMultipleExistingBeansWithOnePrimaryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a test class field can be used to inject a spy @@ -52,7 +52,7 @@ class SpyBeanOnTestFieldForMultipleExistingBeansWithOnePrimaryIntegrationTests { assertThat(this.caller.sayGreeting()).isEqualTo("I say two"); assertThat(Mockito.mockingDetails(this.spy).getMockCreationSettings().getMockName().toString()) .isEqualTo("two"); - verify(this.spy).greeting(); + then(this.spy).should().greeting(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForNewBeanIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForNewBeanIntegrationTests.java index 91a1b8f59c..2cf35176d8 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForNewBeanIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForNewBeanIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} on a test class field can be used to inject new spy @@ -47,7 +47,7 @@ class SpyBeanOnTestFieldForNewBeanIntegrationTests { @Test void testSpying() { assertThat(this.caller.sayGreeting()).isEqualTo("I say simple"); - verify(this.caller.getService()).greeting(); + then(this.caller.getService()).should().greeting(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyAndNotProxyTargetAwareTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyAndNotProxyTargetAwareTests.java index 8b67ebbf9c..38b5439a39 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyAndNotProxyTargetAwareTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyAndNotProxyTargetAwareTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,8 @@ import org.springframework.stereotype.Service; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Test {@link SpyBean @SpyBean} when mixed with Spring AOP. @@ -54,7 +53,7 @@ class SpyBeanWithAopProxyAndNotProxyTargetAwareTests { @Test void verifyShouldUseProxyTarget() { this.dateService.getDate(false); - verify(this.dateService, times(1)).getDate(false); + then(this.dateService).should().getDate(false); assertThatExceptionOfType(UnfinishedVerificationException.class).isThrownBy(() -> reset(this.dateService)); } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyTests.java index 14dfacc187..2c0fd0e2a8 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Test {@link SpyBean @SpyBean} when mixed with Spring AOP. @@ -57,9 +56,9 @@ class SpyBeanWithAopProxyTests { Thread.sleep(200); Long d2 = this.dateService.getDate(false); assertThat(d1).isEqualTo(d2); - verify(this.dateService, times(1)).getDate(false); - verify(this.dateService, times(1)).getDate(eq(false)); - verify(this.dateService, times(1)).getDate(anyBoolean()); + then(this.dateService).should().getDate(false); + then(this.dateService).should().getDate(eq(false)); + then(this.dateService).should().getDate(anyBoolean()); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithDirtiesContextClassModeBeforeMethodIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithDirtiesContextClassModeBeforeMethodIntegrationTests.java index d141dcbf42..875deecc1e 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithDirtiesContextClassModeBeforeMethodIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithDirtiesContextClassModeBeforeMethodIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Integration tests for using {@link SpyBean @SpyBean} with @@ -49,7 +49,7 @@ class SpyBeanWithDirtiesContextClassModeBeforeMethodIntegrationTests { @Test void testSpying() throws Exception { this.caller.sayGreeting(); - verify(this.exampleService).greeting(); + then(this.exampleService).should().greeting(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithJdkProxyTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithJdkProxyTests.java index c096396116..002ca14dec 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithJdkProxyTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithJdkProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link SpyBean @SpyBean} with a JDK proxy. @@ -50,7 +50,7 @@ class SpyBeanWithJdkProxyTests { void jdkProxyCanBeSpied() throws Exception { Example example = this.service.find("id"); assertThat(example.id).isEqualTo("id"); - verify(this.repository).find("id"); + then(this.repository).should().find("id"); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/util/ApplicationContextTestUtilsTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/util/ApplicationContextTestUtilsTests.java index 68e2c5ba5d..13aaaf2cec 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/util/ApplicationContextTestUtilsTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/util/ApplicationContextTestUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link ApplicationContextTestUtils}. @@ -50,10 +50,10 @@ class ApplicationContextTestUtilsTests { given(mock.getParent()).willReturn(parent); given(parent.getParent()).willReturn(null); ApplicationContextTestUtils.closeAll(mock); - verify(mock).getParent(); - verify(mock).close(); - verify(parent).getParent(); - verify(parent).close(); + then(mock).should().getParent(); + then(mock).should().close(); + then(parent).should().getParent(); + then(parent).should().close(); } } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandlerTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandlerTests.java index ad1f67f2eb..85d0e57b84 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandlerTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import org.springframework.web.util.UriTemplateHandler; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link LocalHostUriTemplateHandler}. @@ -99,7 +99,7 @@ class LocalHostUriTemplateHandlerTests { given(uriTemplateHandler.expand("https://localhost:8080/", uriVariables)).willReturn(uri); LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(environment, "https", uriTemplateHandler); assertThat(handler.expand("/", uriVariables)).isEqualTo(uri); - verify(uriTemplateHandler).expand("https://localhost:8080/", uriVariables); + then(uriTemplateHandler).should().expand("https://localhost:8080/", uriVariables); } } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/RootUriRequestExpectationManagerTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/RootUriRequestExpectationManagerTests.java index 5402ecc069..2fd99419ca 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/RootUriRequestExpectationManagerTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/RootUriRequestExpectationManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,8 +40,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; @@ -85,7 +85,7 @@ class RootUriRequestExpectationManagerTests { ExpectedCount count = ExpectedCount.once(); RequestMatcher requestMatcher = mock(RequestMatcher.class); this.manager.expectRequest(count, requestMatcher); - verify(this.delegate).expectRequest(count, requestMatcher); + then(this.delegate).should().expectRequest(count, requestMatcher); } @Test @@ -93,7 +93,7 @@ class RootUriRequestExpectationManagerTests { ClientHttpRequest request = mock(ClientHttpRequest.class); given(request.getURI()).willReturn(new URI("https://spring.io/test")); this.manager.validateRequest(request); - verify(this.delegate).validateRequest(request); + then(this.delegate).should().validateRequest(request); } @Test @@ -101,7 +101,7 @@ class RootUriRequestExpectationManagerTests { ClientHttpRequest request = mock(ClientHttpRequest.class); given(request.getURI()).willReturn(new URI(this.uri + "/hello")); this.manager.validateRequest(request); - verify(this.delegate).validateRequest(this.requestCaptor.capture()); + then(this.delegate).should().validateRequest(this.requestCaptor.capture()); HttpRequestWrapper actual = (HttpRequestWrapper) this.requestCaptor.getValue(); assertThat(actual.getRequest()).isSameAs(request); assertThat(actual.getURI()).isEqualTo(new URI("/hello")); @@ -120,7 +120,7 @@ class RootUriRequestExpectationManagerTests { @Test void resetRequestShouldDelegateToExpectationManager() { this.manager.reset(); - verify(this.delegate).reset(); + then(this.delegate).should().reset(); } @Test diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java index 974065672d..4215136214 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,8 +56,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link TestRestTemplate}. @@ -246,7 +246,7 @@ class TestRestTemplateTests { LocalHostUriTemplateHandler uriTemplateHandler = new LocalHostUriTemplateHandler(new MockEnvironment()); template.setUriTemplateHandler(uriTemplateHandler); template.exchange(entity, String.class); - verify(requestFactory).createRequest(eq(absoluteUri), eq(HttpMethod.GET)); + then(requestFactory).should().createRequest(eq(absoluteUri), eq(HttpMethod.GET)); } @Test @@ -260,7 +260,7 @@ class TestRestTemplateTests { given(requestFactory.createRequest(eq(absoluteUri), eq(HttpMethod.GET))).willReturn(request); template.getRestTemplate().setRequestFactory(requestFactory); template.exchange(entity, String.class); - verify(requestFactory).createRequest(eq(absoluteUri), eq(HttpMethod.GET)); + then(requestFactory).should().createRequest(eq(absoluteUri), eq(HttpMethod.GET)); } @Test @@ -362,7 +362,7 @@ class TestRestTemplateTests { LocalHostUriTemplateHandler uriTemplateHandler = new LocalHostUriTemplateHandler(new MockEnvironment()); template.setUriTemplateHandler(uriTemplateHandler); callback.doWithTestRestTemplate(template, URI.create("/a/b/c.txt?param=%7Bsomething%7D")); - verify(requestFactory).createRequest(eq(absoluteUri), any(HttpMethod.class)); + then(requestFactory).should().createRequest(eq(absoluteUri), any(HttpMethod.class)); } private void assertBasicAuthorizationCredentials(TestRestTemplate testRestTemplate, String username, diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/LocalHostWebClientTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/LocalHostWebClientTests.java index 9d81260b5b..46c461341a 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/LocalHostWebClientTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/LocalHostWebClientTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link LocalHostWebClient}. @@ -64,7 +64,7 @@ class LocalHostWebClientTests { WebConnection connection = mockConnection(); client.setWebConnection(connection); client.getPage("/test"); - verify(connection).getResponse(this.requestCaptor.capture()); + then(connection).should().getResponse(this.requestCaptor.capture()); assertThat(this.requestCaptor.getValue().getUrl()).isEqualTo(new URL("http://localhost:8080/test")); } @@ -76,7 +76,7 @@ class LocalHostWebClientTests { WebConnection connection = mockConnection(); client.setWebConnection(connection); client.getPage("/test"); - verify(connection).getResponse(this.requestCaptor.capture()); + then(connection).should().getResponse(this.requestCaptor.capture()); assertThat(this.requestCaptor.getValue().getUrl()).isEqualTo(new URL("http://localhost:8181/test")); } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java index 2e4b3b3bff..4efbc280f4 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java @@ -38,8 +38,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link LocalHostWebConnectionHtmlUnitDriver}. @@ -94,7 +94,8 @@ class LocalHostWebConnectionHtmlUnitDriverTests { MockEnvironment environment = new MockEnvironment(); LocalHostWebConnectionHtmlUnitDriver driver = new TestLocalHostWebConnectionHtmlUnitDriver(environment); driver.get("/test"); - verify(this.webClient).getPage(isNull(), requestToUrl(new URL("http://localhost:8080/test"))); + then(this.webClient).should().getPage(isNull(), + requestToUrl(new URL("http://localhost:8080/test"))); } @Test @@ -103,7 +104,8 @@ class LocalHostWebConnectionHtmlUnitDriverTests { environment.setProperty("local.server.port", "8181"); LocalHostWebConnectionHtmlUnitDriver driver = new TestLocalHostWebConnectionHtmlUnitDriver(environment); driver.get("/test"); - verify(this.webClient).getPage(isNull(), requestToUrl(new URL("http://localhost:8181/test"))); + then(this.webClient).should().getPage(isNull(), + requestToUrl(new URL("http://localhost:8181/test"))); } private WebRequest requestToUrl(URL url) { diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/reactive/server/WebTestClientContextCustomizerIntegrationTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/reactive/server/WebTestClientContextCustomizerIntegrationTests.java index e616464908..ee02eaff23 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/reactive/server/WebTestClientContextCustomizerIntegrationTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/reactive/server/WebTestClientContextCustomizerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,8 @@ import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClient.Builder; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Integration test for {@link WebTestClientContextCustomizer}. @@ -56,7 +56,7 @@ class WebTestClientContextCustomizerIntegrationTests { @Test void test() { - verify(this.clientBuilderCustomizer).customize(any(Builder.class)); + then(this.clientBuilderCustomizer).should().customize(any(Builder.class)); this.webTestClient.get().uri("/").exchange().expectBody(String.class).isEqualTo("hello"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java index 38bef618b6..32ad37e113 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,11 +47,10 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link Builder}. @@ -97,11 +96,13 @@ class BuilderTests { assertThat(out.toString()).contains("Running creator"); assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); - verify(docker.image()).pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull()); - verify(docker.image()).pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull()); - verify(docker.image()).load(archive.capture(), any()); - verify(docker.image()).remove(archive.getValue().getTag(), true); - verifyNoMoreInteractions(docker.image()); + then(docker.image()).should().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), + isNull()); + then(docker.image()).should().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), + isNull()); + then(docker.image()).should().load(archive.capture(), any()); + then(docker.image()).should().remove(archive.getValue().getTag(), true); + then(docker.image()).shouldHaveNoMoreInteractions(); } @Test @@ -125,15 +126,15 @@ class BuilderTests { assertThat(out.toString()).contains("Running creator"); assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); - verify(docker.image()).pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), + then(docker.image()).should().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())); - verify(docker.image()).pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), + then(docker.image()).should().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())); - verify(docker.image()).push(eq(request.getName()), any(), + then(docker.image()).should().push(eq(request.getName()), any(), eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader())); - verify(docker.image()).load(archive.capture(), any()); - verify(docker.image()).remove(archive.getValue().getTag(), true); - verifyNoMoreInteractions(docker.image()); + then(docker.image()).should().load(archive.capture(), any()); + then(docker.image()).should().remove(archive.getValue().getTag(), true); + then(docker.image()).shouldHaveNoMoreInteractions(); } @Test @@ -152,8 +153,8 @@ class BuilderTests { assertThat(out.toString()).contains("Running creator"); assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); - verify(docker.image()).load(archive.capture(), any()); - verify(docker.image()).remove(archive.getValue().getTag(), true); + then(docker.image()).should().load(archive.capture(), any()); + then(docker.image()).should().remove(archive.getValue().getTag(), true); } @Test @@ -173,8 +174,8 @@ class BuilderTests { assertThat(out.toString()).contains("Running creator"); assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); - verify(docker.image()).load(archive.capture(), any()); - verify(docker.image()).remove(archive.getValue().getTag(), true); + then(docker.image()).should().load(archive.capture(), any()); + then(docker.image()).should().remove(archive.getValue().getTag(), true); } @Test @@ -193,8 +194,8 @@ class BuilderTests { assertThat(out.toString()).contains("Running creator"); assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); - verify(docker.image()).load(archive.capture(), any()); - verify(docker.image()).remove(archive.getValue().getTag(), true); + then(docker.image()).should().load(archive.capture(), any()); + then(docker.image()).should().remove(archive.getValue().getTag(), true); } @Test @@ -217,10 +218,10 @@ class BuilderTests { assertThat(out.toString()).contains("Running creator"); assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); - verify(docker.image()).load(archive.capture(), any()); - verify(docker.image()).remove(archive.getValue().getTag(), true); - verify(docker.image(), never()).pull(any(), any()); - verify(docker.image(), times(2)).inspect(any()); + then(docker.image()).should().load(archive.capture(), any()); + then(docker.image()).should().remove(archive.getValue().getTag(), true); + then(docker.image()).should(never()).pull(any(), any()); + then(docker.image()).should(times(2)).inspect(any()); } @Test @@ -243,10 +244,10 @@ class BuilderTests { assertThat(out.toString()).contains("Running creator"); assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); - verify(docker.image()).load(archive.capture(), any()); - verify(docker.image()).remove(archive.getValue().getTag(), true); - verify(docker.image(), times(2)).pull(any(), any(), isNull()); - verify(docker.image(), never()).inspect(any()); + then(docker.image()).should().load(archive.capture(), any()); + then(docker.image()).should().remove(archive.getValue().getTag(), true); + then(docker.image()).should(times(2)).pull(any(), any(), isNull()); + then(docker.image()).should(never()).inspect(any()); } @Test @@ -271,10 +272,10 @@ class BuilderTests { assertThat(out.toString()).contains("Running creator"); assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); - verify(docker.image()).load(archive.capture(), any()); - verify(docker.image()).remove(archive.getValue().getTag(), true); - verify(docker.image(), times(2)).inspect(any()); - verify(docker.image(), times(2)).pull(any(), any(), isNull()); + then(docker.image()).should().load(archive.capture(), any()); + then(docker.image()).should().remove(archive.getValue().getTag(), true); + then(docker.image()).should(times(2)).inspect(any()); + then(docker.image()).should(times(2)).pull(any(), any(), isNull()); } @Test @@ -293,10 +294,10 @@ class BuilderTests { assertThat(out.toString()).contains("Running creator"); assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); assertThat(out.toString()).contains("Successfully created image tag 'docker.io/library/my-application:1.2.3'"); - verify(docker.image()).tag(eq(request.getName()), eq(ImageReference.of("my-application:1.2.3"))); + then(docker.image()).should().tag(eq(request.getName()), eq(ImageReference.of("my-application:1.2.3"))); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); - verify(docker.image()).load(archive.capture(), any()); - verify(docker.image()).remove(archive.getValue().getTag(), true); + then(docker.image()).should().load(archive.capture(), any()); + then(docker.image()).should().remove(archive.getValue().getTag(), true); } @Test @@ -321,19 +322,19 @@ class BuilderTests { assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); assertThat(out.toString()).contains("Successfully created image tag 'docker.io/library/my-application:1.2.3'"); - verify(docker.image()).pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), + then(docker.image()).should().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())); - verify(docker.image()).pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), + then(docker.image()).should().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())); - verify(docker.image()).push(eq(request.getName()), any(), + then(docker.image()).should().push(eq(request.getName()), any(), eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader())); - verify(docker.image()).tag(eq(request.getName()), eq(ImageReference.of("my-application:1.2.3"))); - verify(docker.image()).push(eq(ImageReference.of("my-application:1.2.3")), any(), + then(docker.image()).should().tag(eq(request.getName()), eq(ImageReference.of("my-application:1.2.3"))); + then(docker.image()).should().push(eq(ImageReference.of("my-application:1.2.3")), any(), eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader())); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); - verify(docker.image()).load(archive.capture(), any()); - verify(docker.image()).remove(archive.getValue().getTag(), true); - verifyNoMoreInteractions(docker.image()); + then(docker.image()).should().load(archive.capture(), any()); + then(docker.image()).should().remove(archive.getValue().getTag(), true); + then(docker.image()).shouldHaveNoMoreInteractions(); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java index b6e4af0b3b..48347e3db6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,8 +54,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link Lifecycle}. @@ -150,7 +150,7 @@ class LifecycleTests { createLifecycle(request).execute(); assertPhaseWasRun("creator", withExpectedConfig("lifecycle-creator-clean-cache.json")); VolumeName name = VolumeName.of("pack-cache-b35197ac41ea.build"); - verify(this.docker.volume()).delete(name, true); + then(this.docker.volume()).should().delete(name, true); } @Test @@ -185,8 +185,8 @@ class LifecycleTests { @Test void closeClearsVolumes() throws Exception { createLifecycle().close(); - verify(this.docker.volume()).delete(VolumeName.of("pack-layers-aaaaaaaaaa"), true); - verify(this.docker.volume()).delete(VolumeName.of("pack-app-aaaaaaaaaa"), true); + then(this.docker.volume()).should().delete(VolumeName.of("pack-layers-aaaaaaaaaa"), true); + then(this.docker.volume()).should().delete(VolumeName.of("pack-app-aaaaaaaaaa"), true); } @Test @@ -280,9 +280,9 @@ class LifecycleTests { private void assertPhaseWasRun(String name, IOConsumer configConsumer) throws IOException { ContainerReference containerReference = ContainerReference.of("cnb-lifecycle-" + name); - verify(this.docker.container()).start(containerReference); - verify(this.docker.container()).logs(eq(containerReference), any()); - verify(this.docker.container()).remove(containerReference, true); + then(this.docker.container()).should().start(containerReference); + then(this.docker.container()).should().logs(eq(containerReference), any()); + then(this.docker.container()).should().remove(containerReference, true); configConsumer.accept(this.configs.get(containerReference.toString())); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/PhaseTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/PhaseTests.java index 6bed915d45..3045853250 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/PhaseTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/PhaseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,8 @@ import org.springframework.boot.buildpack.platform.docker.type.ContainerConfig.U import org.springframework.boot.buildpack.platform.docker.type.VolumeName; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link Phase}. @@ -55,9 +54,9 @@ class PhaseTests { Phase phase = new Phase("test", false); Update update = mock(Update.class); phase.apply(update); - verify(update).withCommand("/cnb/lifecycle/test", NO_ARGS); - verify(update).withLabel("author", "spring-boot"); - verifyNoMoreInteractions(update); + then(update).should().withCommand("/cnb/lifecycle/test", NO_ARGS); + then(update).should().withLabel("author", "spring-boot"); + then(update).shouldHaveNoMoreInteractions(); } @Test @@ -66,11 +65,11 @@ class PhaseTests { phase.withDaemonAccess(); Update update = mock(Update.class); phase.apply(update); - verify(update).withUser("root"); - verify(update).withBinding(Binding.from("/var/run/docker.sock", "/var/run/docker.sock")); - verify(update).withCommand("/cnb/lifecycle/test", NO_ARGS); - verify(update).withLabel("author", "spring-boot"); - verifyNoMoreInteractions(update); + then(update).should().withUser("root"); + then(update).should().withBinding(Binding.from("/var/run/docker.sock", "/var/run/docker.sock")); + then(update).should().withCommand("/cnb/lifecycle/test", NO_ARGS); + then(update).should().withLabel("author", "spring-boot"); + then(update).shouldHaveNoMoreInteractions(); } @Test @@ -79,9 +78,9 @@ class PhaseTests { phase.withLogLevelArg(); Update update = mock(Update.class); phase.apply(update); - verify(update).withCommand("/cnb/lifecycle/test", "-log-level", "debug"); - verify(update).withLabel("author", "spring-boot"); - verifyNoMoreInteractions(update); + then(update).should().withCommand("/cnb/lifecycle/test", "-log-level", "debug"); + then(update).should().withLabel("author", "spring-boot"); + then(update).shouldHaveNoMoreInteractions(); } @Test @@ -90,9 +89,9 @@ class PhaseTests { phase.withLogLevelArg(); Update update = mock(Update.class); phase.apply(update); - verify(update).withCommand("/cnb/lifecycle/test"); - verify(update).withLabel("author", "spring-boot"); - verifyNoMoreInteractions(update); + then(update).should().withCommand("/cnb/lifecycle/test"); + then(update).should().withLabel("author", "spring-boot"); + then(update).shouldHaveNoMoreInteractions(); } @Test @@ -101,9 +100,9 @@ class PhaseTests { phase.withArgs("a", "b", "c"); Update update = mock(Update.class); phase.apply(update); - verify(update).withCommand("/cnb/lifecycle/test", "a", "b", "c"); - verify(update).withLabel("author", "spring-boot"); - verifyNoMoreInteractions(update); + then(update).should().withCommand("/cnb/lifecycle/test", "a", "b", "c"); + then(update).should().withLabel("author", "spring-boot"); + then(update).shouldHaveNoMoreInteractions(); } @Test @@ -113,10 +112,10 @@ class PhaseTests { phase.withBinding(Binding.from(volumeName, "/test")); Update update = mock(Update.class); phase.apply(update); - verify(update).withCommand("/cnb/lifecycle/test"); - verify(update).withLabel("author", "spring-boot"); - verify(update).withBinding(Binding.from(volumeName, "/test")); - verifyNoMoreInteractions(update); + then(update).should().withCommand("/cnb/lifecycle/test"); + then(update).should().withLabel("author", "spring-boot"); + then(update).should().withBinding(Binding.from(volumeName, "/test")); + then(update).shouldHaveNoMoreInteractions(); } @Test @@ -126,11 +125,11 @@ class PhaseTests { phase.withEnv("name2", "value2"); Update update = mock(Update.class); phase.apply(update); - verify(update).withCommand("/cnb/lifecycle/test"); - verify(update).withLabel("author", "spring-boot"); - verify(update).withEnv("name1", "value1"); - verify(update).withEnv("name2", "value2"); - verifyNoMoreInteractions(update); + then(update).should().withCommand("/cnb/lifecycle/test"); + then(update).should().withLabel("author", "spring-boot"); + then(update).should().withEnv("name1", "value1"); + then(update).should().withEnv("name2", "value2"); + then(update).shouldHaveNoMoreInteractions(); } @Test @@ -139,10 +138,10 @@ class PhaseTests { phase.withNetworkMode("test"); Update update = mock(Update.class); phase.apply(update); - verify(update).withCommand("/cnb/lifecycle/test"); - verify(update).withNetworkMode("test"); - verify(update).withLabel("author", "spring-boot"); - verifyNoMoreInteractions(update); + then(update).should().withCommand("/cnb/lifecycle/test"); + then(update).should().withNetworkMode("test"); + then(update).should().withLabel("author", "spring-boot"); + then(update).shouldHaveNoMoreInteractions(); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/DockerApiTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/DockerApiTests.java index 3270e041bb..d1272ff2a3 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/DockerApiTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/DockerApiTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,10 +61,10 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link DockerApi}. @@ -261,7 +261,7 @@ class DockerApiTests { ordered.verify(this.loadListener).onStart(); ordered.verify(this.loadListener).onUpdate(any()); ordered.verify(this.loadListener).onFinish(); - verify(http()).post(any(), any(), this.writer.capture()); + then(http()).should().post(any(), any(), this.writer.capture()); ByteArrayOutputStream out = new ByteArrayOutputStream(); this.writer.getValue().accept(out); assertThat(out.toByteArray()).hasSizeGreaterThan(21000); @@ -281,7 +281,7 @@ class DockerApiTests { + "/docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d"); given(http().delete(removeUri)).willReturn(emptyResponse()); this.api.remove(reference, false); - verify(http()).delete(removeUri); + then(http()).should().delete(removeUri); } @Test @@ -292,7 +292,7 @@ class DockerApiTests { + "/docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d?force=1"); given(http().delete(removeUri)).willReturn(emptyResponse()); this.api.remove(reference, true); - verify(http()).delete(removeUri); + then(http()).should().delete(removeUri); } @Test @@ -370,7 +370,7 @@ class DockerApiTests { URI tagURI = new URI(IMAGES_URL + "/localhost:5000/ubuntu/tag?repo=localhost%3A5000%2Fubuntu%3Atagged"); given(http().post(tagURI)).willReturn(emptyResponse()); this.api.tag(sourceReference, targetReference); - verify(http()).post(tagURI); + then(http()).should().post(tagURI); } } @@ -406,7 +406,7 @@ class DockerApiTests { .willReturn(responseOf("create-container-response.json")); ContainerReference containerReference = this.api.create(config); assertThat(containerReference.toString()).isEqualTo("e90e34656806"); - verify(http()).post(any(), any(), this.writer.capture()); + then(http()).should().post(any(), any(), this.writer.capture()); ByteArrayOutputStream out = new ByteArrayOutputStream(); this.writer.getValue().accept(out); assertThat(out.toByteArray().length).isEqualTo(config.toString().length()); @@ -428,11 +428,11 @@ class DockerApiTests { given(http().put(eq(uploadUri), eq("application/x-tar"), any())).willReturn(emptyResponse()); ContainerReference containerReference = this.api.create(config, content); assertThat(containerReference.toString()).isEqualTo("e90e34656806"); - verify(http()).post(any(), any(), this.writer.capture()); + then(http()).should().post(any(), any(), this.writer.capture()); ByteArrayOutputStream out = new ByteArrayOutputStream(); this.writer.getValue().accept(out); assertThat(out.toByteArray().length).isEqualTo(config.toString().length()); - verify(http()).put(any(), any(), this.writer.capture()); + then(http()).should().put(any(), any(), this.writer.capture()); this.writer.getValue().accept(out); assertThat(out.toByteArray()).hasSizeGreaterThan(2000); } @@ -449,7 +449,7 @@ class DockerApiTests { URI startContainerUri = new URI(CONTAINERS_URL + "/e90e34656806/start"); given(http().post(startContainerUri)).willReturn(emptyResponse()); this.api.start(reference); - verify(http()).post(startContainerUri); + then(http()).should().post(startContainerUri); } @Test @@ -504,7 +504,7 @@ class DockerApiTests { URI removeUri = new URI(CONTAINERS_URL + "/e90e34656806"); given(http().delete(removeUri)).willReturn(emptyResponse()); this.api.remove(reference, false); - verify(http()).delete(removeUri); + then(http()).should().delete(removeUri); } @Test @@ -513,7 +513,7 @@ class DockerApiTests { URI removeUri = new URI(CONTAINERS_URL + "/e90e34656806?force=1"); given(http().delete(removeUri)).willReturn(emptyResponse()); this.api.remove(reference, true); - verify(http()).delete(removeUri); + then(http()).should().delete(removeUri); } } @@ -540,7 +540,7 @@ class DockerApiTests { URI removeUri = new URI(VOLUMES_URL + "/test"); given(http().delete(removeUri)).willReturn(emptyResponse()); this.api.delete(name, false); - verify(http()).delete(removeUri); + then(http()).should().delete(removeUri); } @Test @@ -549,7 +549,7 @@ class DockerApiTests { URI removeUri = new URI(VOLUMES_URL + "/test?force=1"); given(http().delete(removeUri)).willReturn(emptyResponse()); this.api.delete(name, true); - verify(http()).delete(removeUri); + then(http()).should().delete(removeUri); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransportTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransportTests.java index 13587e1351..397aa5194c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransportTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link HttpClientTransport}. @@ -103,7 +103,7 @@ class HttpClientTransportTests { given(this.entity.getContent()).willReturn(this.content); given(this.statusLine.getStatusCode()).willReturn(200); Response response = this.http.get(this.uri); - verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture()); + then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture()); HttpUriRequest request = this.requestCaptor.getValue(); assertThat(request).isInstanceOf(HttpGet.class); assertThat(request.getURI()).isEqualTo(this.uri); @@ -117,7 +117,7 @@ class HttpClientTransportTests { given(this.entity.getContent()).willReturn(this.content); given(this.statusLine.getStatusCode()).willReturn(200); Response response = this.http.post(this.uri); - verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture()); + then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture()); HttpUriRequest request = this.requestCaptor.getValue(); assertThat(request).isInstanceOf(HttpPost.class); assertThat(request.getURI()).isEqualTo(this.uri); @@ -132,7 +132,7 @@ class HttpClientTransportTests { given(this.entity.getContent()).willReturn(this.content); given(this.statusLine.getStatusCode()).willReturn(200); Response response = this.http.post(this.uri, "auth token"); - verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture()); + then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture()); HttpUriRequest request = this.requestCaptor.getValue(); assertThat(request).isInstanceOf(HttpPost.class); assertThat(request.getURI()).isEqualTo(this.uri); @@ -147,7 +147,7 @@ class HttpClientTransportTests { given(this.entity.getContent()).willReturn(this.content); given(this.statusLine.getStatusCode()).willReturn(200); Response response = this.http.post(this.uri, ""); - verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture()); + then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture()); HttpUriRequest request = this.requestCaptor.getValue(); assertThat(request).isInstanceOf(HttpPost.class); assertThat(request.getURI()).isEqualTo(this.uri); @@ -164,7 +164,7 @@ class HttpClientTransportTests { given(this.statusLine.getStatusCode()).willReturn(200); Response response = this.http.post(this.uri, APPLICATION_JSON, (out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out)); - verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture()); + then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture()); HttpUriRequest request = this.requestCaptor.getValue(); HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); assertThat(request).isInstanceOf(HttpPost.class); @@ -186,7 +186,7 @@ class HttpClientTransportTests { given(this.statusLine.getStatusCode()).willReturn(200); Response response = this.http.post(this.uri, APPLICATION_X_TAR, (out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out)); - verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture()); + then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture()); HttpUriRequest request = this.requestCaptor.getValue(); HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); assertThat(request).isInstanceOf(HttpPost.class); @@ -208,7 +208,7 @@ class HttpClientTransportTests { given(this.statusLine.getStatusCode()).willReturn(200); Response response = this.http.put(this.uri, APPLICATION_JSON, (out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out)); - verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture()); + then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture()); HttpUriRequest request = this.requestCaptor.getValue(); HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); assertThat(request).isInstanceOf(HttpPut.class); @@ -230,7 +230,7 @@ class HttpClientTransportTests { given(this.statusLine.getStatusCode()).willReturn(200); Response response = this.http.put(this.uri, APPLICATION_X_TAR, (out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out)); - verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture()); + then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture()); HttpUriRequest request = this.requestCaptor.getValue(); HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); assertThat(request).isInstanceOf(HttpPut.class); @@ -250,7 +250,7 @@ class HttpClientTransportTests { given(this.entity.getContent()).willReturn(this.content); given(this.statusLine.getStatusCode()).willReturn(200); Response response = this.http.delete(this.uri); - verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture()); + then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture()); HttpUriRequest request = this.requestCaptor.getValue(); assertThat(request).isInstanceOf(HttpDelete.class); assertThat(request.getURI()).isEqualTo(this.uri); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java index d57eed273c..4363d5abc5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,8 +64,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIOException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Tests for {@link JarFile}. @@ -243,7 +243,7 @@ class JarFileTests { RandomAccessDataFile randomAccessDataFile = spy(new RandomAccessDataFile(this.rootJarFile)); JarFile jarFile = new JarFile(randomAccessDataFile); jarFile.close(); - verify(randomAccessDataFile).close(); + then(randomAccessDataFile).should().close(); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java index bc8cd7bb1a..1e4eceed03 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,9 +42,9 @@ import org.springframework.boot.loader.tools.LibraryScope; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link ArtifactsLibraries}. @@ -85,7 +85,7 @@ class ArtifactsLibrariesTests { given(this.artifact.getArtifactHandler()).willReturn(this.artifactHandler); given(this.artifact.getScope()).willReturn("compile"); this.libs.doWithLibraries(this.callback); - verify(this.callback).library(this.libraryCaptor.capture()); + then(this.callback).should().library(this.libraryCaptor.capture()); Library library = this.libraryCaptor.getValue(); assertThat(library.getFile()).isEqualTo(this.file); assertThat(library.getScope()).isEqualTo(LibraryScope.COMPILE); @@ -105,7 +105,7 @@ class ArtifactsLibrariesTests { this.libs = new ArtifactsLibraries(this.artifacts, Collections.emptyList(), Collections.singleton(unpack), mock(Log.class)); this.libs.doWithLibraries(this.callback); - verify(this.callback).library(this.libraryCaptor.capture()); + then(this.callback).should().library(this.libraryCaptor.capture()); assertThat(this.libraryCaptor.getValue().isUnpackRequired()).isTrue(); } @@ -128,7 +128,7 @@ class ArtifactsLibrariesTests { this.artifacts = new LinkedHashSet<>(Arrays.asList(artifact1, artifact2)); this.libs = new ArtifactsLibraries(this.artifacts, Collections.emptyList(), null, mock(Log.class)); this.libs.doWithLibraries(this.callback); - verify(this.callback, times(2)).library(this.libraryCaptor.capture()); + then(this.callback).should(times(2)).library(this.libraryCaptor.capture()); assertThat(this.libraryCaptor.getAllValues().get(0).getName()).isEqualTo("g1-artifact-1.0.jar"); assertThat(this.libraryCaptor.getAllValues().get(1).getName()).isEqualTo("g2-artifact-1.0.jar"); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/BannerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/BannerTests.java index fe4d18a7f8..4c39c3f8da 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/BannerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/BannerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,9 @@ import org.springframework.core.env.Environment; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.verify; /** * Tests for {@link Banner} and its usage by {@link SpringApplication}. @@ -98,10 +98,11 @@ class BannerTests { this.context = application.run(); Banner printedBanner = (Banner) this.context.getBean("springBootBanner"); assertThat(printedBanner).hasFieldOrPropertyWithValue("banner", banner); - verify(banner).printBanner(any(Environment.class), this.sourceClassCaptor.capture(), any(PrintStream.class)); + then(banner).should().printBanner(any(Environment.class), this.sourceClassCaptor.capture(), + any(PrintStream.class)); reset(banner); printedBanner.printBanner(this.context.getEnvironment(), null, System.out); - verify(banner).printBanner(any(Environment.class), eq(this.sourceClassCaptor.getValue()), + then(banner).should().printBanner(any(Environment.class), eq(this.sourceClassCaptor.getValue()), any(PrintStream.class)); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/DefaultPropertiesPropertySourceTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/DefaultPropertiesPropertySourceTests.java index 32a9492cfc..aac03ef012 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/DefaultPropertiesPropertySourceTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/DefaultPropertiesPropertySourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,8 +33,7 @@ import org.springframework.mock.env.MockEnvironment; import org.springframework.mock.env.MockPropertySource; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.BDDMockito.then; /** * Tests for {@link DefaultPropertiesPropertySource}. @@ -84,19 +83,19 @@ class DefaultPropertiesPropertySourceTests { @Test void ifNotEmptyWhenNullDoesNotCallAction() { DefaultPropertiesPropertySource.ifNotEmpty(null, this.action); - verifyNoInteractions(this.action); + then(this.action).shouldHaveNoInteractions(); } @Test void ifNotEmptyWhenEmptyDoesNotCallAction() { DefaultPropertiesPropertySource.ifNotEmpty(Collections.emptyMap(), this.action); - verifyNoInteractions(this.action); + then(this.action).shouldHaveNoInteractions(); } @Test void ifNotEmptyHasValueCallsAction() { DefaultPropertiesPropertySource.ifNotEmpty(Collections.singletonMap("spring", "boot"), this.action); - verify(this.action).accept(this.captor.capture()); + then(this.action).should().accept(this.captor.capture()); assertThat(this.captor.getValue().getProperty("spring")).isEqualTo("boot"); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index c292fc6ba3..6a4d6e5c07 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -126,14 +126,13 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockingDetails; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link SpringApplication}. @@ -272,7 +271,7 @@ class SpringApplicationTests { SpringApplication application = spy(new SpringApplication(ExampleConfig.class)); application.setWebApplicationType(WebApplicationType.NONE); this.context = application.run("--spring.main.banner-mode=log"); - verify(application, atLeastOnce()).setBannerMode(Banner.Mode.LOG); + then(application).should(atLeastOnce()).setBannerMode(Banner.Mode.LOG); assertThat(output).contains("o.s.b.SpringApplication"); } @@ -388,15 +387,16 @@ class SpringApplicationTests { application.addListeners(listener); this.context = application.run(); InOrder inOrder = Mockito.inOrder(listener); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationStartingEvent.class)); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationEnvironmentPreparedEvent.class)); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationContextInitializedEvent.class)); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationPreparedEvent.class)); - inOrder.verify(listener).onApplicationEvent(isA(ContextRefreshedEvent.class)); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationStartedEvent.class)); - inOrder.verify(listener).onApplicationEvent(argThat(isAvailabilityChangeEventWithState(LivenessState.CORRECT))); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationReadyEvent.class)); - inOrder.verify(listener) + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationStartingEvent.class)); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationEnvironmentPreparedEvent.class)); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationContextInitializedEvent.class)); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationPreparedEvent.class)); + then(listener).should(inOrder).onApplicationEvent(isA(ContextRefreshedEvent.class)); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationStartedEvent.class)); + then(listener).should(inOrder) + .onApplicationEvent(argThat(isAvailabilityChangeEventWithState(LivenessState.CORRECT))); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationReadyEvent.class)); + then(listener).should(inOrder) .onApplicationEvent(argThat(isAvailabilityChangeEventWithState(ReadinessState.ACCEPTING_TRAFFIC))); inOrder.verifyNoMoreInteractions(); } @@ -466,7 +466,7 @@ class SpringApplicationTests { ConfigurableEnvironment environment = new StandardEnvironment(); application.setEnvironment(environment); this.context = application.run(); - verify(application.getLoader()).setEnvironment(environment); + then(application.getLoader()).should().setEnvironment(environment); } @Test @@ -476,7 +476,7 @@ class SpringApplicationTests { ResourceLoader resourceLoader = new DefaultResourceLoader(); application.setResourceLoader(resourceLoader); this.context = application.run(); - verify(application.getLoader()).setResourceLoader(resourceLoader); + then(application.getLoader()).should().setResourceLoader(resourceLoader); } @Test @@ -484,7 +484,7 @@ class SpringApplicationTests { ResourceLoader resourceLoader = new DefaultResourceLoader(); TestSpringApplication application = new TestSpringApplication(resourceLoader, ExampleWebConfig.class); this.context = application.run(); - verify(application.getLoader()).setResourceLoader(resourceLoader); + then(application.getLoader()).should().setResourceLoader(resourceLoader); } @Test @@ -493,7 +493,7 @@ class SpringApplicationTests { BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator(); application.setBeanNameGenerator(beanNameGenerator); this.context = application.run(); - verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator); + then(application.getLoader()).should().setBeanNameGenerator(beanNameGenerator); Object actualGenerator = this.context.getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR); assertThat(actualGenerator).isSameAs(beanNameGenerator); } @@ -505,7 +505,7 @@ class SpringApplicationTests { BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator(); application.setBeanNameGenerator(beanNameGenerator); this.context = application.run(); - verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator); + then(application.getLoader()).should().setBeanNameGenerator(beanNameGenerator); Object actualGenerator = this.context.getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR); assertThat(actualGenerator).isSameAs(beanNameGenerator); } @@ -682,9 +682,9 @@ class SpringApplicationTests { willThrow(failure).given(runner).run(isA(ApplicationArguments.class)); application.addInitializers((context) -> context.getBeanFactory().registerSingleton("runner", runner)); assertThatIllegalStateException().isThrownBy(application::run).withCause(failure); - verify(listener).onApplicationEvent(isA(ApplicationStartedEvent.class)); - verify(listener).onApplicationEvent(isA(ApplicationFailedEvent.class)); - verify(listener, never()).onApplicationEvent(isA(ApplicationReadyEvent.class)); + then(listener).should().onApplicationEvent(isA(ApplicationStartedEvent.class)); + then(listener).should().onApplicationEvent(isA(ApplicationFailedEvent.class)); + then(listener).should(never()).onApplicationEvent(isA(ApplicationReadyEvent.class)); } @Test @@ -699,9 +699,9 @@ class SpringApplicationTests { willThrow(failure).given(runner).run(); application.addInitializers((context) -> context.getBeanFactory().registerSingleton("runner", runner)); assertThatIllegalStateException().isThrownBy(application::run).withCause(failure); - verify(listener).onApplicationEvent(isA(ApplicationStartedEvent.class)); - verify(listener).onApplicationEvent(isA(ApplicationFailedEvent.class)); - verify(listener, never()).onApplicationEvent(isA(ApplicationReadyEvent.class)); + then(listener).should().onApplicationEvent(isA(ApplicationStartedEvent.class)); + then(listener).should().onApplicationEvent(isA(ApplicationFailedEvent.class)); + then(listener).should(never()).onApplicationEvent(isA(ApplicationReadyEvent.class)); } @Test @@ -714,8 +714,8 @@ class SpringApplicationTests { RuntimeException failure = new RuntimeException(); willThrow(failure).given(listener).onApplicationEvent(isA(ApplicationReadyEvent.class)); assertThatExceptionOfType(RuntimeException.class).isThrownBy(application::run).isEqualTo(failure); - verify(listener).onApplicationEvent(isA(ApplicationReadyEvent.class)); - verify(listener, never()).onApplicationEvent(isA(ApplicationFailedEvent.class)); + then(listener).should().onApplicationEvent(isA(ApplicationReadyEvent.class)); + then(listener).should(never()).onApplicationEvent(isA(ApplicationFailedEvent.class)); } @Test @@ -730,8 +730,8 @@ class SpringApplicationTests { ExitStatusException failure = new ExitStatusException(); willThrow(failure).given(listener).onApplicationEvent(isA(ApplicationReadyEvent.class)); assertThatExceptionOfType(RuntimeException.class).isThrownBy(application::run); - verify(listener).onApplicationEvent(isA(ApplicationReadyEvent.class)); - verify(listener, never()).onApplicationEvent(isA(ApplicationFailedEvent.class)); + then(listener).should().onApplicationEvent(isA(ApplicationReadyEvent.class)); + then(listener).should(never()).onApplicationEvent(isA(ApplicationFailedEvent.class)); assertThat(exitCodeListener.getExitCode()).isEqualTo(11); assertThat(output).contains("Application run failed"); } @@ -804,7 +804,7 @@ class SpringApplicationTests { application.addListeners(listener); application.setWebApplicationType(WebApplicationType.NONE); assertThatIllegalStateException().isThrownBy(application::run); - verify(handler).registerExitCode(11); + then(handler).should().registerExitCode(11); assertThat(listener.getExitCode()).isEqualTo(11); } @@ -823,7 +823,7 @@ class SpringApplicationTests { application.addListeners(listener); application.setWebApplicationType(WebApplicationType.NONE); assertThatIllegalStateException().isThrownBy(application::run); - verify(handler).registerExitCode(11); + then(handler).should().registerExitCode(11); assertThat(listener.getExitCode()).isEqualTo(11); } @@ -843,7 +843,7 @@ class SpringApplicationTests { application.setWebApplicationType(WebApplicationType.NONE); assertThatExceptionOfType(RuntimeException.class).isThrownBy(application::run); ArgumentCaptor exceptionCaptor = ArgumentCaptor.forClass(RuntimeException.class); - verify(handler).registerLoggedException(exceptionCaptor.capture()); + then(handler).should().registerLoggedException(exceptionCaptor.capture()); assertThat(exceptionCaptor.getValue()).hasCauseInstanceOf(RefreshFailureException.class); assertThat(output).doesNotContain("NullPointerException"); } @@ -927,11 +927,12 @@ class SpringApplicationTests { ApplicationListener listener = this.context.getBean("testApplicationListener", ApplicationListener.class); InOrder inOrder = Mockito.inOrder(listener); - inOrder.verify(listener).onApplicationEvent(isA(ContextRefreshedEvent.class)); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationStartedEvent.class)); - inOrder.verify(listener).onApplicationEvent(argThat(isAvailabilityChangeEventWithState(LivenessState.CORRECT))); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationReadyEvent.class)); - inOrder.verify(listener) + then(listener).should(inOrder).onApplicationEvent(isA(ContextRefreshedEvent.class)); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationStartedEvent.class)); + then(listener).should(inOrder) + .onApplicationEvent(argThat(isAvailabilityChangeEventWithState(LivenessState.CORRECT))); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationReadyEvent.class)); + then(listener).should(inOrder) .onApplicationEvent(argThat(isAvailabilityChangeEventWithState(ReadinessState.ACCEPTING_TRAFFIC))); inOrder.verifyNoMoreInteractions(); } @@ -959,11 +960,11 @@ class SpringApplicationTests { private void verifyRegisteredListenerFailedFromApplicationEvents(ApplicationListener listener) { InOrder inOrder = Mockito.inOrder(listener); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationStartingEvent.class)); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationEnvironmentPreparedEvent.class)); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationContextInitializedEvent.class)); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationPreparedEvent.class)); - inOrder.verify(listener).onApplicationEvent(isA(ApplicationFailedEvent.class)); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationStartingEvent.class)); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationEnvironmentPreparedEvent.class)); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationContextInitializedEvent.class)); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationPreparedEvent.class)); + then(listener).should(inOrder).onApplicationEvent(isA(ApplicationFailedEvent.class)); inOrder.verifyNoMoreInteractions(); } @@ -974,8 +975,8 @@ class SpringApplicationTests { SpringApplication application = new SpringApplication(ExampleConfig.class); application.addInitializers((applicationContext) -> applicationContext.addApplicationListener(listener)); assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(application::run); - verify(listener).onApplicationEvent(isA(ApplicationFailedEvent.class)); - verifyNoMoreInteractions(listener); + then(listener).should().onApplicationEvent(isA(ApplicationFailedEvent.class)); + then(listener).shouldHaveNoMoreInteractions(); } @SuppressWarnings("unchecked") @@ -986,8 +987,8 @@ class SpringApplicationTests { application.setWebApplicationType(WebApplicationType.NONE); application.addInitializers((applicationContext) -> applicationContext.addApplicationListener(listener)); assertThatExceptionOfType(BeanCreationException.class).isThrownBy(application::run); - verify(listener).onApplicationEvent(isA(ApplicationFailedEvent.class)); - verifyNoMoreInteractions(listener); + then(listener).should().onApplicationEvent(isA(ApplicationFailedEvent.class)); + then(listener).shouldHaveNoMoreInteractions(); } @Test @@ -1168,12 +1169,12 @@ class SpringApplicationTests { application.setApplicationStartup(applicationStartup); this.context = application.run(); assertThat(this.context.getBean(ApplicationStartup.class)).isEqualTo(applicationStartup); - verify(applicationStartup).start("spring.boot.application.starting"); - verify(applicationStartup).start("spring.boot.application.environment-prepared"); - verify(applicationStartup).start("spring.boot.application.context-prepared"); - verify(applicationStartup).start("spring.boot.application.context-loaded"); - verify(applicationStartup).start("spring.boot.application.started"); - verify(applicationStartup).start("spring.boot.application.ready"); + then(applicationStartup).should().start("spring.boot.application.starting"); + then(applicationStartup).should().start("spring.boot.application.environment-prepared"); + then(applicationStartup).should().start("spring.boot.application.context-prepared"); + then(applicationStartup).should().start("spring.boot.application.context-loaded"); + then(applicationStartup).should().start("spring.boot.application.started"); + then(applicationStartup).should().start("spring.boot.application.ready"); long startCount = mockingDetails(applicationStartup).getInvocations().stream() .filter((invocation) -> invocation.getMethod().toString().contains("start(")).count(); long endCount = mockingDetails(startupStep).getInvocations().stream() @@ -1192,9 +1193,9 @@ class SpringApplicationTests { application.setWebApplicationType(WebApplicationType.NONE); application.setApplicationStartup(applicationStartup); assertThatExceptionOfType(BeanCreationException.class).isThrownBy(application::run); - verify(applicationStartup).start("spring.boot.application.starting"); - verify(applicationStartup).start("spring.boot.application.environment-prepared"); - verify(applicationStartup).start("spring.boot.application.failed"); + then(applicationStartup).should().start("spring.boot.application.starting"); + then(applicationStartup).should().start("spring.boot.application.environment-prepared"); + then(applicationStartup).should().start("spring.boot.application.failed"); long startCount = mockingDetails(applicationStartup).getInvocations().stream() .filter((invocation) -> invocation.getMethod().toString().contains("start(")).count(); long endCount = mockingDetails(startupStep).getInvocations().stream() diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTests.java index bd7a202a32..836809c1d6 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,8 @@ import java.lang.reflect.InvocationTargetException; import org.junit.jupiter.api.Test; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link SpringBootExceptionHandler}. @@ -43,7 +42,7 @@ class SpringBootExceptionHandlerTests { Exception ex = new Exception(); this.handler.registerLoggedException(ex); this.handler.uncaughtException(thread, ex); - verifyNoInteractions(this.parent); + then(this.parent).shouldHaveNoInteractions(); } @Test @@ -52,7 +51,7 @@ class SpringBootExceptionHandlerTests { Exception ex = new Exception("[stuff] Logback configuration error detected [stuff]"); this.handler.registerLoggedException(ex); this.handler.uncaughtException(thread, ex); - verify(this.parent).uncaughtException(thread, ex); + then(this.parent).should().uncaughtException(thread, ex); } @Test @@ -62,7 +61,7 @@ class SpringBootExceptionHandlerTests { new Exception("[stuff] Logback configuration error detected [stuff]", new Exception())); this.handler.registerLoggedException(ex); this.handler.uncaughtException(thread, ex); - verify(this.parent).uncaughtException(thread, ex); + then(this.parent).should().uncaughtException(thread, ex); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/StartupInfoLoggerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/StartupInfoLoggerTests.java index 3910168266..f3477ceb56 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/StartupInfoLoggerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/StartupInfoLoggerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import org.springframework.boot.system.ApplicationPid; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link StartupInfoLogger}. @@ -46,7 +46,7 @@ class StartupInfoLoggerTests { given(this.log.isInfoEnabled()).willReturn(true); new StartupInfoLogger(getClass()).logStarting(this.log); ArgumentCaptor captor = ArgumentCaptor.forClass(Object.class); - verify(this.log).info(captor.capture()); + then(this.log).should().info(captor.capture()); assertThat(captor.getValue().toString()).contains("Starting " + getClass().getSimpleName() + " using Java " + System.getProperty("java.version") + " on " + InetAddress.getLocalHost().getHostName() + " with PID " + new ApplicationPid() + " (started by " + System.getProperty("user.name") + " in " @@ -59,7 +59,7 @@ class StartupInfoLoggerTests { Duration timeTakenToStartup = Duration.ofMillis(10); new StartupInfoLogger(getClass()).logStarted(this.log, timeTakenToStartup); ArgumentCaptor captor = ArgumentCaptor.forClass(Object.class); - verify(this.log).info(captor.capture()); + then(this.log).should().info(captor.capture()); assertThat(captor.getValue().toString()).matches("Started " + getClass().getSimpleName() + " in \\d+\\.\\d{1,3} seconds \\(JVM running for \\d+\\.\\d{1,3}\\)"); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/availability/AvailabilityChangeEventTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/availability/AvailabilityChangeEventTests.java index feaa35d17a..f1527bfcbe 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/availability/AvailabilityChangeEventTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/availability/AvailabilityChangeEventTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import org.springframework.core.ResolvableType; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link AvailabilityChangeEvent}. @@ -77,7 +77,7 @@ class AvailabilityChangeEventTests { AvailabilityState state = LivenessState.CORRECT; AvailabilityChangeEvent.publish(context, state); ArgumentCaptor captor = ArgumentCaptor.forClass(ApplicationEvent.class); - verify(context).publishEvent(captor.capture()); + then(context).should().publishEvent(captor.capture()); AvailabilityChangeEvent event = (AvailabilityChangeEvent) captor.getValue(); assertThat(event.getSource()).isEqualTo(context); assertThat(event.getState()).isEqualTo(state); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java index 3e3f889902..a91e5d0332 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,9 +43,9 @@ import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Tests for {@link SpringApplicationBuilder}. @@ -127,7 +127,8 @@ class SpringApplicationBuilderTests { .contextFactory(ApplicationContextFactory.ofContextClass(SpyApplicationContext.class)); application.parent(ExampleConfig.class); this.context = application.run("foo.bar=baz"); - verify(((SpyApplicationContext) this.context).getApplicationContext()).setParent(any(ApplicationContext.class)); + then(((SpyApplicationContext) this.context).getApplicationContext()).should() + .setParent(any(ApplicationContext.class)); assertThat(SpringApplicationShutdownHookInstance.get()).didNotRegisterApplicationContext(this.context); assertThat(this.context.getParent().getBean(ApplicationArguments.class).getNonOptionArgs()) .contains("foo.bar=baz"); @@ -140,7 +141,8 @@ class SpringApplicationBuilderTests { .contextFactory(ApplicationContextFactory.ofContextClass(SpyApplicationContext.class)); application.parent(ExampleConfig.class); this.context = application.build("a=alpha").run("b=bravo"); - verify(((SpyApplicationContext) this.context).getApplicationContext()).setParent(any(ApplicationContext.class)); + then(((SpyApplicationContext) this.context).getApplicationContext()).should() + .setParent(any(ApplicationContext.class)); assertThat(SpringApplicationShutdownHookInstance.get()).didNotRegisterApplicationContext(this.context); assertThat(this.context.getParent().getBean(ApplicationArguments.class).getNonOptionArgs()).contains("a=alpha"); assertThat(this.context.getBean(ApplicationArguments.class).getNonOptionArgs()).contains("b=bravo"); @@ -153,7 +155,8 @@ class SpringApplicationBuilderTests { .registerShutdownHook(true); application.parent(ExampleConfig.class); this.context = application.run(); - verify(((SpyApplicationContext) this.context).getApplicationContext()).setParent(any(ApplicationContext.class)); + then(((SpyApplicationContext) this.context).getApplicationContext()).should() + .setParent(any(ApplicationContext.class)); assertThat(SpringApplicationShutdownHookInstance.get()).registeredApplicationContext(this.context); } @@ -184,7 +187,8 @@ class SpringApplicationBuilderTests { .child(ChildConfig.class); application.contextFactory(ApplicationContextFactory.ofContextClass(SpyApplicationContext.class)); this.context = application.run(); - verify(((SpyApplicationContext) this.context).getApplicationContext()).setParent(any(ApplicationContext.class)); + then(((SpyApplicationContext) this.context).getApplicationContext()).should() + .setParent(any(ApplicationContext.class)); assertThat(SpringApplicationShutdownHookInstance.get()).didNotRegisterApplicationContext(this.context); } @@ -241,7 +245,8 @@ class SpringApplicationBuilderTests { application.parent(ExampleConfig.class); application.contextFactory(ApplicationContextFactory.ofContextClass(SpyApplicationContext.class)); this.context = application.run(); - verify(((SpyApplicationContext) this.context).getApplicationContext()).setParent(any(ApplicationContext.class)); + then(((SpyApplicationContext) this.context).getApplicationContext()).should() + .setParent(any(ApplicationContext.class)); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributorsTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributorsTests.java index 0b9eb4402b..53fabcdacc 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributorsTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributorsTests.java @@ -47,8 +47,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link ConfigDataEnvironmentContributors}. @@ -185,7 +185,7 @@ class ConfigDataEnvironmentContributorsTests { ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory, this.bootstrapContext, Arrays.asList(existingContributor, contributor)); contributors.withProcessedImports(this.importer, this.activationContext); - verify(this.importer).resolveAndLoad(any(), this.locationResolverContext.capture(), any(), any()); + then(this.importer).should().resolveAndLoad(any(), this.locationResolverContext.capture(), any(), any()); ConfigDataLocationResolverContext context = this.locationResolverContext.getValue(); assertThat(context.getBinder().bind("test", String.class).get()).isEqualTo("springboot"); } @@ -212,7 +212,8 @@ class ConfigDataEnvironmentContributorsTests { ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory, this.bootstrapContext, Arrays.asList(contributor)); contributors.withProcessedImports(this.importer, this.activationContext); - verify(this.importer).resolveAndLoad(any(), this.locationResolverContext.capture(), any(), eq(secondLocations)); + then(this.importer).should().resolveAndLoad(any(), this.locationResolverContext.capture(), any(), + eq(secondLocations)); ConfigDataLocationResolverContext context = this.locationResolverContext.getValue(); assertThat(context.getParent()).hasToString("a"); } @@ -235,7 +236,7 @@ class ConfigDataEnvironmentContributorsTests { ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory, this.bootstrapContext, Arrays.asList(existingContributor, contributor)); contributors.withProcessedImports(this.importer, this.activationContext); - verify(this.importer).resolveAndLoad(any(), this.locationResolverContext.capture(), any(), any()); + then(this.importer).should().resolveAndLoad(any(), this.locationResolverContext.capture(), any(), any()); ConfigDataLocationResolverContext context = this.locationResolverContext.getValue(); assertThat(context.getBootstrapContext()).isSameAs(this.bootstrapContext); } @@ -258,7 +259,7 @@ class ConfigDataEnvironmentContributorsTests { ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory, this.bootstrapContext, Arrays.asList(existingContributor, contributor)); contributors.withProcessedImports(this.importer, this.activationContext); - verify(this.importer).resolveAndLoad(any(), any(), this.loaderContext.capture(), any()); + then(this.importer).should().resolveAndLoad(any(), any(), this.loaderContext.capture(), any()); ConfigDataLoaderContext context = this.loaderContext.getValue(); assertThat(context.getBootstrapContext()).isSameAs(this.bootstrapContext); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorTests.java index 585e0dd84a..a449df1318 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,11 +37,10 @@ import org.springframework.core.io.ResourceLoader; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willReturn; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link ConfigDataEnvironmentPostProcessor}. @@ -80,8 +79,8 @@ class ConfigDataEnvironmentPostProcessorTests { void postProcessEnvironmentWhenNoLoaderCreatesDefaultLoaderInstance() { willReturn(this.configDataEnvironment).given(this.postProcessor).getConfigDataEnvironment(any(), any(), any()); this.postProcessor.postProcessEnvironment(this.environment, this.application); - verify(this.postProcessor).getConfigDataEnvironment(any(), this.resourceLoaderCaptor.capture(), any()); - verify(this.configDataEnvironment).processAndApply(); + then(this.postProcessor).should().getConfigDataEnvironment(any(), this.resourceLoaderCaptor.capture(), any()); + then(this.configDataEnvironment).should().processAndApply(); assertThat(this.resourceLoaderCaptor.getValue()).isInstanceOf(DefaultResourceLoader.class); } @@ -91,8 +90,8 @@ class ConfigDataEnvironmentPostProcessorTests { this.application.setResourceLoader(resourceLoader); willReturn(this.configDataEnvironment).given(this.postProcessor).getConfigDataEnvironment(any(), any(), any()); this.postProcessor.postProcessEnvironment(this.environment, this.application); - verify(this.postProcessor).getConfigDataEnvironment(any(), this.resourceLoaderCaptor.capture(), any()); - verify(this.configDataEnvironment).processAndApply(); + then(this.postProcessor).should().getConfigDataEnvironment(any(), this.resourceLoaderCaptor.capture(), any()); + then(this.configDataEnvironment).should().processAndApply(); assertThat(this.resourceLoaderCaptor.getValue()).isSameAs(resourceLoader); } @@ -101,8 +100,9 @@ class ConfigDataEnvironmentPostProcessorTests { this.application.setAdditionalProfiles("dev"); willReturn(this.configDataEnvironment).given(this.postProcessor).getConfigDataEnvironment(any(), any(), any()); this.postProcessor.postProcessEnvironment(this.environment, this.application); - verify(this.postProcessor).getConfigDataEnvironment(any(), any(), this.additionalProfilesCaptor.capture()); - verify(this.configDataEnvironment).processAndApply(); + then(this.postProcessor).should().getConfigDataEnvironment(any(), any(), + this.additionalProfilesCaptor.capture()); + then(this.configDataEnvironment).should().processAndApply(); assertThat(this.additionalProfilesCaptor.getValue()).containsExactly("dev"); } @@ -110,8 +110,8 @@ class ConfigDataEnvironmentPostProcessorTests { void postProcessEnvironmentWhenNoActiveProfiles() { willReturn(this.configDataEnvironment).given(this.postProcessor).getConfigDataEnvironment(any(), any(), any()); this.postProcessor.postProcessEnvironment(this.environment, this.application); - verify(this.postProcessor).getConfigDataEnvironment(any(), this.resourceLoaderCaptor.capture(), any()); - verify(this.configDataEnvironment).processAndApply(); + then(this.postProcessor).should().getConfigDataEnvironment(any(), this.resourceLoaderCaptor.capture(), any()); + then(this.configDataEnvironment).should().processAndApply(); assertThat(this.environment.getActiveProfiles()).isEmpty(); } @@ -123,8 +123,8 @@ class ConfigDataEnvironmentPostProcessorTests { .getConfigDataEnvironment(any(), any(), any()); willReturn(legacyListener).given(this.postProcessor).getLegacyListener(); this.postProcessor.postProcessEnvironment(this.environment, this.application); - verifyNoInteractions(this.configDataEnvironment); - verify(legacyListener).addPropertySources(eq(this.environment), any(DefaultResourceLoader.class)); + then(this.configDataEnvironment).shouldHaveNoInteractions(); + then(legacyListener).should().addPropertySources(eq(this.environment), any(DefaultResourceLoader.class)); assertThat(this.environment.getActiveProfiles()).isEmpty(); } @@ -137,8 +137,8 @@ class ConfigDataEnvironmentPostProcessorTests { .getConfigDataEnvironment(any(), any(), any()); willReturn(legacyListener).given(this.postProcessor).getLegacyListener(); this.postProcessor.postProcessEnvironment(this.environment, this.application); - verifyNoInteractions(this.configDataEnvironment); - verify(legacyListener).addPropertySources(eq(this.environment), any(DefaultResourceLoader.class)); + then(this.configDataEnvironment).shouldHaveNoInteractions(); + then(legacyListener).should().addPropertySources(eq(this.environment), any(DefaultResourceLoader.class)); assertThat(this.environment.getActiveProfiles()).containsExactly("dev"); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/InvalidConfigDataPropertyExceptionTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/InvalidConfigDataPropertyExceptionTests.java index 2f3cafd149..8612104b02 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/InvalidConfigDataPropertyExceptionTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/InvalidConfigDataPropertyExceptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,8 @@ import org.springframework.mock.env.MockPropertySource; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link InvalidConfigDataPropertyException}. @@ -162,7 +162,7 @@ class InvalidConfigDataPropertyExceptionTests { propertySource.setProperty("spring.profiles", "a"); ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofExisting(propertySource); InvalidConfigDataPropertyException.throwOrWarn(this.logger, contributor); - verify(this.logger).warn("Property 'spring.profiles' is invalid and should be replaced with " + then(this.logger).should().warn("Property 'spring.profiles' is invalid and should be replaced with " + "'spring.config.activate.on-profile' [origin: \"spring.profiles\" from property source \"mockProperties\"]"); } @@ -172,7 +172,7 @@ class InvalidConfigDataPropertyExceptionTests { propertySource.setProperty("spring.profiles[0]", "a"); ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofExisting(propertySource); InvalidConfigDataPropertyException.throwOrWarn(this.logger, contributor); - verify(this.logger).warn("Property 'spring.profiles[0]' is invalid and should be replaced with " + then(this.logger).should().warn("Property 'spring.profiles[0]' is invalid and should be replaced with " + "'spring.config.activate.on-profile' [origin: \"spring.profiles[0]\" from property source \"mockProperties\"]"); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java index 07dd481234..b97fb459e6 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,8 +105,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link ConfigurationProperties @ConfigurationProperties}-annotated beans. @@ -620,7 +620,7 @@ class ConfigurationPropertiesTests { this.context.addProtocolResolver(protocolResolver); this.context.register(PropertiesWithResource.class); this.context.refresh(); - verify(protocolResolver).resolve(eq("application.properties"), any(ResourceLoader.class)); + then(protocolResolver).should().resolve(eq("application.properties"), any(ResourceLoader.class)); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesRegistrarTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesRegistrarTests.java index 32208fec83..571fc63960 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesRegistrarTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesRegistrarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,9 +31,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link EnableConfigurationPropertiesRegistrar}. @@ -88,7 +87,7 @@ class EnableConfigurationPropertiesRegistrarTests { void registrationWithDuplicatedTypeShouldRegisterSingleBeanDefinition() { register(DuplicateConfiguration.class); String name = "foo-" + getClass().getName() + "$FooProperties"; - verify(this.beanFactory, times(1)).registerBeanDefinition(eq(name), any()); + then(this.beanFactory).should().registerBeanDefinition(eq(name), any()); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BindConverterTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BindConverterTests.java index 7115c31c32..7ee4fb899a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BindConverterTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BindConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ import org.springframework.core.convert.support.GenericConversionService; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link BindConverter}. @@ -63,7 +63,7 @@ class BindConverterTests { @Test void createWhenPropertyEditorInitializerIsNotNullShouldUseToInitialize() { BindConverter.get(null, this.propertyEditorInitializer); - verify(this.propertyEditorInitializer).accept(any(PropertyEditorRegistry.class)); + then(this.propertyEditorInitializer).should().accept(any(PropertyEditorRegistry.class)); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BindResultTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BindResultTests.java index 46784450c2..3e744ad15a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BindResultTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BindResultTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIOException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.BDDMockito.then; /** * Tests for {@link BindResult}. @@ -89,14 +88,14 @@ class BindResultTests { void ifBoundWhenHasValueShouldCallConsumer() { BindResult result = BindResult.of("foo"); result.ifBound(this.consumer); - verify(this.consumer).accept("foo"); + then(this.consumer).should().accept("foo"); } @Test void ifBoundWhenHasNoValueShouldNotCallConsumer() { BindResult result = BindResult.of(null); result.ifBound(this.consumer); - verifyNoInteractions(this.consumer); + then(this.consumer).shouldHaveNoInteractions(); } @Test @@ -117,7 +116,7 @@ class BindResultTests { void mapWhenHasNoValueShouldNotCallMapper() { BindResult result = BindResult.of(null); result.map(this.mapper); - verifyNoInteractions(this.mapper); + then(this.mapper).shouldHaveNoInteractions(); } @Test @@ -136,7 +135,7 @@ class BindResultTests { void orElseGetWhenHasValueShouldReturnValue() { BindResult result = BindResult.of("foo"); assertThat(result.orElseGet(this.supplier)).isEqualTo("foo"); - verifyNoInteractions(this.supplier); + then(this.supplier).shouldHaveNoInteractions(); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BoundPropertiesTrackingBindHandlerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BoundPropertiesTrackingBindHandlerTests.java index 6716785908..93116d2af3 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BoundPropertiesTrackingBindHandlerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BoundPropertiesTrackingBindHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,9 +31,8 @@ import org.springframework.boot.context.properties.source.ConfigurationPropertyS import org.springframework.boot.context.properties.source.MockConfigurationPropertySource; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link BoundPropertiesTrackingBindHandler}. @@ -62,8 +61,8 @@ class BoundPropertiesTrackingBindHandlerTests { void handlerShouldCallRecordBindingIfConfigurationPropertyIsNotNull() { this.sources.add(new MockConfigurationPropertySource("foo.age", 4)); this.binder.bind("foo", Bindable.of(ExampleBean.class), this.handler); - verify(this.consumer, times(1)).accept(any(ConfigurationProperty.class)); - verify(this.consumer, never()).accept(null); + then(this.consumer).should().accept(any(ConfigurationProperty.class)); + then(this.consumer).should(never()).accept(null); } static class ExampleBean { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertySourcesCachingTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertySourcesCachingTests.java index 73aff6f7b4..1e747e4e0e 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertySourcesCachingTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertySourcesCachingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.withSettings; /** @@ -62,8 +62,8 @@ class ConfigurationPropertySourcesCachingTests { @Test void enableDelegatesToCachingConfigurationPropertySources() { this.caching.enable(); - verify(getCaching(0)).enable(); - verify(getCaching(2)).enable(); + then(getCaching(0)).should().enable(); + then(getCaching(2)).should().enable(); } @Test @@ -74,8 +74,8 @@ class ConfigurationPropertySourcesCachingTests { @Test void disableDelegatesToCachingConfigurationPropertySources() { this.caching.disable(); - verify(getCaching(0)).disable(); - verify(getCaching(2)).disable(); + then(getCaching(0)).should().disable(); + then(getCaching(2)).should().disable(); } @Test @@ -87,8 +87,8 @@ class ConfigurationPropertySourcesCachingTests { void setTimeToLiveDelegatesToCachingConfigurationPropertySources() { Duration ttl = Duration.ofDays(1); this.caching.setTimeToLive(ttl); - verify(getCaching(0)).setTimeToLive(ttl); - verify(getCaching(2)).setTimeToLive(ttl); + then(getCaching(0)).should().setTimeToLive(ttl); + then(getCaching(2)).should().setTimeToLive(ttl); } @Test @@ -99,8 +99,8 @@ class ConfigurationPropertySourcesCachingTests { @Test void clearDelegatesToCachingConfigurationPropertySources() { this.caching.clear(); - verify(getCaching(0)).clear(); - verify(getCaching(2)).clear(); + then(getCaching(0)).should().clear(); + then(getCaching(2)).should().clear(); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/ApplicationConversionServiceTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/ApplicationConversionServiceTests.java index 1599587f95..5fe5d23261 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/ApplicationConversionServiceTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/ApplicationConversionServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,9 +36,8 @@ import org.springframework.format.Printer; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link ApplicationConversionService}. @@ -54,8 +53,8 @@ class ApplicationConversionServiceTests { try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( ExampleGenericConverter.class)) { ApplicationConversionService.addBeans(this.registry, context); - verify(this.registry).addConverter(context.getBean(ExampleGenericConverter.class)); - verifyNoMoreInteractions(this.registry); + then(this.registry).should().addConverter(context.getBean(ExampleGenericConverter.class)); + then(this.registry).shouldHaveNoMoreInteractions(); } } @@ -63,8 +62,8 @@ class ApplicationConversionServiceTests { void addBeansWhenHasConverterBeanAddConverter() { try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ExampleConverter.class)) { ApplicationConversionService.addBeans(this.registry, context); - verify(this.registry).addConverter(context.getBean(ExampleConverter.class)); - verifyNoMoreInteractions(this.registry); + then(this.registry).should().addConverter(context.getBean(ExampleConverter.class)); + then(this.registry).shouldHaveNoMoreInteractions(); } } @@ -72,8 +71,8 @@ class ApplicationConversionServiceTests { void addBeansWhenHasFormatterBeanAddsOnlyFormatter() { try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ExampleFormatter.class)) { ApplicationConversionService.addBeans(this.registry, context); - verify(this.registry).addFormatter(context.getBean(ExampleFormatter.class)); - verifyNoMoreInteractions(this.registry); + then(this.registry).should().addFormatter(context.getBean(ExampleFormatter.class)); + then(this.registry).shouldHaveNoMoreInteractions(); } } @@ -81,8 +80,8 @@ class ApplicationConversionServiceTests { void addBeansWhenHasPrinterBeanAddPrinter() { try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ExamplePrinter.class)) { ApplicationConversionService.addBeans(this.registry, context); - verify(this.registry).addPrinter(context.getBean(ExamplePrinter.class)); - verifyNoMoreInteractions(this.registry); + then(this.registry).should().addPrinter(context.getBean(ExamplePrinter.class)); + then(this.registry).shouldHaveNoMoreInteractions(); } } @@ -90,8 +89,8 @@ class ApplicationConversionServiceTests { void addBeansWhenHasParserBeanAddParser() { try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ExampleParser.class)) { ApplicationConversionService.addBeans(this.registry, context); - verify(this.registry).addParser(context.getBean(ExampleParser.class)); - verifyNoMoreInteractions(this.registry); + then(this.registry).should().addParser(context.getBean(ExampleParser.class)); + then(this.registry).shouldHaveNoMoreInteractions(); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java index 458f61629d..8fae3980fd 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +30,9 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.core.env.Environment; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link FailureAnalyzers}. @@ -53,42 +53,42 @@ class FailureAnalyzersTests { void analyzersAreLoadedAndCalled() { RuntimeException failure = new RuntimeException(); analyzeAndReport("basic.factories", failure); - verify(failureAnalyzer, times(2)).analyze(failure); + then(failureAnalyzer).should(times(2)).analyze(failure); } @Test void beanFactoryIsInjectedIntoBeanFactoryAwareFailureAnalyzers() { RuntimeException failure = new RuntimeException(); analyzeAndReport("basic.factories", failure); - verify(failureAnalyzer).setBeanFactory(any(BeanFactory.class)); + then(failureAnalyzer).should().setBeanFactory(any(BeanFactory.class)); } @Test void environmentIsInjectedIntoEnvironmentAwareFailureAnalyzers() { RuntimeException failure = new RuntimeException(); analyzeAndReport("basic.factories", failure); - verify(failureAnalyzer).setEnvironment(any(Environment.class)); + then(failureAnalyzer).should().setEnvironment(any(Environment.class)); } @Test void analyzerThatFailsDuringInitializationDoesNotPreventOtherAnalyzersFromBeingCalled() { RuntimeException failure = new RuntimeException(); analyzeAndReport("broken-initialization.factories", failure); - verify(failureAnalyzer, times(1)).analyze(failure); + then(failureAnalyzer).should().analyze(failure); } @Test void analyzerThatFailsDuringAnalysisDoesNotPreventOtherAnalyzersFromBeingCalled() { RuntimeException failure = new RuntimeException(); analyzeAndReport("broken-analysis.factories", failure); - verify(failureAnalyzer, times(1)).analyze(failure); + then(failureAnalyzer).should().analyze(failure); } @Test void createWithNullContextSkipsAwareAnalyzers() { RuntimeException failure = new RuntimeException(); analyzeAndReport("basic.factories", failure, null); - verify(failureAnalyzer, times(1)).analyze(failure); + then(failureAnalyzer).should().analyze(failure); } private void analyzeAndReport(String factoriesName, Throwable failure) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorApplicationListenerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorApplicationListenerTests.java index 2d2db32616..cd17935818 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorApplicationListenerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorApplicationListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,9 +34,9 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Tests for {@link EnvironmentPostProcessorApplicationListener}. @@ -105,7 +105,7 @@ class EnvironmentPostProcessorApplicationListenerTests { ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class); ApplicationPreparedEvent event = new ApplicationPreparedEvent(application, new String[0], context); this.listener.onApplicationEvent(event); - verify(this.deferredLogs).switchOverAll(); + then(this.deferredLogs).should().switchOverAll(); } @Test @@ -115,7 +115,7 @@ class EnvironmentPostProcessorApplicationListenerTests { ApplicationFailedEvent event = new ApplicationFailedEvent(application, new String[0], context, new RuntimeException()); this.listener.onApplicationEvent(event); - verify(this.deferredLogs).switchOverAll(); + then(this.deferredLogs).should().switchOverAll(); } static class TestEnvironmentPostProcessor implements EnvironmentPostProcessor { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceUnwrapperTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceUnwrapperTests.java index c2173351e9..0f93285fdd 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceUnwrapperTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceUnwrapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,8 @@ import org.springframework.jdbc.datasource.SingleConnectionDataSource; import org.springframework.jdbc.datasource.SmartDataSource; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link DataSourceUnwrapper}. @@ -102,15 +101,15 @@ class DataSourceUnwrapperTests { void unwrappingIsNotAttemptedWhenTargetIsNotAnInterface() { DataSource dataSource = mock(DataSource.class); assertThat(DataSourceUnwrapper.unwrap(dataSource, HikariDataSource.class)).isNull(); - verifyNoMoreInteractions(dataSource); + then(dataSource).shouldHaveNoMoreInteractions(); } @Test void unwrappingIsNotAttemptedWhenDataSourceIsNotWrapperForTarget() throws SQLException { DataSource dataSource = mock(DataSource.class); assertThat(DataSourceUnwrapper.unwrap(dataSource, Consumer.class)).isNull(); - verify(dataSource).isWrapperFor(Consumer.class); - verifyNoMoreInteractions(dataSource); + then(dataSource).should().isWrapperFor(Consumer.class); + then(dataSource).shouldHaveNoMoreInteractions(); } private DataSource wrapInProxy(DataSource dataSource) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/json/JacksonJsonParserTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/json/JacksonJsonParserTests.java index f7d5af24e6..c259f2ae06 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/json/JacksonJsonParserTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/json/JacksonJsonParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,8 @@ import org.junit.jupiter.api.Test; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Tests for {@link JacksonJsonParser}. @@ -45,7 +45,7 @@ class JacksonJsonParserTests extends AbstractJsonParserTests { void instanceWithSpecificObjectMapper() throws IOException { ObjectMapper objectMapper = spy(new ObjectMapper()); new JacksonJsonParser(objectMapper).parseMap("{}"); - verify(objectMapper).readValue(eq("{}"), any(TypeReference.class)); + then(objectMapper).should().readValue(eq("{}"), any(TypeReference.class)); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosConnectionFactoryBeanTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosConnectionFactoryBeanTests.java index 0f9d348416..6babbc0aa7 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosConnectionFactoryBeanTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosConnectionFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ package org.springframework.boot.jta.atomikos; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Tests for {@link AtomikosConnectionFactoryBean}. @@ -36,10 +36,10 @@ class AtomikosConnectionFactoryBeanTests { bean.setBeanName("bean"); bean.afterPropertiesSet(); assertThat(bean.getUniqueResourceName()).isEqualTo("bean"); - verify(bean).init(); - verify(bean, never()).close(); + then(bean).should().init(); + then(bean).should(never()).close(); bean.destroy(); - verify(bean).close(); + then(bean).should().close(); } static class MockAtomikosConnectionFactoryBean extends AtomikosConnectionFactoryBean { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosDataSourceBeanTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosDataSourceBeanTests.java index b078d0012e..bc33b770dc 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosDataSourceBeanTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosDataSourceBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ package org.springframework.boot.jta.atomikos; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Tests for {@link AtomikosDataSourceBean}. @@ -36,10 +36,10 @@ class AtomikosDataSourceBeanTests { bean.setBeanName("bean"); bean.afterPropertiesSet(); assertThat(bean.getUniqueResourceName()).isEqualTo("bean"); - verify(bean).init(); - verify(bean, never()).close(); + then(bean).should().init(); + then(bean).should(never()).close(); bean.destroy(); - verify(bean).close(); + then(bean).should().close(); } static class MockAtomikosDataSourceBean extends AtomikosDataSourceBean { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DeferredLogTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DeferredLogTests.java index 64f75ad501..c887824089 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DeferredLogTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DeferredLogTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,8 @@ import org.springframework.boot.logging.DeferredLog.Lines; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link DeferredLog}. @@ -77,84 +75,84 @@ class DeferredLogTests { void trace() { this.deferredLog.trace(this.message); this.deferredLog.replayTo(this.log); - verify(this.log).trace(this.message, null); + then(this.log).should().trace(this.message, null); } @Test void traceWithThrowable() { this.deferredLog.trace(this.message, this.throwable); this.deferredLog.replayTo(this.log); - verify(this.log).trace(this.message, this.throwable); + then(this.log).should().trace(this.message, this.throwable); } @Test void debug() { this.deferredLog.debug(this.message); this.deferredLog.replayTo(this.log); - verify(this.log).debug(this.message, null); + then(this.log).should().debug(this.message, null); } @Test void debugWithThrowable() { this.deferredLog.debug(this.message, this.throwable); this.deferredLog.replayTo(this.log); - verify(this.log).debug(this.message, this.throwable); + then(this.log).should().debug(this.message, this.throwable); } @Test void info() { this.deferredLog.info(this.message); this.deferredLog.replayTo(this.log); - verify(this.log).info(this.message, null); + then(this.log).should().info(this.message, null); } @Test void infoWithThrowable() { this.deferredLog.info(this.message, this.throwable); this.deferredLog.replayTo(this.log); - verify(this.log).info(this.message, this.throwable); + then(this.log).should().info(this.message, this.throwable); } @Test void warn() { this.deferredLog.warn(this.message); this.deferredLog.replayTo(this.log); - verify(this.log).warn(this.message, null); + then(this.log).should().warn(this.message, null); } @Test void warnWithThrowable() { this.deferredLog.warn(this.message, this.throwable); this.deferredLog.replayTo(this.log); - verify(this.log).warn(this.message, this.throwable); + then(this.log).should().warn(this.message, this.throwable); } @Test void error() { this.deferredLog.error(this.message); this.deferredLog.replayTo(this.log); - verify(this.log).error(this.message, null); + then(this.log).should().error(this.message, null); } @Test void errorWithThrowable() { this.deferredLog.error(this.message, this.throwable); this.deferredLog.replayTo(this.log); - verify(this.log).error(this.message, this.throwable); + then(this.log).should().error(this.message, this.throwable); } @Test void fatal() { this.deferredLog.fatal(this.message); this.deferredLog.replayTo(this.log); - verify(this.log).fatal(this.message, null); + then(this.log).should().fatal(this.message, null); } @Test void fatalWithThrowable() { this.deferredLog.fatal(this.message, this.throwable); this.deferredLog.replayTo(this.log); - verify(this.log).fatal(this.message, this.throwable); + then(this.log).should().fatal(this.message, this.throwable); } @Test @@ -164,10 +162,10 @@ class DeferredLogTests { Log log2 = mock(Log.class); this.deferredLog.replayTo(this.log); this.deferredLog.replayTo(log2); - verify(this.log).info("1", null); - verify(this.log).fatal("2", null); - verifyNoMoreInteractions(this.log); - verifyNoInteractions(log2); + then(this.log).should().info("1", null); + then(this.log).should().fatal("2", null); + then(this.log).shouldHaveNoMoreInteractions(); + then(log2).shouldHaveNoInteractions(); } @Test @@ -180,8 +178,8 @@ class DeferredLogTests { assertThat(lines).isEmpty(); this.deferredLog.info("Message2"); assertThat(lines).isEmpty(); - verify(this.log).error(this.message, this.throwable); - verify(this.log).info("Message2", null); + then(this.log).should().error(this.message, this.throwable); + then(this.log).should().info("Message2", null); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DeferredLogsTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DeferredLogsTests.java index 6dc1d88a5b..8010cb9ef2 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DeferredLogsTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DeferredLogsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,9 @@ import org.apache.commons.logging.Log; import org.junit.jupiter.api.Test; import org.mockito.InOrder; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoInteractions; -import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Tests for {@link DeferredLogs}. @@ -43,18 +42,20 @@ class DeferredLogsTests { dlog2.info("b"); dlog1.info("c"); dlog2.info("d"); - verifyNoInteractions(log1, log2); + then(log1).shouldHaveNoInteractions(); + then(log2).shouldHaveNoInteractions(); loggers.switchOverAll(); InOrder ordered = inOrder(log1, log2); - ordered.verify(log1).info("a", null); - ordered.verify(log2).info("b", null); - ordered.verify(log1).info("c", null); - ordered.verify(log2).info("d", null); - verifyNoMoreInteractions(log1, log2); + then(log1).should(ordered).info("a", null); + then(log2).should(ordered).info("b", null); + then(log1).should(ordered).info("c", null); + then(log2).should(ordered).info("d", null); + then(log1).shouldHaveNoMoreInteractions(); + then(log2).shouldHaveNoMoreInteractions(); dlog1.info("e"); dlog2.info("f"); - ordered.verify(log1).info("e", null); - ordered.verify(log2).info("f", null); + then(log1).should(ordered).info("e", null); + then(log2).should(ordered).info("f", null); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DelegatingLoggingSystemFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DelegatingLoggingSystemFactoryTests.java index b683ea4796..86f4d028dc 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DelegatingLoggingSystemFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/DelegatingLoggingSystemFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,8 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link DelegatingLoggingSystemFactory}. @@ -58,9 +57,9 @@ class DelegatingLoggingSystemFactoryTests { given(delegates.get(1).getLoggingSystem(this.classLoader)).willReturn(result); DelegatingLoggingSystemFactory factory = new DelegatingLoggingSystemFactory((cl) -> delegates); assertThat(factory.getLoggingSystem(this.classLoader)).isSameAs(result); - verify(delegates.get(0)).getLoggingSystem(this.classLoader); - verify(delegates.get(1)).getLoggingSystem(this.classLoader); - verifyNoInteractions(delegates.get(2)); + then(delegates.get(0)).should().getLoggingSystem(this.classLoader); + then(delegates.get(1)).should().getLoggingSystem(this.classLoader); + then(delegates.get(2)).shouldHaveNoInteractions(); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java index 65d83cb628..96e719c7af 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,9 +60,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.contentOf; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link Log4J2LoggingSystem}. @@ -342,11 +342,11 @@ class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests { this.loggingSystem.initialize(this.initializationContext, null, null); this.loggingSystem.beforeInitialize(); this.loggingSystem.initialize(this.initializationContext, null, null); - verify(listener, times(2)).propertyChange(any(PropertyChangeEvent.class)); + then(listener).should(times(2)).propertyChange(any(PropertyChangeEvent.class)); this.loggingSystem.cleanUp(); this.loggingSystem.beforeInitialize(); this.loggingSystem.initialize(this.initializationContext, null, null); - verify(listener, times(4)).propertyChange(any(PropertyChangeEvent.class)); + then(listener).should(times(4)).propertyChange(any(PropertyChangeEvent.class)); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java index 3b8fc3a13e..18f309016b 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,9 +67,9 @@ import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.contentOf; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link LogbackLoggingSystem}. @@ -539,12 +539,12 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { initialize(this.initializationContext, null, null); this.loggingSystem.beforeInitialize(); initialize(this.initializationContext, null, null); - verify(listener, times(1)).onReset(loggerContext); + then(listener).should().onReset(loggerContext); this.loggingSystem.cleanUp(); loggerContext.addListener(listener); this.loggingSystem.beforeInitialize(); initialize(this.initializationContext, null, null); - verify(listener, times(2)).onReset(loggerContext); + then(listener).should(times(2)).onReset(loggerContext); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringProfileActionTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringProfileActionTests.java index 3f1b66c83b..acb6e9c41d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringProfileActionTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringProfileActionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,8 +34,8 @@ import org.springframework.core.env.Profiles; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link SpringProfileAction}. @@ -64,7 +64,7 @@ class SpringProfileActionTests { given(this.attributes.getValue(Action.NAME_ATTRIBUTE)).willReturn("dev"); this.action.begin(this.interpretationContext, null, this.attributes); ArgumentCaptor profiles = ArgumentCaptor.forClass(Profiles.class); - verify(this.environment).acceptsProfiles(profiles.capture()); + then(this.environment).should().acceptsProfiles(profiles.capture()); List profileNames = new ArrayList<>(); profiles.getValue().matches((profile) -> { profileNames.add(profile); @@ -78,7 +78,7 @@ class SpringProfileActionTests { given(this.attributes.getValue(Action.NAME_ATTRIBUTE)).willReturn("dev,qa"); this.action.begin(this.interpretationContext, null, this.attributes); ArgumentCaptor profiles = ArgumentCaptor.forClass(Profiles.class); - verify(this.environment).acceptsProfiles(profiles.capture()); + then(this.environment).should().acceptsProfiles(profiles.capture()); List profileNames = new ArrayList<>(); profiles.getValue().matches((profile) -> { profileNames.add(profile); @@ -93,7 +93,7 @@ class SpringProfileActionTests { this.context.putProperty("profile", "dev"); this.action.begin(this.interpretationContext, null, this.attributes); ArgumentCaptor profiles = ArgumentCaptor.forClass(Profiles.class); - verify(this.environment).acceptsProfiles(profiles.capture()); + then(this.environment).should().acceptsProfiles(profiles.capture()); List profileNames = new ArrayList<>(); profiles.getValue().matches((profile) -> { profileNames.add(profile); @@ -110,7 +110,7 @@ class SpringProfileActionTests { this.context.putProperty("profile2", "qa"); this.action.begin(this.interpretationContext, null, this.attributes); ArgumentCaptor profiles = ArgumentCaptor.forClass(Profiles.class); - verify(this.environment).acceptsProfiles(profiles.capture()); + then(this.environment).should().acceptsProfiles(profiles.capture()); List profileNames = new ArrayList<>(); profiles.getValue().matches((profile) -> { profileNames.add(profile); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/origin/OriginTrackedResourceTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/origin/OriginTrackedResourceTests.java index ab8ed4a51c..74b10996cd 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/origin/OriginTrackedResourceTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/origin/OriginTrackedResourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,8 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.WritableResource; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link OriginTrackedResource}. @@ -53,91 +53,91 @@ class OriginTrackedResourceTests { @Test void getInputStreamDelegatesToResource() throws IOException { this.tracked.getInputStream(); - verify(this.resource).getInputStream(); + then(this.resource).should().getInputStream(); } @Test void existsDelegatesToResource() { this.tracked.exists(); - verify(this.resource).exists(); + then(this.resource).should().exists(); } @Test void isReadableDelegatesToResource() { this.tracked.isReadable(); - verify(this.resource).isReadable(); + then(this.resource).should().isReadable(); } @Test void isOpenDelegatesToResource() { this.tracked.isOpen(); - verify(this.resource).isOpen(); + then(this.resource).should().isOpen(); } @Test void isFileDelegatesToResource() { this.tracked.isFile(); - verify(this.resource).isFile(); + then(this.resource).should().isFile(); } @Test void getURLDelegatesToResource() throws IOException { this.tracked.getURL(); - verify(this.resource).getURL(); + then(this.resource).should().getURL(); } @Test void getURIDelegatesToResource() throws IOException { this.tracked.getURI(); - verify(this.resource).getURI(); + then(this.resource).should().getURI(); } @Test void getFileDelegatesToResource() throws IOException { this.tracked.getFile(); - verify(this.resource).getFile(); + then(this.resource).should().getFile(); } @Test void readableChannelDelegatesToResource() throws IOException { this.tracked.readableChannel(); - verify(this.resource).readableChannel(); + then(this.resource).should().readableChannel(); } @Test void contentLengthDelegatesToResource() throws IOException { this.tracked.contentLength(); - verify(this.resource).contentLength(); + then(this.resource).should().contentLength(); } @Test void lastModifiedDelegatesToResource() throws IOException { this.tracked.lastModified(); - verify(this.resource).lastModified(); + then(this.resource).should().lastModified(); } @Test void createRelativeDelegatesToResource() throws IOException { this.tracked.createRelative("path"); - verify(this.resource).createRelative("path"); + then(this.resource).should().createRelative("path"); } @Test void getFilenameDelegatesToResource() { this.tracked.getFilename(); - verify(this.resource).getFilename(); + then(this.resource).should().getFilename(); } @Test void getDescriptionDelegatesToResource() { this.tracked.getDescription(); - verify(this.resource).getDescription(); + then(this.resource).should().getDescription(); } @Test void getOutputStreamDelegatesToResource() throws IOException { this.tracked.getOutputStream(); - verify(this.resource).getOutputStream(); + then(this.resource).should().getOutputStream(); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/rsocket/context/RSocketPortInfoApplicationContextInitializerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/rsocket/context/RSocketPortInfoApplicationContextInitializerTests.java index a1fd70e83c..1fb098565c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/rsocket/context/RSocketPortInfoApplicationContextInitializerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/rsocket/context/RSocketPortInfoApplicationContextInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link RSocketPortInfoApplicationContextInitializer}. @@ -56,7 +56,7 @@ class RSocketPortInfoApplicationContextInitializerTests { context.getBean(RSocketPortInfoApplicationContextInitializer.class).initialize(context); RSocketServer server = mock(RSocketServer.class); context.publishEvent(new RSocketServerInitializedEvent(server)); - verify(server).address(); + then(server).should().address(); assertThat(context.getEnvironment().getProperty("local.rsocket.server.port")).isNull(); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/sql/init/dependency/DatabaseInitializationDependencyConfigurerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/sql/init/dependency/DatabaseInitializationDependencyConfigurerTests.java index f4d40ffe19..4d0a296963 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/sql/init/dependency/DatabaseInitializationDependencyConfigurerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/sql/init/dependency/DatabaseInitializationDependencyConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,9 +53,9 @@ import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.verify; /** * Tests for {@link DatabaseInitializationDependencyConfigurer}. @@ -129,7 +129,7 @@ class DatabaseInitializationDependencyConfigurerTests { assertThat(alpha.getAttribute(DatabaseInitializerDetector.class.getName())) .isEqualTo(MockDatabaseInitializerDetector.class.getName()); assertThat(bravo.getAttribute(DatabaseInitializerDetector.class.getName())).isNull(); - verify(MockDatabaseInitializerDetector.instance).detectionComplete(context.getBeanFactory(), + then(MockDatabaseInitializerDetector.instance).should().detectionComplete(context.getBeanFactory(), Collections.singleton("alpha")); assertThat(bravo.getDependsOn()).containsExactly("alpha"); }); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskExecutorBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskExecutorBuilderTests.java index b3f35dbe20..183a491934 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskExecutorBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskExecutorBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,10 +27,9 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link TaskExecutorBuilder}. @@ -96,7 +95,7 @@ class TaskExecutorBuilderTests { void customizersShouldApply() { TaskExecutorCustomizer customizer = mock(TaskExecutorCustomizer.class); ThreadPoolTaskExecutor executor = this.builder.customizers(customizer).build(); - verify(customizer).customize(executor); + then(customizer).should().customize(executor); } @Test @@ -106,15 +105,15 @@ class TaskExecutorBuilderTests { this.builder.queueCapacity(10).corePoolSize(4).maxPoolSize(8).allowCoreThreadTimeOut(true) .keepAlive(Duration.ofMinutes(1)).awaitTermination(true).awaitTerminationPeriod(Duration.ofSeconds(30)) .threadNamePrefix("test-").taskDecorator(taskDecorator).additionalCustomizers((taskExecutor) -> { - verify(taskExecutor).setQueueCapacity(10); - verify(taskExecutor).setCorePoolSize(4); - verify(taskExecutor).setMaxPoolSize(8); - verify(taskExecutor).setAllowCoreThreadTimeOut(true); - verify(taskExecutor).setKeepAliveSeconds(60); - verify(taskExecutor).setWaitForTasksToCompleteOnShutdown(true); - verify(taskExecutor).setAwaitTerminationSeconds(30); - verify(taskExecutor).setThreadNamePrefix("test-"); - verify(taskExecutor).setTaskDecorator(taskDecorator); + then(taskExecutor).should().setQueueCapacity(10); + then(taskExecutor).should().setCorePoolSize(4); + then(taskExecutor).should().setMaxPoolSize(8); + then(taskExecutor).should().setAllowCoreThreadTimeOut(true); + then(taskExecutor).should().setKeepAliveSeconds(60); + then(taskExecutor).should().setWaitForTasksToCompleteOnShutdown(true); + then(taskExecutor).should().setAwaitTerminationSeconds(30); + then(taskExecutor).should().setThreadNamePrefix("test-"); + then(taskExecutor).should().setTaskDecorator(taskDecorator); }); this.builder.configure(executor); } @@ -125,8 +124,8 @@ class TaskExecutorBuilderTests { TaskExecutorCustomizer customizer2 = mock(TaskExecutorCustomizer.class); ThreadPoolTaskExecutor executor = this.builder.customizers(customizer1) .customizers(Collections.singleton(customizer2)).build(); - verifyNoInteractions(customizer1); - verify(customizer2).customize(executor); + then(customizer1).shouldHaveNoInteractions(); + then(customizer2).should().customize(executor); } @Test @@ -149,8 +148,8 @@ class TaskExecutorBuilderTests { TaskExecutorCustomizer customizer2 = mock(TaskExecutorCustomizer.class); ThreadPoolTaskExecutor executor = this.builder.customizers(customizer1).additionalCustomizers(customizer2) .build(); - verify(customizer1).customize(executor); - verify(customizer2).customize(executor); + then(customizer1).should().customize(executor); + then(customizer2).should().customize(executor); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskSchedulerBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskSchedulerBuilderTests.java index 46bb185a10..b9f8786f43 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskSchedulerBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskSchedulerBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,10 +26,9 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link TaskSchedulerBuilder}. @@ -83,15 +82,15 @@ class TaskSchedulerBuilderTests { void customizersShouldApply() { TaskSchedulerCustomizer customizer = mock(TaskSchedulerCustomizer.class); ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer).build(); - verify(customizer).customize(scheduler); + then(customizer).should().customize(scheduler); } @Test void customizersShouldBeAppliedLast() { ThreadPoolTaskScheduler scheduler = spy(new ThreadPoolTaskScheduler()); this.builder.poolSize(4).threadNamePrefix("test-").additionalCustomizers((taskScheduler) -> { - verify(taskScheduler).setPoolSize(4); - verify(taskScheduler).setThreadNamePrefix("test-"); + then(taskScheduler).should().setPoolSize(4); + then(taskScheduler).should().setThreadNamePrefix("test-"); }); this.builder.configure(scheduler); } @@ -102,8 +101,8 @@ class TaskSchedulerBuilderTests { TaskSchedulerCustomizer customizer2 = mock(TaskSchedulerCustomizer.class); ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer1) .customizers(Collections.singleton(customizer2)).build(); - verifyNoInteractions(customizer1); - verify(customizer2).customize(scheduler); + then(customizer1).shouldHaveNoInteractions(); + then(customizer2).should().customize(scheduler); } @Test @@ -126,8 +125,8 @@ class TaskSchedulerBuilderTests { TaskSchedulerCustomizer customizer2 = mock(TaskSchedulerCustomizer.class); ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer1).additionalCustomizers(customizer2) .build(); - verify(customizer1).customize(scheduler); - verify(customizer2).customize(scheduler); + then(customizer1).should().customize(scheduler); + then(customizer2).should().customize(scheduler); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/type/classreading/ConcurrentReferenceCachingMetadataReaderFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/type/classreading/ConcurrentReferenceCachingMetadataReaderFactoryTests.java index 359a83c18f..3b6670a785 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/type/classreading/ConcurrentReferenceCachingMetadataReaderFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/type/classreading/ConcurrentReferenceCachingMetadataReaderFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,10 @@ import org.springframework.core.type.classreading.MetadataReader; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link ConcurrentReferenceCachingMetadataReaderFactory}. @@ -42,7 +42,7 @@ class ConcurrentReferenceCachingMetadataReaderFactoryTests { MetadataReader metadataReader1 = factory.getMetadataReader(getClass().getName()); MetadataReader metadataReader2 = factory.getMetadataReader(getClass().getName()); assertThat(metadataReader1).isSameAs(metadataReader2); - verify(factory, times(1)).createMetadataReader(any(Resource.class)); + then(factory).should().createMetadataReader(any(Resource.class)); } @Test @@ -53,7 +53,7 @@ class ConcurrentReferenceCachingMetadataReaderFactoryTests { factory.clearCache(); MetadataReader metadataReader2 = factory.getMetadataReader(getClass().getName()); assertThat(metadataReader1).isNotSameAs(metadataReader2); - verify(factory, times(2)).createMetadataReader(any(Resource.class)); + then(factory).should(times(2)).createMetadataReader(any(Resource.class)); } static class TestConcurrentReferenceCachingMetadataReaderFactory diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/LambdaSafeTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/LambdaSafeTests.java index 96c1c04042..374642980e 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/LambdaSafeTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/LambdaSafeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,8 @@ import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.contains; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link LambdaSafe}. @@ -61,7 +60,7 @@ class LambdaSafeTests { NonGenericCallback callbackInstance = mock(NonGenericCallback.class); String argument = "foo"; LambdaSafe.callback(NonGenericCallback.class, callbackInstance, argument).invoke((c) -> c.handle(argument)); - verify(callbackInstance).handle(argument); + then(callbackInstance).should().handle(argument); } @Test @@ -70,7 +69,7 @@ class LambdaSafeTests { StringCallback callbackInstance = mock(StringCallback.class); String argument = "foo"; LambdaSafe.callback(GenericCallback.class, callbackInstance, argument).invoke((c) -> c.handle(argument)); - verify(callbackInstance).handle(argument); + then(callbackInstance).should().handle(argument); } @Test @@ -79,7 +78,7 @@ class LambdaSafeTests { StringBuilderCallback callbackInstance = mock(StringBuilderCallback.class); StringBuilder argument = new StringBuilder("foo"); LambdaSafe.callback(GenericCallback.class, callbackInstance, argument).invoke((c) -> c.handle(argument)); - verify(callbackInstance).handle(argument); + then(callbackInstance).should().handle(argument); } @Test @@ -88,7 +87,7 @@ class LambdaSafeTests { GenericCallback callbackInstance = mock(StringBuilderCallback.class); String argument = "foo"; LambdaSafe.callback(GenericCallback.class, callbackInstance, argument).invoke((c) -> c.handle(argument)); - verifyNoInteractions(callbackInstance); + then(callbackInstance).shouldHaveNoInteractions(); } @Test @@ -151,7 +150,7 @@ class LambdaSafeTests { given(callbackInstance.handle(any(StringBuilder.class))).willReturn(123); InvocationResult result = LambdaSafe.callback(GenericFactory.class, callbackInstance, argument) .invokeAnd((c) -> c.handle(argument)); - verify(callbackInstance).handle(argument); + then(callbackInstance).should().handle(argument); assertThat(result.hasResult()).isTrue(); assertThat(result.get()).isEqualTo(123); } @@ -164,7 +163,7 @@ class LambdaSafeTests { InvocationResult result = LambdaSafe.callback(GenericFactory.class, callbackInstance, argument) .invokeAnd((c) -> c.handle(argument)); assertThat(result.hasResult()).isFalse(); - verifyNoInteractions(callbackInstance); + then(callbackInstance).shouldHaveNoInteractions(); } @Test @@ -199,7 +198,7 @@ class LambdaSafeTests { String argument = "foo"; LambdaSafe.callbacks(NonGenericCallback.class, Collections.singleton(callbackInstance), argument) .invoke((c) -> c.handle(argument)); - verify(callbackInstance).handle(argument); + then(callbackInstance).should().handle(argument); } @Test @@ -209,7 +208,7 @@ class LambdaSafeTests { String argument = "foo"; LambdaSafe.callbacks(GenericCallback.class, Collections.singleton(callbackInstance), argument) .invoke((c) -> c.handle(argument)); - verify(callbackInstance).handle(argument); + then(callbackInstance).should().handle(argument); } @Test @@ -219,7 +218,7 @@ class LambdaSafeTests { StringBuilder argument = new StringBuilder("foo"); LambdaSafe.callbacks(GenericCallback.class, Collections.singleton(callbackInstance), argument) .invoke((c) -> c.handle(argument)); - verify(callbackInstance).handle(argument); + then(callbackInstance).should().handle(argument); } @Test @@ -229,7 +228,7 @@ class LambdaSafeTests { String argument = "foo"; LambdaSafe.callbacks(GenericCallback.class, Collections.singleton(callbackInstance), argument) .invoke((c) -> c.handle(null)); - verifyNoInteractions(callbackInstance); + then(callbackInstance).shouldHaveNoInteractions(); } @Test @@ -365,7 +364,7 @@ class LambdaSafeTests { String argument = "foo"; LambdaSafe.callback(GenericCallback.class, callbackInstance, argument).withFilter(Filter.allowAll()) .invoke((c) -> c.handle(null)); - verify(callbackInstance).handle(null); + then(callbackInstance).should().handle(null); } @Test @@ -377,7 +376,8 @@ class LambdaSafeTests { String argument = "foo"; LambdaSafe.callback(GenericCallback.class, callbackInstance, argument).withLogger(logger) .invoke((c) -> c.handle(argument)); - verify(logger).debug(contains("Non-matching CharSequence type for callback LambdaSafeTests.GenericCallback"), + then(logger).should().debug( + contains("Non-matching CharSequence type for callback LambdaSafeTests.GenericCallback"), any(Throwable.class)); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java index 7eac2c08f5..45ca08e663 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,11 +57,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.entry; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; @@ -97,7 +96,7 @@ class RestTemplateBuilderTests { void createWithCustomizersShouldApplyCustomizers() { RestTemplateCustomizer customizer = mock(RestTemplateCustomizer.class); RestTemplate template = new RestTemplateBuilder(customizer).build(); - verify(customizer).customize(template); + then(customizer).should().customize(template); } @Test @@ -129,7 +128,7 @@ class RestTemplateBuilderTests { UriTemplateHandler handler = template.getUriTemplateHandler(); handler.expand("/hello"); assertThat(handler).isInstanceOf(RootUriTemplateHandler.class); - verify(uriTemplateHandler).expand("https://example.com/hello"); + then(uriTemplateHandler).should().expand("https://example.com/hello"); } @Test @@ -369,14 +368,14 @@ class RestTemplateBuilderTests { void customizersShouldApply() { RestTemplateCustomizer customizer = mock(RestTemplateCustomizer.class); RestTemplate template = this.builder.customizers(customizer).build(); - verify(customizer).customize(template); + then(customizer).should().customize(template); } @Test void customizersShouldBeAppliedLast() { RestTemplate template = spy(new RestTemplate()); this.builder.additionalCustomizers( - (restTemplate) -> verify(restTemplate).setRequestFactory(any(ClientHttpRequestFactory.class))); + (restTemplate) -> then(restTemplate).should().setRequestFactory(any(ClientHttpRequestFactory.class))); this.builder.configure(template); } @@ -386,8 +385,8 @@ class RestTemplateBuilderTests { RestTemplateCustomizer customizer2 = mock(RestTemplateCustomizer.class); RestTemplate template = this.builder.customizers(customizer1).customizers(Collections.singleton(customizer2)) .build(); - verifyNoInteractions(customizer1); - verify(customizer2).customize(template); + then(customizer1).shouldHaveNoInteractions(); + then(customizer2).should().customize(template); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RootUriTemplateHandlerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RootUriTemplateHandlerTests.java index cb3ba8f7c3..f75da6468b 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RootUriTemplateHandlerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RootUriTemplateHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link RootUriTemplateHandler}. @@ -76,7 +76,7 @@ class RootUriTemplateHandlerTests { given(this.delegate.expand(anyString(), any(Map.class))).willReturn(this.uri); HashMap uriVariables = new HashMap<>(); URI expanded = this.handler.expand("/hello", uriVariables); - verify(this.delegate).expand("https://example.com/hello", uriVariables); + then(this.delegate).should().expand("https://example.com/hello", uriVariables); assertThat(expanded).isEqualTo(this.uri); } @@ -86,7 +86,7 @@ class RootUriTemplateHandlerTests { given(this.delegate.expand(anyString(), any(Map.class))).willReturn(this.uri); HashMap uriVariables = new HashMap<>(); URI expanded = this.handler.expand("https://spring.io/hello", uriVariables); - verify(this.delegate).expand("https://spring.io/hello", uriVariables); + then(this.delegate).should().expand("https://spring.io/hello", uriVariables); assertThat(expanded).isEqualTo(this.uri); } @@ -95,7 +95,7 @@ class RootUriTemplateHandlerTests { given(this.delegate.expand(anyString(), any(Object[].class))).willReturn(this.uri); Object[] uriVariables = new Object[0]; URI expanded = this.handler.expand("/hello", uriVariables); - verify(this.delegate).expand("https://example.com/hello", uriVariables); + then(this.delegate).should().expand("https://example.com/hello", uriVariables); assertThat(expanded).isEqualTo(this.uri); } @@ -104,7 +104,7 @@ class RootUriTemplateHandlerTests { given(this.delegate.expand(anyString(), any(Object[].class))).willReturn(this.uri); Object[] uriVariables = new Object[0]; URI expanded = this.handler.expand("https://spring.io/hello", uriVariables); - verify(this.delegate).expand("https://spring.io/hello", uriVariables); + then(this.delegate).should().expand("https://spring.io/hello", uriVariables); assertThat(expanded).isEqualTo(this.uri); } @@ -116,7 +116,7 @@ class RootUriTemplateHandlerTests { this.handler = RootUriTemplateHandler.addTo(restTemplate, "https://example.com"); Object[] uriVariables = new Object[0]; URI expanded = this.handler.expand("/hello", uriVariables); - verify(this.delegate).expand("https://example.com/hello", uriVariables); + then(this.delegate).should().expand("https://example.com/hello", uriVariables); assertThat(expanded).isEqualTo(this.uri); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java index ea122a439b..13a63ebc07 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,9 +55,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link TomcatReactiveWebServerFactory}. @@ -83,7 +83,7 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto this.webServer = factory.getWebServer(mock(HttpHandler.class)); InOrder ordered = inOrder((Object[]) customizers); for (TomcatContextCustomizer customizer : customizers) { - ordered.verify(customizer).customize(any(Context.class)); + then(customizer).should(ordered).customize(any(Context.class)); } } @@ -94,7 +94,7 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto factory.addContextCustomizers(customizer); this.webServer = factory.getWebServer(mock(HttpHandler.class)); ArgumentCaptor contextCaptor = ArgumentCaptor.forClass(Context.class); - verify(customizer).customize(contextCaptor.capture()); + then(customizer).should().customize(contextCaptor.capture()); assertThat(contextCaptor.getValue().getParent()).isNotNull(); } @@ -119,7 +119,7 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto this.webServer = factory.getWebServer(mock(HttpHandler.class)); InOrder ordered = inOrder((Object[]) listeners); for (LifecycleListener listener : listeners) { - ordered.verify(listener).lifecycleEvent(any(LifecycleEvent.class)); + then(listener).should(ordered).lifecycleEvent(any(LifecycleEvent.class)); } } @@ -164,7 +164,7 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto this.webServer = factory.getWebServer(handler); InOrder ordered = inOrder((Object[]) customizers); for (TomcatConnectorCustomizer customizer : customizers) { - ordered.verify(customizer).customize(any(Connector.class)); + then(customizer).should(ordered).customize(any(Connector.class)); } } @@ -180,7 +180,7 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto this.webServer = factory.getWebServer(handler); InOrder ordered = inOrder((Object[]) customizers); for (TomcatProtocolHandlerCustomizer customizer : customizers) { - ordered.verify(customizer).customize(any(ProtocolHandler.class)); + then(customizer).should(ordered).customize(any(ProtocolHandler.class)); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java index cf507a3d9c..b1368d452c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -94,9 +94,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link TomcatServletWebServerFactory}. @@ -152,7 +152,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory this.webServer = factory.getWebServer(); InOrder ordered = inOrder((Object[]) listeners); for (LifecycleListener listener : listeners) { - ordered.verify(listener).lifecycleEvent(any(LifecycleEvent.class)); + then(listener).should(ordered).lifecycleEvent(any(LifecycleEvent.class)); } } @@ -166,7 +166,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory this.webServer = factory.getWebServer(); InOrder ordered = inOrder((Object[]) customizers); for (TomcatContextCustomizer customizer : customizers) { - ordered.verify(customizer).customize(any(Context.class)); + then(customizer).should(ordered).customize(any(Context.class)); } } @@ -177,7 +177,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory factory.addContextCustomizers(customizer); this.webServer = factory.getWebServer(); ArgumentCaptor contextCaptor = ArgumentCaptor.forClass(Context.class); - verify(customizer).customize(contextCaptor.capture()); + then(customizer).should().customize(contextCaptor.capture()); assertThat(contextCaptor.getValue().getParent()).isNotNull(); } @@ -191,7 +191,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory this.webServer = factory.getWebServer(); InOrder ordered = inOrder((Object[]) customizers); for (TomcatConnectorCustomizer customizer : customizers) { - ordered.verify(customizer).customize(any(Connector.class)); + then(customizer).should(ordered).customize(any(Connector.class)); } } @@ -206,7 +206,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory this.webServer = factory.getWebServer(); InOrder ordered = inOrder((Object[]) customizers); for (TomcatProtocolHandlerCustomizer customizer : customizers) { - ordered.verify(customizer).customize(any(ProtocolHandler.class)); + then(customizer).should(ordered).customize(any(ProtocolHandler.class)); } } @@ -267,7 +267,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory Valve valve = mock(Valve.class); factory.addContextValves(valve); this.webServer = factory.getWebServer(); - verify(valve).setNext(any(Valve.class)); + then(valve).should().setNext(any(Valve.class)); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextTests.java index c16930732b..24ff9da399 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ import org.springframework.http.server.reactive.HttpHandler; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link ReactiveWebServerApplicationContext}. @@ -123,7 +123,7 @@ class ReactiveWebServerApplicationContextTests { this.context.refresh(); MockReactiveWebServerFactory factory = this.context.getBean(MockReactiveWebServerFactory.class); this.context.close(); - verify(factory.getWebServer()).stop(); + then(factory.getWebServer()).should().stop(); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java index 77c9e95139..998d376256 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Abstract base for {@link AbstractFilterRegistrationBean} tests. @@ -60,9 +60,9 @@ abstract class AbstractFilterRegistrationBeanTests { given(this.servletContext.addFilter(anyString(), any(Filter.class))).willReturn(this.registration); AbstractFilterRegistrationBean bean = createFilterRegistrationBean(); bean.onStartup(this.servletContext); - verify(this.servletContext).addFilter(eq("mockFilter"), getExpectedFilter()); - verify(this.registration).setAsyncSupported(true); - verify(this.registration).addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*"); + then(this.servletContext).should().addFilter(eq("mockFilter"), getExpectedFilter()); + then(this.registration).should().setAsyncSupported(true); + then(this.registration).should().addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*"); } @Test @@ -81,15 +81,16 @@ abstract class AbstractFilterRegistrationBeanTests { bean.addServletRegistrationBeans(mockServletRegistration("s5")); bean.setMatchAfter(true); bean.onStartup(this.servletContext); - verify(this.servletContext).addFilter(eq("test"), getExpectedFilter()); - verify(this.registration).setAsyncSupported(false); + then(this.servletContext).should().addFilter(eq("test"), getExpectedFilter()); + then(this.registration).should().setAsyncSupported(false); Map expectedInitParameters = new HashMap<>(); expectedInitParameters.put("a", "b"); expectedInitParameters.put("c", "d"); - verify(this.registration).setInitParameters(expectedInitParameters); - verify(this.registration).addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/a", "/b", "/c"); - verify(this.registration).addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, "s4", "s5", "s1", - "s2", "s3"); + then(this.registration).should().setInitParameters(expectedInitParameters); + then(this.registration).should().addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/a", "/b", + "/c"); + then(this.registration).should().addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, "s4", "s5", + "s1", "s2", "s3"); } @Test @@ -97,14 +98,14 @@ abstract class AbstractFilterRegistrationBeanTests { AbstractFilterRegistrationBean bean = createFilterRegistrationBean(); bean.setName("specificName"); bean.onStartup(this.servletContext); - verify(this.servletContext).addFilter(eq("specificName"), getExpectedFilter()); + then(this.servletContext).should().addFilter(eq("specificName"), getExpectedFilter()); } @Test void deducedName() throws Exception { AbstractFilterRegistrationBean bean = createFilterRegistrationBean(); bean.onStartup(this.servletContext); - verify(this.servletContext).addFilter(eq("mockFilter"), getExpectedFilter()); + then(this.servletContext).should().addFilter(eq("mockFilter"), getExpectedFilter()); } @Test @@ -112,7 +113,7 @@ abstract class AbstractFilterRegistrationBeanTests { AbstractFilterRegistrationBean bean = createFilterRegistrationBean(); bean.setEnabled(false); bean.onStartup(this.servletContext); - verify(this.servletContext, never()).addFilter(eq("mockFilter"), getExpectedFilter()); + then(this.servletContext).should(never()).addFilter(eq("mockFilter"), getExpectedFilter()); } @Test @@ -137,7 +138,7 @@ abstract class AbstractFilterRegistrationBeanTests { bean.setServletRegistrationBeans( new LinkedHashSet>(Collections.singletonList(mockServletRegistration("b")))); bean.onStartup(this.servletContext); - verify(this.registration).addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), false, "b"); + then(this.registration).should().addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), false, "b"); } @Test @@ -147,7 +148,7 @@ abstract class AbstractFilterRegistrationBeanTests { bean.addInitParameter("a", "b"); bean.getInitParameters().put("a", "c"); bean.onStartup(this.servletContext); - verify(this.registration).setInitParameters(Collections.singletonMap("a", "c")); + then(this.registration).should().setInitParameters(Collections.singletonMap("a", "c")); } @Test @@ -184,8 +185,8 @@ abstract class AbstractFilterRegistrationBeanTests { AbstractFilterRegistrationBean bean = createFilterRegistrationBean(); bean.setDispatcherTypes(DispatcherType.INCLUDE, DispatcherType.FORWARD); bean.onStartup(this.servletContext); - verify(this.registration).addMappingForUrlPatterns(EnumSet.of(DispatcherType.INCLUDE, DispatcherType.FORWARD), - false, "/*"); + then(this.registration).should() + .addMappingForUrlPatterns(EnumSet.of(DispatcherType.INCLUDE, DispatcherType.FORWARD), false, "/*"); } @Test @@ -195,7 +196,7 @@ abstract class AbstractFilterRegistrationBeanTests { EnumSet types = EnumSet.of(DispatcherType.INCLUDE, DispatcherType.FORWARD); bean.setDispatcherTypes(types); bean.onStartup(this.servletContext); - verify(this.registration).addMappingForUrlPatterns(types, false, "/*"); + then(this.registration).should().addMappingForUrlPatterns(types, false, "/*"); } protected abstract Filter getExpectedFilter(); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/FilterRegistrationBeanTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/FilterRegistrationBeanTests.java index e36060d0a2..17faa28d7a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/FilterRegistrationBeanTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/FilterRegistrationBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link FilterRegistrationBean}. @@ -62,7 +62,7 @@ class FilterRegistrationBeanTests extends AbstractFilterRegistrationBeanTests { FilterRegistrationBean bean = new FilterRegistrationBean<>(); bean.setFilter(this.filter); bean.onStartup(this.servletContext); - verify(this.servletContext).addFilter("mockFilter", this.filter); + then(this.servletContext).should().addFilter("mockFilter", this.filter); } @Test @@ -90,9 +90,9 @@ class FilterRegistrationBeanTests extends AbstractFilterRegistrationBeanTests { given(this.servletContext.addFilter(anyString(), any(Filter.class))).willReturn(this.registration); FilterRegistrationBean bean = new FilterRegistrationBean<>(this.oncePerRequestFilter); bean.onStartup(this.servletContext); - verify(this.servletContext).addFilter(eq("oncePerRequestFilter"), eq(this.oncePerRequestFilter)); - verify(this.registration).setAsyncSupported(true); - verify(this.registration).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); + then(this.servletContext).should().addFilter(eq("oncePerRequestFilter"), eq(this.oncePerRequestFilter)); + then(this.registration).should().setAsyncSupported(true); + then(this.registration).should().addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); } @Override diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletListenerRegistrationBeanTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletListenerRegistrationBeanTests.java index ca1e9587a0..b934637bc1 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletListenerRegistrationBeanTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletListenerRegistrationBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link ServletListenerRegistrationBean}. @@ -50,7 +50,7 @@ class ServletListenerRegistrationBeanTests { ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean<>( this.listener); bean.onStartup(this.servletContext); - verify(this.servletContext).addListener(this.listener); + then(this.servletContext).should().addListener(this.listener); } @Test @@ -59,7 +59,7 @@ class ServletListenerRegistrationBeanTests { this.listener); bean.setEnabled(false); bean.onStartup(this.servletContext); - verify(this.servletContext, never()).addListener(any(ServletContextListener.class)); + then(this.servletContext).should(never()).addListener(any(ServletContextListener.class)); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletRegistrationBeanTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletRegistrationBeanTests.java index d94ef06850..f6a2d46080 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletRegistrationBeanTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletRegistrationBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link ServletRegistrationBean}. @@ -65,9 +65,9 @@ class ServletRegistrationBeanTests { given(this.servletContext.addServlet(anyString(), any(Servlet.class))).willReturn(this.registration); ServletRegistrationBean bean = new ServletRegistrationBean<>(this.servlet); bean.onStartup(this.servletContext); - verify(this.servletContext).addServlet("mockServlet", this.servlet); - verify(this.registration).setAsyncSupported(true); - verify(this.registration).addMapping("/*"); + then(this.servletContext).should().addServlet("mockServlet", this.servlet); + then(this.registration).should().setAsyncSupported(true); + then(this.registration).should().addMapping("/*"); } @Test @@ -75,8 +75,8 @@ class ServletRegistrationBeanTests { ServletRegistrationBean bean = new ServletRegistrationBean<>(this.servlet); given(this.servletContext.addServlet(anyString(), any(Servlet.class))).willReturn(null); bean.onStartup(this.servletContext); - verify(this.servletContext).addServlet("mockServlet", this.servlet); - verify(this.registration, never()).setAsyncSupported(true); + then(this.servletContext).should().addServlet("mockServlet", this.servlet); + then(this.registration).should(never()).setAsyncSupported(true); } @Test @@ -92,14 +92,14 @@ class ServletRegistrationBeanTests { bean.addUrlMappings("/c"); bean.setLoadOnStartup(10); bean.onStartup(this.servletContext); - verify(this.servletContext).addServlet("test", this.servlet); - verify(this.registration).setAsyncSupported(false); + then(this.servletContext).should().addServlet("test", this.servlet); + then(this.registration).should().setAsyncSupported(false); Map expectedInitParameters = new HashMap<>(); expectedInitParameters.put("a", "b"); expectedInitParameters.put("c", "d"); - verify(this.registration).setInitParameters(expectedInitParameters); - verify(this.registration).addMapping("/a", "/b", "/c"); - verify(this.registration).setLoadOnStartup(10); + then(this.registration).should().setInitParameters(expectedInitParameters); + then(this.registration).should().addMapping("/a", "/b", "/c"); + then(this.registration).should().setLoadOnStartup(10); } @Test @@ -108,7 +108,7 @@ class ServletRegistrationBeanTests { bean.setName("specificName"); bean.setServlet(this.servlet); bean.onStartup(this.servletContext); - verify(this.servletContext).addServlet("specificName", this.servlet); + then(this.servletContext).should().addServlet("specificName", this.servlet); } @Test @@ -116,7 +116,7 @@ class ServletRegistrationBeanTests { ServletRegistrationBean bean = new ServletRegistrationBean<>(); bean.setServlet(this.servlet); bean.onStartup(this.servletContext); - verify(this.servletContext).addServlet("mockServlet", this.servlet); + then(this.servletContext).should().addServlet("mockServlet", this.servlet); } @Test @@ -125,7 +125,7 @@ class ServletRegistrationBeanTests { bean.setServlet(this.servlet); bean.setEnabled(false); bean.onStartup(this.servletContext); - verify(this.servletContext, never()).addServlet("mockServlet", this.servlet); + then(this.servletContext).should(never()).addServlet("mockServlet", this.servlet); } @Test @@ -168,7 +168,7 @@ class ServletRegistrationBeanTests { ServletRegistrationBean bean = new ServletRegistrationBean<>(this.servlet, "/a", "/b"); bean.setUrlMappings(new LinkedHashSet<>(Arrays.asList("/c", "/d"))); bean.onStartup(this.servletContext); - verify(this.registration).addMapping("/c", "/d"); + then(this.registration).should().addMapping("/c", "/d"); } @Test @@ -178,14 +178,14 @@ class ServletRegistrationBeanTests { bean.addInitParameter("a", "b"); bean.getInitParameters().put("a", "c"); bean.onStartup(this.servletContext); - verify(this.registration).setInitParameters(Collections.singletonMap("a", "c")); + then(this.registration).should().setInitParameters(Collections.singletonMap("a", "c")); } @Test void withoutDefaultMappings() throws Exception { ServletRegistrationBean bean = new ServletRegistrationBean<>(this.servlet, false); bean.onStartup(this.servletContext); - verify(this.registration, never()).addMapping(any(String[].class)); + then(this.registration).should(never()).addMapping(any(String[].class)); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java index d4d78c1981..756fcecba3 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ import org.springframework.web.context.ServletContextAware; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link AnnotationConfigServletWebServerApplicationContext}. @@ -138,7 +138,7 @@ class AnnotationConfigServletWebServerApplicationContextTests { private void verifyContext() { MockServletWebServerFactory factory = this.context.getBean(MockServletWebServerFactory.class); Servlet servlet = this.context.getBean(Servlet.class); - verify(factory.getServletContext()).addServlet("servlet", servlet); + then(factory.getServletContext()).should().addServlet("servlet", servlet); } @Component diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java index 1ba3f1d3e0..60cbafa3ee 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,10 +81,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.withSettings; /** @@ -113,8 +113,8 @@ class ServletWebServerApplicationContextTests { MockServletWebServerFactory factory = getWebServerFactory(); // Ensure that the context has been setup assertThat(this.context.getServletContext()).isEqualTo(factory.getServletContext()); - verify(factory.getServletContext()).setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, - this.context); + then(factory.getServletContext()).should() + .setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context); // Ensure WebApplicationContextUtils.registerWebApplicationScopes was called assertThat(this.context.getBeanFactory().getRegisteredScope(WebApplicationContext.SCOPE_SESSION)) .isInstanceOf(SessionScope.class); @@ -161,7 +161,7 @@ class ServletWebServerApplicationContextTests { this.context.refresh(); MockServletWebServerFactory factory = getWebServerFactory(); this.context.close(); - verify(factory.getWebServer()).stop(); + then(factory.getWebServer()).should().stop(); } @Test @@ -199,7 +199,7 @@ class ServletWebServerApplicationContextTests { ServletContextAware bean = mock(ServletContextAware.class); this.context.registerBeanDefinition("bean", beanDefinition(bean)); this.context.refresh(); - verify(bean).setServletContext(getWebServerFactory().getServletContext()); + then(bean).should().setServletContext(getWebServerFactory().getServletContext()); } @Test @@ -227,8 +227,8 @@ class ServletWebServerApplicationContextTests { this.context.registerBeanDefinition("servletBean", beanDefinition(servlet)); this.context.refresh(); MockServletWebServerFactory factory = getWebServerFactory(); - verify(factory.getServletContext()).addServlet("servletBean", servlet); - verify(factory.getRegisteredServlet(0).getRegistration()).addMapping("/"); + then(factory.getServletContext()).should().addServlet("servletBean", servlet); + then(factory.getRegisteredServlet(0).getRegistration()).should().addMapping("/"); } @Test @@ -242,8 +242,8 @@ class ServletWebServerApplicationContextTests { this.context.registerBeanDefinition("filterRegistrationBean", beanDefinition(registration)); this.context.refresh(); MockServletWebServerFactory factory = getWebServerFactory(); - verify(factory.getServletContext()).addFilter("filterBean", filter); - verify(factory.getServletContext()).addFilter("object", registration.getFilter()); + then(factory.getServletContext()).should().addFilter("filterBean", filter); + then(factory.getServletContext()).should().addFilter("object", registration.getFilter()); assertThat(factory.getRegisteredFilter(0).getFilter()).isEqualTo(filter); } @@ -260,10 +260,10 @@ class ServletWebServerApplicationContextTests { MockServletWebServerFactory factory = getWebServerFactory(); ServletContext servletContext = factory.getServletContext(); InOrder ordered = inOrder(servletContext); - ordered.verify(servletContext).addServlet("servletBean1", servlet1); - ordered.verify(servletContext).addServlet("servletBean2", servlet2); - verify(factory.getRegisteredServlet(0).getRegistration()).addMapping("/servletBean1/"); - verify(factory.getRegisteredServlet(1).getRegistration()).addMapping("/servletBean2/"); + then(servletContext).should(ordered).addServlet("servletBean1", servlet1); + then(servletContext).should(ordered).addServlet("servletBean2", servlet2); + then(factory.getRegisteredServlet(0).getRegistration()).should().addMapping("/servletBean1/"); + then(factory.getRegisteredServlet(1).getRegistration()).should().addMapping("/servletBean2/"); } @Test @@ -279,10 +279,10 @@ class ServletWebServerApplicationContextTests { MockServletWebServerFactory factory = getWebServerFactory(); ServletContext servletContext = factory.getServletContext(); InOrder ordered = inOrder(servletContext); - ordered.verify(servletContext).addServlet("dispatcherServlet", servlet1); - ordered.verify(servletContext).addServlet("servletBean2", servlet2); - verify(factory.getRegisteredServlet(0).getRegistration()).addMapping("/"); - verify(factory.getRegisteredServlet(1).getRegistration()).addMapping("/servletBean2/"); + then(servletContext).should(ordered).addServlet("dispatcherServlet", servlet1); + then(servletContext).should(ordered).addServlet("servletBean2", servlet2); + then(factory.getRegisteredServlet(0).getRegistration()).should().addMapping("/"); + then(factory.getRegisteredServlet(1).getRegistration()).should().addMapping("/servletBean2/"); } @Test @@ -300,13 +300,13 @@ class ServletWebServerApplicationContextTests { MockServletWebServerFactory factory = getWebServerFactory(); ServletContext servletContext = factory.getServletContext(); InOrder ordered = inOrder(servletContext); - verify(factory.getServletContext()).addServlet("servletBean", servlet); - verify(factory.getRegisteredServlet(0).getRegistration()).addMapping("/"); - ordered.verify(factory.getServletContext()).addFilter("filterBean1", filter1); - ordered.verify(factory.getServletContext()).addFilter("filterBean2", filter2); - verify(factory.getRegisteredFilter(0).getRegistration()) + then(factory.getServletContext()).should().addServlet("servletBean", servlet); + then(factory.getRegisteredServlet(0).getRegistration()).should().addMapping("/"); + then(factory.getServletContext()).should(ordered).addFilter("filterBean1", filter1); + then(factory.getServletContext()).should(ordered).addFilter("filterBean2", filter2); + then(factory.getRegisteredFilter(0).getRegistration()).should() .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*"); - verify(factory.getRegisteredFilter(1).getRegistration()) + then(factory.getRegisteredFilter(1).getRegistration()).should() .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*"); } @@ -324,8 +324,8 @@ class ServletWebServerApplicationContextTests { this.context.refresh(); ServletContext servletContext = getWebServerFactory().getServletContext(); InOrder ordered = inOrder(initializer1, initializer2); - ordered.verify(initializer1).onStartup(servletContext); - ordered.verify(initializer2).onStartup(servletContext); + then(initializer1).should(ordered).onStartup(servletContext); + then(initializer2).should(ordered).onStartup(servletContext); } @Test @@ -335,7 +335,7 @@ class ServletWebServerApplicationContextTests { this.context.registerBeanDefinition("initializerBean", beanDefinition(initializer)); this.context.refresh(); ServletContext servletContext = getWebServerFactory().getServletContext(); - verify(servletContext).addListener(initializer); + then(servletContext).should().addListener(initializer); } @Test @@ -347,8 +347,8 @@ class ServletWebServerApplicationContextTests { this.context.registerBeanDefinition("initializerBean1", beanDefinition(initializer1)); this.context.refresh(); ServletContext servletContext = getWebServerFactory().getServletContext(); - verify(initializer1).onStartup(servletContext); - verify(initializer2).onStartup(servletContext); + then(initializer1).should().onStartup(servletContext); + then(initializer2).should().onStartup(servletContext); } @Test @@ -362,9 +362,9 @@ class ServletWebServerApplicationContextTests { this.context.registerBeanDefinition("filterBean", beanDefinition(filter)); this.context.refresh(); ServletContext servletContext = getWebServerFactory().getServletContext(); - verify(initializer).onStartup(servletContext); - verify(servletContext).addServlet(anyString(), any(Servlet.class)); - verify(servletContext).addFilter(anyString(), any(Filter.class)); + then(initializer).should().onStartup(servletContext); + then(servletContext).should().addServlet(anyString(), any(Servlet.class)); + then(servletContext).should().addFilter(anyString(), any(Filter.class)); } @Test @@ -378,8 +378,8 @@ class ServletWebServerApplicationContextTests { this.context.registerBeanDefinition("filterBean", beanDefinition(filter)); this.context.refresh(); ServletContext servletContext = getWebServerFactory().getServletContext(); - verify(servletContext, atMost(1)).addServlet(anyString(), any(Servlet.class)); - verify(servletContext, atMost(1)).addFilter(anyString(), any(Filter.class)); + then(servletContext).should(atMost(1)).addServlet(anyString(), any(Servlet.class)); + then(servletContext).should(atMost(1)).addFilter(anyString(), any(Filter.class)); } @Test @@ -391,7 +391,7 @@ class ServletWebServerApplicationContextTests { this.context.registerBeanDefinition("filterBean", beanDefinition(filter)); this.context.refresh(); ServletContext servletContext = getWebServerFactory().getServletContext(); - verify(servletContext, atMost(1)).addFilter(anyString(), any(Filter.class)); + then(servletContext).should(atMost(1)).addFilter(anyString(), any(Filter.class)); } @Test @@ -404,7 +404,7 @@ class ServletWebServerApplicationContextTests { this.context.registerBeanDefinition("filterBean", filterBeanDefinition); this.context.refresh(); ServletContext servletContext = getWebServerFactory().getServletContext(); - verify(servletContext, atMost(1)).addFilter(anyString(), this.filterCaptor.capture()); + then(servletContext).should(atMost(1)).addFilter(anyString(), this.filterCaptor.capture()); // Up to this point the filterBean should not have been created, calling // the delegate proxy will trigger creation and an exception assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/XmlServletWebServerApplicationContextTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/XmlServletWebServerApplicationContextTests.java index 9b8fab137d..04e0ea8749 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/XmlServletWebServerApplicationContextTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/XmlServletWebServerApplicationContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; import org.springframework.core.io.ClassPathResource; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link XmlServletWebServerApplicationContext}. @@ -84,7 +84,7 @@ class XmlServletWebServerApplicationContextTests { private void verifyContext() { MockServletWebServerFactory factory = this.context.getBean(MockServletWebServerFactory.class); Servlet servlet = this.context.getBean(Servlet.class); - verify(factory.getServletContext()).addServlet("servlet", servlet); + then(factory.getServletContext()).should().addServlet("servlet", servlet); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/filter/ErrorPageSecurityFilterTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/filter/ErrorPageSecurityFilterTests.java index 41cdbd479b..3bae2d22f5 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/filter/ErrorPageSecurityFilterTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/filter/ErrorPageSecurityFilterTests.java @@ -42,10 +42,9 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link ErrorPageSecurityFilter}. @@ -82,7 +81,7 @@ class ErrorPageSecurityFilterTests { void whenAccessIsAllowedShouldContinueDownFilterChain() throws Exception { given(this.privilegeEvaluator.isAllowed(anyString(), any())).willReturn(true); this.securityFilter.doFilter(this.request, this.response, this.filterChain); - verify(this.filterChain).doFilter(this.request, this.response); + then(this.filterChain).should().doFilter(this.request, this.response); } @Test @@ -90,7 +89,7 @@ class ErrorPageSecurityFilterTests { given(this.privilegeEvaluator.isAllowed(anyString(), any())).willReturn(false); this.request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, 403); this.securityFilter.doFilter(this.request, this.response, this.filterChain); - verifyNoInteractions(this.filterChain); + then(this.filterChain).shouldHaveNoInteractions(); assertThat(this.response.getStatus()).isEqualTo(403); } @@ -101,7 +100,7 @@ class ErrorPageSecurityFilterTests { SecurityContextHolder.setContext(securityContext); given(securityContext.getAuthentication()).willReturn(mock(Authentication.class)); this.securityFilter.doFilter(this.request, this.response, this.filterChain); - verifyNoInteractions(this.filterChain); + then(this.filterChain).shouldHaveNoInteractions(); assertThat(this.response.getStatus()).isEqualTo(401); } @@ -111,7 +110,7 @@ class ErrorPageSecurityFilterTests { willThrow(NoSuchBeanDefinitionException.class).given(context).getBean(WebInvocationPrivilegeEvaluator.class); ErrorPageSecurityFilter securityFilter = new ErrorPageSecurityFilter(context); securityFilter.doFilter(this.request, this.response, this.filterChain); - verify(this.filterChain).doFilter(this.request, this.response); + then(this.filterChain).should().doFilter(this.request, this.response); } @Test @@ -119,8 +118,8 @@ class ErrorPageSecurityFilterTests { this.request.setDispatcherType(DispatcherType.REQUEST); given(this.privilegeEvaluator.isAllowed(anyString(), any())).willReturn(false); this.securityFilter.doFilter(this.request, this.response, this.filterChain); - verifyNoInteractions(this.privilegeEvaluator); - verify(this.filterChain).doFilter(this.request, this.response); + then(this.privilegeEvaluator).shouldHaveNoInteractions(); + then(this.filterChain).should().doFilter(this.request, this.response); } @Test @@ -133,7 +132,7 @@ class ErrorPageSecurityFilterTests { // Servlet mapped to / this.request.setServletPath("/error"); this.securityFilter.doFilter(this.request, this.response, this.filterChain); - verify(this.privilegeEvaluator).isAllowed(eq("/error"), any()); + then(this.privilegeEvaluator).should().isAllowed(eq("/error"), any()); } @Test @@ -146,7 +145,7 @@ class ErrorPageSecurityFilterTests { // Servlet mapped to /dispatcher/path/* this.request.setServletPath("/dispatcher/path"); this.securityFilter.doFilter(this.request, this.response, this.filterChain); - verify(this.privilegeEvaluator).isAllowed(eq("/dispatcher/path/error"), any()); + then(this.privilegeEvaluator).should().isAllowed(eq("/dispatcher/path/error"), any()); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java index f56d26a69d..26b23ded52 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -157,10 +157,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Base for testing classes that extends {@link AbstractServletWebServerFactory}. @@ -381,7 +381,7 @@ public abstract class AbstractServletWebServerFactoryTests { this.webServer.start(); InOrder ordered = inOrder((Object[]) initializers); for (ServletContextInitializer initializer : initializers) { - ordered.verify(initializer).onStartup(any(ServletContext.class)); + then(initializer).should(ordered).onStartup(any(ServletContext.class)); } } @@ -649,8 +649,8 @@ public abstract class AbstractServletWebServerFactoryTests { HttpClient httpClient = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).build(); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); assertThat(getResponse(getLocalUrl("https", "/test.txt"), requestFactory)).isEqualTo("test"); - verify(sslStoreProvider, atLeastOnce()).getKeyStore(); - verify(sslStoreProvider, atLeastOnce()).getTrustStore(); + then(sslStoreProvider).should(atLeastOnce()).getKeyStore(); + then(sslStoreProvider).should(atLeastOnce()).getTrustStore(); } @Test @@ -1094,7 +1094,7 @@ public abstract class AbstractServletWebServerFactoryTests { this.webServer = getFactory().getWebServer((servletContext) -> servletContext.addListener(listener)); this.webServer.start(); this.webServer.stop(); - verify(listener).contextDestroyed(any(ServletContextEvent.class)); + then(listener).should().contextDestroyed(any(ServletContextEvent.class)); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterTests.java index e3110ab02c..91a1473036 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,9 +52,9 @@ import org.springframework.web.util.NestedServletException; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link ErrorPageFilter}. @@ -339,7 +339,7 @@ class ErrorPageFilterTests { given(committedResponse.isCommitted()).willReturn(true); given(committedResponse.getStatus()).willReturn(200); this.filter.doFilter(this.request, committedResponse, this.chain); - verify(committedResponse, never()).flushBuffer(); + then(committedResponse).should(never()).flushBuffer(); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ServletContextApplicationContextInitializerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ServletContextApplicationContextInitializerTests.java index 557ddeb9d2..82ec8f217b 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ServletContextApplicationContextInitializerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ServletContextApplicationContextInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,9 @@ import org.junit.jupiter.api.Test; import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.WebApplicationContext; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; /** * Tests for {@link ServletContextApplicationContextInitializer}. @@ -41,20 +41,20 @@ class ServletContextApplicationContextInitializerTests { @Test void servletContextIsSetOnTheApplicationContext() { new ServletContextApplicationContextInitializer(this.servletContext).initialize(this.applicationContext); - verify(this.applicationContext).setServletContext(this.servletContext); + then(this.applicationContext).should().setServletContext(this.servletContext); } @Test void applicationContextIsNotStoredInServletContextByDefault() { new ServletContextApplicationContextInitializer(this.servletContext).initialize(this.applicationContext); - verify(this.servletContext, never()).setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, - this.applicationContext); + then(this.servletContext).should(never()) + .setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.applicationContext); } @Test void applicationContextCanBeStoredInServletContext() { new ServletContextApplicationContextInitializer(this.servletContext, true).initialize(this.applicationContext); - verify(this.servletContext).setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, + then(this.servletContext).should().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.applicationContext); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializerTests.java index eb4d3fa58a..84ac463bcb 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,8 +57,8 @@ import org.springframework.web.context.support.StandardServletEnvironment; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; /** * Tests for {@link SpringBootServletInitializer}. @@ -220,7 +220,7 @@ class SpringBootServletInitializerTests { }.onStartup(servletContext); ArgumentCaptor captor = ArgumentCaptor.forClass(ServletContextListener.class); - verify(servletContext).addListener(captor.capture()); + then(servletContext).should().addListener(captor.capture()); captor.getValue().contextDestroyed(new ServletContextEvent(servletContext)); assertThat(driversDeregistered).isTrue(); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderTests.java index 707e8e744b..550bc0f8c6 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,10 +44,9 @@ import org.springframework.ws.transport.http.HttpUrlConnectionMessageSender; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; /** * Tests for {@link WebServiceTemplateBuilder}. @@ -70,7 +69,7 @@ class WebServiceTemplateBuilderTests { void createWithCustomizersShouldApplyCustomizers() { WebServiceTemplateCustomizer customizer = mock(WebServiceTemplateCustomizer.class); WebServiceTemplate template = new WebServiceTemplateBuilder(customizer).build(); - verify(customizer).customize(template); + then(customizer).should().customize(template); } @Test @@ -220,14 +219,14 @@ class WebServiceTemplateBuilderTests { void customizersShouldApply() { WebServiceTemplateCustomizer customizer = mock(WebServiceTemplateCustomizer.class); WebServiceTemplate template = this.builder.customizers(customizer).build(); - verify(customizer).customize(template); + then(customizer).should().customize(template); } @Test void customizersShouldBeAppliedLast() { WebServiceTemplate template = spy(new WebServiceTemplate()); - this.builder - .additionalCustomizers(((webServiceTemplate) -> verify(webServiceTemplate).setMessageSenders(any()))); + this.builder.additionalCustomizers( + ((webServiceTemplate) -> then(webServiceTemplate).should().setMessageSenders(any()))); this.builder.configure(template); } @@ -237,8 +236,8 @@ class WebServiceTemplateBuilderTests { WebServiceTemplateCustomizer customizer2 = mock(WebServiceTemplateCustomizer.class); WebServiceTemplate template = this.builder.customizers(customizer1) .customizers(Collections.singleton(customizer2)).build(); - verifyNoInteractions(customizer1); - verify(customizer2).customize(template); + then(customizer1).shouldHaveNoInteractions(); + then(customizer2).should().customize(template); } @Test @@ -260,22 +259,22 @@ class WebServiceTemplateBuilderTests { WebServiceTemplateCustomizer customizer1 = mock(WebServiceTemplateCustomizer.class); WebServiceTemplateCustomizer customizer2 = mock(WebServiceTemplateCustomizer.class); WebServiceTemplate template = this.builder.customizers(customizer1).additionalCustomizers(customizer2).build(); - verify(customizer1).customize(template); - verify(customizer2).customize(template); + then(customizer1).should().customize(template); + then(customizer2).should().customize(template); } @Test void setCheckConnectionForFault() { WebServiceTemplate template = mock(WebServiceTemplate.class); this.builder.setCheckConnectionForFault(false).configure(template); - verify(template).setCheckConnectionForFault(false); + then(template).should().setCheckConnectionForFault(false); } @Test void setCheckConnectionForError() { WebServiceTemplate template = mock(WebServiceTemplate.class); this.builder.setCheckConnectionForError(false).configure(template); - verify(template).setCheckConnectionForError(false); + then(template).should().setCheckConnectionForError(false); } @@ -283,7 +282,7 @@ class WebServiceTemplateBuilderTests { void setTransformerFactoryClass() { WebServiceTemplate template = mock(WebServiceTemplate.class); this.builder.setTransformerFactoryClass(SAXTransformerFactory.class).configure(template); - verify(template).setTransformerFactoryClass(SAXTransformerFactory.class); + then(template).should().setTransformerFactoryClass(SAXTransformerFactory.class); } @Test diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/SpyBeanSampleDataJpaApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/SpyBeanSampleDataJpaApplicationTests.java index 6e59ee92e4..4e2e4b801c 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/SpyBeanSampleDataJpaApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/SpyBeanSampleDataJpaApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -58,7 +58,7 @@ class SpyBeanSampleDataJpaApplicationTests { @Test void testHome() throws Exception { this.mvc.perform(get("/")).andExpect(status().isOk()).andExpect(content().string("Bath")); - verify(this.repository).findByNameAndCountryAllIgnoringCase("Bath", "UK"); + then(this.repository).should().findByNameAndCountryAllIgnoringCase("Bath", "UK"); } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/test/java/smoketest/webservices/WebServiceServerTestSampleWsApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/test/java/smoketest/webservices/WebServiceServerTestSampleWsApplicationTests.java index 8b3882750e..35879f5b0d 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/test/java/smoketest/webservices/WebServiceServerTestSampleWsApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/test/java/smoketest/webservices/WebServiceServerTestSampleWsApplicationTests.java @@ -36,7 +36,7 @@ import org.springframework.ws.test.server.MockWebServiceClient; import org.springframework.ws.test.server.RequestCreators; import org.springframework.ws.test.server.ResponseMatchers; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.then; /** * Tests for {@link SampleWsApplicationTests} that use {@link WebServiceServerTest} and @@ -64,7 +64,8 @@ class WebServiceServerTestSampleWsApplicationTests { StreamSource source = new StreamSource(new StringReader(request)); this.client.sendRequest(RequestCreators.withPayload(source)).andExpect(ResponseMatchers.noFault()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - verify(this.service).bookHoliday(dateFormat.parse("2013-10-20"), dateFormat.parse("2013-11-22"), "John Doe"); + then(this.service).should().bookHoliday(dateFormat.parse("2013-10-20"), dateFormat.parse("2013-11-22"), + "John Doe"); } } diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index b9daaa1e1a..f0f1aa09ee 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -48,7 +48,7 @@ - +