Merge branch '2.5.x' into 2.6.x

Closes gh-29612
pull/30003/head
Stephane Nicoll 3 years ago
commit 136b5959c3

@ -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<Token> 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<Token> 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);

@ -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

@ -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<ExposableJmxEndpoint> 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");
});

@ -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)

@ -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)

@ -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) {

@ -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

@ -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);
});
}

@ -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<RepositoryFactoryCustomizer> 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

@ -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);
});
}

@ -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);
});
}

@ -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);
}
}

@ -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) {

@ -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<Map<String, Object>>) 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<Map<String, Object>>) health.getDetails().get("endpoints")).hasSize(2);
verify(cluster).diagnostics();
then(cluster).should().diagnostics();
}
}

@ -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<Map<String, Object>>) 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<Map<String, Object>>) health.getDetails().get("endpoints")).hasSize(2);
verify(cluster).diagnostics();
then(cluster).should().diagnostics();
}
}

@ -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

@ -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

@ -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,10 +38,9 @@ import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
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 {

@ -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

@ -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<String> 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

@ -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");
}

@ -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) {

@ -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<T extends Configurable
void writeOperationWithVoidResponse() {
load(VoidWriteResponseEndpointConfiguration.class, (context, client) -> {
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<T extends Configurable
void deleteOperationWithVoidResponse() {
load(VoidDeleteResponseEndpointConfiguration.class, (context, client) -> {
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<T extends Configurable
Map<String, Object> 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<T extends Configurable
load(TestEndpointConfiguration.class, (context, client) -> {
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);
});
}

@ -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();
}
}

@ -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();
}
}

@ -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

@ -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

@ -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<String>) any());
then(ldapTemplate).should().executeReadOnly((ContextExecutor<String>) 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<String>) any());
then(ldapTemplate).should().executeReadOnly((ContextExecutor<String>) any());
}
}

@ -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);
}
}

@ -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

@ -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();
}

@ -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);
}

@ -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 }");
}
}

@ -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

@ -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

@ -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 {

@ -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) {

@ -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> health = healthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> assertThat(h.getStatus()).isEqualTo(Status.DOWN))
.verifyComplete();
verify(redisConnection).closeLater();
then(redisConnection).should().closeLater();
}
@Test

@ -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<AuditApplicationEvent> 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();
}

@ -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<AuditApplicationEvent> 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();
}

@ -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());
}
}

@ -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,

@ -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> metadataReaderFactory = ArgumentCaptor
.forClass(MetadataReaderFactory.class);
verify(configurationAnnotationPostProcessor).setMetadataReaderFactory(metadataReaderFactory.capture());
then(configurationAnnotationPostProcessor).should().setMetadataReaderFactory(metadataReaderFactory.capture());
assertThat(metadataReaderFactory.getValue())
.isInstanceOf(ConcurrentReferenceCachingMetadataReaderFactory.class);
}

@ -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)));
}

@ -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,9 +35,8 @@ import org.springframework.rabbit.stream.listener.ConsumerCustomizer;
import org.springframework.rabbit.stream.listener.StreamListenerContainer;
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}.
@ -61,7 +60,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);
});
}
@ -99,12 +98,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
@ -113,7 +112,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
@ -122,7 +121,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
@ -132,8 +131,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
@ -145,8 +144,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");
}
@Configuration(proxyBeanMethods = false)

@ -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();
}
}

@ -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();
}
}

@ -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();
});
}

@ -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();
});
}

@ -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> 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);
}

@ -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.
@ -46,8 +46,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}.
@ -257,7 +257,7 @@ class ElasticsearchRestClientAutoConfigurationTests {
assertThat(context).hasSingleBean(Sniffer.class);
Sniffer sniffer = context.getBean(Sniffer.class);
assertThat(sniffer).isSameAs(customSniffer);
verifyNoInteractions(customSniffer);
then(customSniffer).shouldHaveNoInteractions();
});
}

@ -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));
});
}

@ -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();
}
}

@ -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();
}
}

@ -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<RuntimeException> 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() {

@ -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

@ -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.
@ -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<String>) 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);
});
}

@ -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();
});
}

@ -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<T> {
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

@ -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<AssertableApplicationContext> assertDefaultDdlAutoNotInvoked(String expectedDdlAuto) {
return assertHibernateProperties((hibernateProperties) -> {
assertThat(hibernateProperties).containsEntry(AvailableSettings.HBM2DDL_AUTO, expectedDdlAuto);
verify(this.ddlAutoSupplier, never()).get();
then(this.ddlAutoSupplier).should(never()).get();
});
}

@ -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();
});
}

@ -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

@ -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("##", "--");
}
}

@ -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();
}
}

@ -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();
}
}

@ -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");
});
}

@ -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<Duration> fallback = mock(Supplier.class);
assertThat(properties.determineTimeout(fallback)).isEqualTo(Duration.ofMinutes(1));
verifyNoInteractions(fallback);
then(fallback).shouldHaveNoInteractions();
}
@Test

@ -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);
});
}

@ -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);
}

@ -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();
});
}

@ -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);
});
}

@ -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

@ -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,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}.
@ -74,14 +74,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
@ -89,7 +89,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
@ -98,7 +98,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
@ -127,7 +127,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();
@ -140,10 +140,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<ChannelOption<?>, ?> options = httpServer.configuration().options();
@ -152,10 +152,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();

@ -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> T boundServerOption(Option<T> option) {

@ -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));
});
}

@ -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<Shutdown> shutdownCaptor = ArgumentCaptor.forClass(Shutdown.class);
verify(factory).setShutdown(shutdownCaptor.capture());
then(factory).should().setShutdown(shutdownCaptor.capture());
assertThat(shutdownCaptor.getValue()).isEqualTo(Shutdown.GRACEFUL);
}

@ -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));
});
}

@ -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));
});
}

@ -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));
});
}

@ -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)

@ -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<Session> 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<Session> 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<Shutdown> shutdownCaptor = ArgumentCaptor.forClass(Shutdown.class);
verify(factory).setShutdown(shutdownCaptor.capture());
then(factory).should().setShutdown(shutdownCaptor.capture());
assertThat(shutdownCaptor.getValue()).isEqualTo(Shutdown.GRACEFUL);
}

@ -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();
}

@ -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);

@ -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

@ -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);
}

@ -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/");
}

@ -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

@ -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())

@ -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<DataSource> 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;
}

@ -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");
}
}

@ -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

@ -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

@ -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();
}
}

@ -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);

@ -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

@ -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();
}
}

@ -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

@ -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();

@ -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);
}
}

@ -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) {

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save