Merge branch '2.7.x' into 3.0.x

Closes gh-37965
This commit is contained in:
Phillip Webb
2023-10-19 20:21:41 -07:00
28 changed files with 125 additions and 124 deletions

View File

@@ -35,9 +35,9 @@ import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
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.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Tests for {@link SpringApplicationShutdownHook}.
@@ -163,8 +163,7 @@ class SpringApplicationShutdownHookTests {
ConfigurableApplicationContext context = new GenericApplicationContext();
shutdownHook.registerApplicationContext(context);
context.refresh();
assertThatThrownBy(() -> shutdownHook.deregisterFailedApplicationContext(context))
.isInstanceOf(IllegalStateException.class);
assertThatIllegalStateException().isThrownBy(() -> shutdownHook.deregisterFailedApplicationContext(context));
assertThat(shutdownHook.isApplicationContextRegistered(context)).isTrue();
}
@@ -174,7 +173,7 @@ class SpringApplicationShutdownHookTests {
GenericApplicationContext context = new GenericApplicationContext();
shutdownHook.registerApplicationContext(context);
context.registerBean(FailingBean.class);
assertThatThrownBy(context::refresh).isInstanceOf(BeanCreationException.class);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(context::refresh);
assertThat(shutdownHook.isApplicationContextRegistered(context)).isTrue();
shutdownHook.deregisterFailedApplicationContext(context);
assertThat(shutdownHook.isApplicationContextRegistered(context)).isFalse();

View File

@@ -27,7 +27,8 @@ import org.springframework.boot.context.metrics.buffering.StartupTimeline.Timeli
import org.springframework.core.metrics.StartupStep;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Tests for {@link BufferingApplicationStartup}.
@@ -86,8 +87,8 @@ class BufferingApplicationStartupTests {
void startRecordingShouldFailIfEventsWereRecorded() {
BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(2);
applicationStartup.start("first").end();
assertThatThrownBy(applicationStartup::startRecording).isInstanceOf(IllegalStateException.class)
.hasMessage("Cannot restart recording once steps have been buffered.");
assertThatIllegalStateException().isThrownBy(applicationStartup::startRecording)
.withMessage("Cannot restart recording once steps have been buffered.");
}
@Test
@@ -95,8 +96,8 @@ class BufferingApplicationStartupTests {
BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(2);
StartupStep step = applicationStartup.start("first");
step.end();
assertThatThrownBy(() -> step.tag("name", "value")).isInstanceOf(IllegalStateException.class)
.hasMessage("StartupStep has already ended.");
assertThatIllegalStateException().isThrownBy(() -> step.tag("name", "value"))
.withMessage("StartupStep has already ended.");
}
@Test
@@ -104,7 +105,8 @@ class BufferingApplicationStartupTests {
BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(2);
StartupStep step = applicationStartup.start("first");
step.tag("name", "value");
assertThatThrownBy(() -> step.getTags().iterator().remove()).isInstanceOf(UnsupportedOperationException.class);
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> step.getTags().iterator().remove());
}
@Test // gh-25792

View File

@@ -101,6 +101,7 @@ import org.springframework.validation.Validator;
import org.springframework.validation.annotation.Validated;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatException;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.entry;
@@ -709,11 +710,10 @@ class ConfigurationPropertiesTests {
@Test
void loadWhenHasConfigurationPropertiesValidatorShouldApplyValidator() {
assertThatExceptionOfType(Exception.class).isThrownBy(() -> load(WithCustomValidatorConfiguration.class))
.satisfies((ex) -> {
assertThat(ex).hasCauseInstanceOf(BindException.class);
assertThat(ex.getCause()).hasCauseExactlyInstanceOf(BindValidationException.class);
});
assertThatException().isThrownBy(() -> load(WithCustomValidatorConfiguration.class)).satisfies((ex) -> {
assertThat(ex).hasCauseInstanceOf(BindException.class);
assertThat(ex.getCause()).hasCauseExactlyInstanceOf(BindValidationException.class);
});
}
@Test
@@ -726,7 +726,7 @@ class ConfigurationPropertiesTests {
@Test
void loadWhenConfigurationPropertiesIsAlsoValidatorShouldApplyValidator() {
assertThatExceptionOfType(Exception.class).isThrownBy(() -> load(ValidatorProperties.class)).satisfies((ex) -> {
assertThatException().isThrownBy(() -> load(ValidatorProperties.class)).satisfies((ex) -> {
assertThat(ex).hasCauseInstanceOf(BindException.class);
assertThat(ex.getCause()).hasCauseExactlyInstanceOf(BindValidationException.class);
});
@@ -734,8 +734,7 @@ class ConfigurationPropertiesTests {
@Test
void loadWhenConstructorBoundConfigurationPropertiesIsAlsoValidatorShouldApplyValidator() {
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> load(ValidatorConstructorBoundPropertiesConfiguration.class))
assertThatException().isThrownBy(() -> load(ValidatorConstructorBoundPropertiesConfiguration.class))
.satisfies((ex) -> {
assertThat(ex).hasCauseInstanceOf(BindException.class);
assertThat(ex.getCause()).hasCauseExactlyInstanceOf(BindValidationException.class);
@@ -909,8 +908,7 @@ class ConfigurationPropertiesTests {
Map<String, Object> source = new HashMap<>();
source.put("test.duration", "P12D");
sources.addLast(new MapPropertySource("test", source));
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> load(ConstructorParameterWithFormatConfiguration.class))
assertThatException().isThrownBy(() -> load(ConstructorParameterWithFormatConfiguration.class))
.havingCause()
.isInstanceOf(BindException.class);
}
@@ -921,8 +919,7 @@ class ConfigurationPropertiesTests {
Map<String, Object> source = new HashMap<>();
source.put("test.period", "P12D");
sources.addLast(new MapPropertySource("test", source));
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> load(ConstructorParameterWithFormatConfiguration.class))
assertThatException().isThrownBy(() -> load(ConstructorParameterWithFormatConfiguration.class))
.havingCause()
.isInstanceOf(BindException.class);
}
@@ -938,8 +935,7 @@ class ConfigurationPropertiesTests {
@Test
void loadWhenBindingToConstructorParametersShouldValidate() {
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> load(ConstructorParameterValidationConfiguration.class))
assertThatException().isThrownBy(() -> load(ConstructorParameterValidationConfiguration.class))
.satisfies((ex) -> {
assertThat(ex).hasCauseInstanceOf(BindException.class);
assertThat(ex.getCause()).hasCauseExactlyInstanceOf(BindValidationException.class);
@@ -3062,7 +3058,7 @@ class ConfigurationPropertiesTests {
@Bean
@ConfigurationPropertiesBinding
static Converter<ArrayList<?>, CustomList<?>> arrayListToCustomList() {
return new Converter<ArrayList<?>, CustomList<?>>() {
return new Converter<>() {
@Override
public CustomList<?> convert(ArrayList<?> source) {
@@ -3096,7 +3092,7 @@ class ConfigurationPropertiesTests {
@Bean
@ConfigurationPropertiesBinding
static Converter<ArrayList<?>, CustomList<?>> arrayListToCustomList() {
return new Converter<ArrayList<?>, CustomList<?>>() {
return new Converter<>() {
@Override
public CustomList<?> convert(ArrayList<?> source) {

View File

@@ -28,7 +28,7 @@ import org.springframework.boot.web.server.PortInUseException;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatException;
/**
* Integration tests for {@link FailureAnalyzers}.
@@ -40,7 +40,7 @@ class FailureAnalyzersIntegrationTests {
@Test
void analysisIsPerformed(CapturedOutput output) {
assertThatExceptionOfType(Exception.class)
assertThatException()
.isThrownBy(() -> new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).run());
assertThat(output).contains("APPLICATION FAILED TO START");
}

View File

@@ -25,7 +25,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.validation.annotation.Validated;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatException;
/**
* Tests for {@link ValidationExceptionFailureAnalyzer}
@@ -37,8 +37,7 @@ class JakartaApiValidationExceptionFailureAnalyzerTests {
@Test
void validatedPropertiesTest() {
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> new AnnotationConfigApplicationContext(TestConfiguration.class).close())
assertThatException().isThrownBy(() -> new AnnotationConfigApplicationContext(TestConfiguration.class).close())
.satisfies((ex) -> assertThat(new ValidationExceptionFailureAnalyzer().analyze(ex)).isNotNull());
}

View File

@@ -34,7 +34,7 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.jdbc.datasource.init.ScriptStatementFailedException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests for {@link DataSourceScriptDatabaseInitializer}.
@@ -82,7 +82,7 @@ class DataSourceScriptDatabaseInitializerTests
populator.setContinueOnError(false);
}
};
assertThatThrownBy(initializer::initializeDatabase).isInstanceOf(ScriptStatementFailedException.class);
assertThatExceptionOfType(ScriptStatementFailedException.class).isThrownBy(initializer::initializeDatabase);
}
@Override

View File

@@ -32,7 +32,7 @@ import org.springframework.context.support.StaticMessageSource;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.assertThatException;
/**
* Integration tests for {@link MessageSourceMessageInterpolator}.
@@ -85,8 +85,8 @@ class MessageSourceMessageInterpolatorIntegrationTests {
@Test
void recursion() {
assertThatThrownBy(() -> validate("recursion"))
.hasStackTraceContaining("Circular reference '{recursion -> middle -> recursion}'");
assertThatException().isThrownBy(() -> validate("recursion"))
.withStackTraceContaining("Circular reference '{recursion -> middle -> recursion}'");
}
@Test

View File

@@ -38,7 +38,7 @@ import org.springframework.boot.web.server.Ssl;
import org.springframework.boot.web.server.WebServerException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatNoException;
@@ -92,8 +92,7 @@ class SslServerCustomizerTests {
void configureSslWhenSslIsEnabledWithNoKeyStoreAndNotPkcs11ThrowsException() {
Ssl ssl = new Ssl();
SslServerCustomizer customizer = new SslServerCustomizer(null, ssl, null, null);
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> customizer.configureSsl(new SslContextFactory.Server(), ssl, null))
assertThatException().isThrownBy(() -> customizer.configureSsl(new SslContextFactory.Server(), ssl, null))
.satisfies((ex) -> {
assertThat(ex).isInstanceOf(WebServerException.class);
assertThat(ex).hasMessageContaining("Could not load key store 'null'");

View File

@@ -77,7 +77,7 @@ import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientRequestException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.assertThatException;
/**
* Base for testing classes that extends {@link AbstractReactiveWebServerFactory}.
@@ -210,7 +210,8 @@ public abstract class AbstractReactiveWebServerFactoryTests {
}
protected void assertThatSslWithInvalidAliasCallFails(ThrowingCallable call) {
assertThatThrownBy(call).hasStackTraceContaining("Keystore does not contain specified alias 'test-alias-404'");
assertThatException().isThrownBy(call)
.withStackTraceContaining("Keystore does not contain specified alias 'test-alias-404'");
}
protected ReactorClientHttpConnector buildTrustAllSslConnector() {
@@ -399,8 +400,8 @@ public abstract class AbstractReactiveWebServerFactoryTests {
@Test
void whenSslIsEnabledAndNoKeyStoreIsConfiguredThenServerFailsToStart() {
assertThatThrownBy(() -> testBasicSslWithKeyStore(null, null))
.hasMessageContaining("Could not load key store 'null'");
assertThatException().isThrownBy(() -> testBasicSslWithKeyStore(null, null))
.withMessageContaining("Could not load key store 'null'");
}
@Test

View File

@@ -26,7 +26,6 @@ import org.junit.jupiter.params.provider.ValueSource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Tests for {@link PrivateKeyParser}.
@@ -73,12 +72,12 @@ class PrivateKeyParserTests {
})
// @formatter:on
void shouldNotParseUnsupportedTraditionalPkcs1(String file) {
assertThatThrownBy(() -> PrivateKeyParser.parse("classpath:org/springframework/boot/web/server/pkcs1/" + file))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Error loading private key file")
.hasCauseInstanceOf(IllegalStateException.class)
.cause()
.hasMessageContaining("Unrecognized private key format");
assertThatIllegalStateException()
.isThrownBy(() -> PrivateKeyParser.parse("classpath:org/springframework/boot/web/server/pkcs1/" + file))
.withMessageContaining("Error loading private key file")
.withCauseInstanceOf(IllegalStateException.class)
.havingCause()
.withMessageContaining("Unrecognized private key format");
}
@ParameterizedTest
@@ -116,12 +115,12 @@ class PrivateKeyParserTests {
})
// @formatter:on
void shouldNotParseUnsupportedEcPkcs8(String file) {
assertThatThrownBy(() -> PrivateKeyParser.parse("classpath:org/springframework/boot/web/server/pkcs8/" + file))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Error loading private key file")
.hasCauseInstanceOf(IllegalStateException.class)
.cause()
.hasMessageContaining("Unrecognized private key format");
assertThatIllegalStateException()
.isThrownBy(() -> PrivateKeyParser.parse("classpath:org/springframework/boot/web/server/pkcs8/" + file))
.withMessageContaining("Error loading private key file")
.withCauseInstanceOf(IllegalStateException.class)
.havingCause()
.withMessageContaining("Unrecognized private key format");
}
@ParameterizedTest
@@ -187,12 +186,12 @@ class PrivateKeyParserTests {
})
// @formatter:on
void shouldNotParseUnsupportedEcSec1(String file) {
assertThatThrownBy(() -> PrivateKeyParser.parse("classpath:org/springframework/boot/web/server/sec1/" + file))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Error loading private key file")
.hasCauseInstanceOf(IllegalStateException.class)
.cause()
.hasMessageContaining("Unrecognized private key format");
assertThatIllegalStateException()
.isThrownBy(() -> PrivateKeyParser.parse("classpath:org/springframework/boot/web/server/sec1/" + file))
.withMessageContaining("Error loading private key file")
.withCauseInstanceOf(IllegalStateException.class)
.havingCause()
.withMessageContaining("Unrecognized private key format");
}
@Test

View File

@@ -24,7 +24,7 @@ import java.security.KeyStoreException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Tests for {@link SslConfigurationValidator}.
@@ -65,17 +65,17 @@ class SslConfigurationValidatorTests {
@Test
void validateKeyAliasWhenAliasNotFoundShouldThrowException() {
assertThatThrownBy(() -> SslConfigurationValidator.validateKeyAlias(this.keyStore, INVALID_ALIAS))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Keystore does not contain specified alias '" + INVALID_ALIAS + "'");
assertThatIllegalStateException()
.isThrownBy(() -> SslConfigurationValidator.validateKeyAlias(this.keyStore, INVALID_ALIAS))
.withMessage("Keystore does not contain specified alias '" + INVALID_ALIAS + "'");
}
@Test
void validateKeyAliasWhenKeyStoreThrowsExceptionOnContains() throws KeyStoreException {
KeyStore uninitializedKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
assertThatThrownBy(() -> SslConfigurationValidator.validateKeyAlias(uninitializedKeyStore, "alias"))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Could not determine if keystore contains alias 'alias'");
assertThatIllegalStateException()
.isThrownBy(() -> SslConfigurationValidator.validateKeyAlias(uninitializedKeyStore, "alias"))
.withMessage("Could not determine if keystore contains alias 'alias'");
}
}

View File

@@ -148,11 +148,11 @@ import org.springframework.util.FileCopyUtils;
import org.springframework.util.StreamUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatException;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIOException;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
@@ -473,7 +473,8 @@ public abstract class AbstractServletWebServerFactoryTests {
}
protected void assertThatSslWithInvalidAliasCallFails(ThrowingCallable call) {
assertThatThrownBy(call).hasStackTraceContaining("Keystore does not contain specified alias 'test-alias-404'");
assertThatException().isThrownBy(call)
.withStackTraceContaining("Keystore does not contain specified alias 'test-alias-404'");
}
@Test