mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Merge branch '3.1.x'
Closes gh-37967
This commit is contained in:
commit
d638bbb0ba
@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.build.mavenplugin.PluginXmlParser.Plugin;
|
||||
|
||||
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 PluginXmlParser}.
|
||||
@ -49,9 +49,9 @@ class PluginXmlParserTests {
|
||||
|
||||
@Test
|
||||
void parseNonExistingFileThrowException() {
|
||||
assertThatThrownBy(() -> this.parser.parse(new File("src/test/resources/nonexistent.xml")))
|
||||
.isInstanceOf(RuntimeException.class)
|
||||
.hasCauseInstanceOf(FileNotFoundException.class);
|
||||
assertThatExceptionOfType(RuntimeException.class)
|
||||
.isThrownBy(() -> this.parser.parse(new File("src/test/resources/nonexistent.xml")))
|
||||
.withCauseInstanceOf(FileNotFoundException.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||
|
||||
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.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@ -117,8 +117,8 @@ class HibernateMetricsAutoConfigurationTests {
|
||||
.withUserConfiguration(NonHibernateEntityManagerFactoryConfiguration.class)
|
||||
.run((context) -> {
|
||||
// ensure EntityManagerFactory is not a Hibernate SessionFactory
|
||||
assertThatThrownBy(() -> context.getBean(EntityManagerFactory.class).unwrap(SessionFactory.class))
|
||||
.isInstanceOf(PersistenceException.class);
|
||||
assertThatExceptionOfType(PersistenceException.class)
|
||||
.isThrownBy(() -> context.getBean(EntityManagerFactory.class).unwrap(SessionFactory.class));
|
||||
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
||||
assertThat(registry.find("hibernate.statements").meter()).isNull();
|
||||
});
|
||||
|
@ -52,7 +52,7 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
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.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@ -198,8 +198,8 @@ class ObservationAutoConfigurationTests {
|
||||
Observation.start("observation2", observationRegistry).stop();
|
||||
MeterRegistry meterRegistry = context.getBean(MeterRegistry.class);
|
||||
assertThat(meterRegistry.get("observation1").timer().count()).isOne();
|
||||
assertThatThrownBy(() -> meterRegistry.get("observation2").timer())
|
||||
.isInstanceOf(MeterNotFoundException.class);
|
||||
assertThatExceptionOfType(MeterNotFoundException.class)
|
||||
.isThrownBy(() -> meterRegistry.get("observation2").timer());
|
||||
});
|
||||
}
|
||||
|
||||
@ -329,8 +329,8 @@ class ObservationAutoConfigurationTests {
|
||||
ObservationRegistry observationRegistry = context.getBean(ObservationRegistry.class);
|
||||
Observation.start("spring.security.filterchains", observationRegistry).stop();
|
||||
MeterRegistry meterRegistry = context.getBean(MeterRegistry.class);
|
||||
assertThatThrownBy(() -> meterRegistry.get("spring.security.filterchains").timer())
|
||||
.isInstanceOf(MeterNotFoundException.class);
|
||||
assertThatExceptionOfType(MeterNotFoundException.class)
|
||||
.isThrownBy(() -> meterRegistry.get("spring.security.filterchains").timer());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThatException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@ -285,30 +285,33 @@ class BraveAutoConfigurationTests {
|
||||
this.contextRunner
|
||||
.withPropertyValues("management.tracing.propagation.type=W3C",
|
||||
"management.tracing.brave.span-joining-supported=true")
|
||||
.run((context) -> assertThatThrownBy(() -> context.getBean(Tracing.class)).rootCause()
|
||||
.run((context) -> assertThatException().isThrownBy(() -> context.getBean(Tracing.class))
|
||||
.havingRootCause()
|
||||
.isExactlyInstanceOf(IncompatibleConfigurationException.class)
|
||||
.hasMessage(
|
||||
"The following configuration properties have incompatible values: [management.tracing.propagation.type, management.tracing.brave.span-joining-supported]"));
|
||||
.withMessage("The following configuration properties have incompatible values: "
|
||||
+ "[management.tracing.propagation.type, management.tracing.brave.span-joining-supported]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailIfSupportJoinedSpansIsEnabledAndW3cIsChosenAsConsume() {
|
||||
this.contextRunner.withPropertyValues("management.tracing.propagation.produce=B3",
|
||||
"management.tracing.propagation.consume=W3C", "management.tracing.brave.span-joining-supported=true")
|
||||
.run((context) -> assertThatThrownBy(() -> context.getBean(Tracing.class)).rootCause()
|
||||
.run((context) -> assertThatException().isThrownBy(() -> context.getBean(Tracing.class))
|
||||
.havingRootCause()
|
||||
.isExactlyInstanceOf(IncompatibleConfigurationException.class)
|
||||
.hasMessage(
|
||||
"The following configuration properties have incompatible values: [management.tracing.propagation.consume, management.tracing.brave.span-joining-supported]"));
|
||||
.withMessage("The following configuration properties have incompatible values: "
|
||||
+ "[management.tracing.propagation.consume, management.tracing.brave.span-joining-supported]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailIfSupportJoinedSpansIsEnabledAndW3cIsChosenAsProduce() {
|
||||
this.contextRunner.withPropertyValues("management.tracing.propagation.consume=B3",
|
||||
"management.tracing.propagation.produce=W3C", "management.tracing.brave.span-joining-supported=true")
|
||||
.run((context) -> assertThatThrownBy(() -> context.getBean(Tracing.class)).rootCause()
|
||||
.run((context) -> assertThatException().isThrownBy(() -> context.getBean(Tracing.class))
|
||||
.havingRootCause()
|
||||
.isExactlyInstanceOf(IncompatibleConfigurationException.class)
|
||||
.hasMessage(
|
||||
"The following configuration properties have incompatible values: [management.tracing.propagation.produce, management.tracing.brave.span-joining-supported]"));
|
||||
.withMessage("The following configuration properties have incompatible values: "
|
||||
+ "[management.tracing.propagation.produce, management.tracing.brave.span-joining-supported]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -33,7 +33,7 @@ import zipkin2.reporter.ClosedSenderException;
|
||||
import zipkin2.reporter.Sender;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Abstract base test class which is used for testing the different implementations of the
|
||||
@ -60,8 +60,8 @@ abstract class ZipkinHttpSenderTests {
|
||||
@Test
|
||||
void sendSpansShouldThrowIfCloseWasCalled() throws IOException {
|
||||
this.sender.close();
|
||||
assertThatThrownBy(() -> this.sender.sendSpans(Collections.emptyList()))
|
||||
.isInstanceOf(ClosedSenderException.class);
|
||||
assertThatExceptionOfType(ClosedSenderException.class)
|
||||
.isThrownBy(() -> this.sender.sendSpans(Collections.emptyList()));
|
||||
}
|
||||
|
||||
protected void makeRequest(List<byte[]> encodedSpans, boolean async) throws IOException {
|
||||
|
@ -34,7 +34,7 @@ import org.springframework.test.web.client.MockRestServiceServer;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThatException;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.content;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
|
||||
@ -109,8 +109,8 @@ class ZipkinRestTemplateSenderTests extends ZipkinHttpSenderTests {
|
||||
assertThat(callbackResult.error()).isNotNull().hasMessageContaining("500 Internal Server Error");
|
||||
}
|
||||
else {
|
||||
assertThatThrownBy(() -> makeSyncRequest(Collections.emptyList()))
|
||||
.hasMessageContaining("500 Internal Server Error");
|
||||
assertThatException().isThrownBy(() -> makeSyncRequest(Collections.emptyList()))
|
||||
.withMessageContaining("500 Internal Server Error");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ import zipkin2.reporter.Sender;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThatException;
|
||||
|
||||
/**
|
||||
* Tests for {@link ZipkinWebClientSender}.
|
||||
@ -130,8 +130,8 @@ class ZipkinWebClientSenderTests extends ZipkinHttpSenderTests {
|
||||
assertThat(callbackResult.error()).isNotNull().hasMessageContaining("500 Internal Server Error");
|
||||
}
|
||||
else {
|
||||
assertThatThrownBy(() -> makeSyncRequest(Collections.emptyList()))
|
||||
.hasMessageContaining("500 Internal Server Error");
|
||||
assertThatException().isThrownBy(() -> makeSyncRequest(Collections.emptyList()))
|
||||
.withMessageContaining("500 Internal Server Error");
|
||||
}
|
||||
requestAssertions((request) -> assertThat(request.getMethod()).isEqualTo("POST"));
|
||||
}
|
||||
@ -165,8 +165,8 @@ class ZipkinWebClientSenderTests extends ZipkinHttpSenderTests {
|
||||
assertThat(callbackResult.error()).isNotNull().isInstanceOf(TimeoutException.class);
|
||||
}
|
||||
else {
|
||||
assertThatThrownBy(() -> makeSyncRequest(sender, Collections.emptyList()))
|
||||
.hasCauseInstanceOf(TimeoutException.class);
|
||||
assertThatException().isThrownBy(() -> makeSyncRequest(sender, Collections.emptyList()))
|
||||
.withCauseInstanceOf(TimeoutException.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontPropert
|
||||
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
|
||||
|
||||
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 WavefrontProperties}.
|
||||
@ -51,9 +51,9 @@ class WavefrontPropertiesTests {
|
||||
properties.setUri(URI.create("http://localhost:2878"));
|
||||
properties.setApiToken(null);
|
||||
assertThat(properties.getEffectiveUri()).isEqualTo(URI.create("http://localhost:2878"));
|
||||
assertThatThrownBy(properties::getApiTokenOrThrow)
|
||||
.isInstanceOf(InvalidConfigurationPropertyValueException.class)
|
||||
.hasMessageContaining("management.wavefront.api-token");
|
||||
assertThatExceptionOfType(InvalidConfigurationPropertyValueException.class)
|
||||
.isThrownBy(properties::getApiTokenOrThrow)
|
||||
.withMessageContaining("management.wavefront.api-token");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -26,7 +26,7 @@ import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
|
||||
|
||||
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 RabbitProperties}.
|
||||
@ -369,9 +369,9 @@ class RabbitPropertiesTests {
|
||||
void hostPropertyMustBeSingleHost() {
|
||||
this.properties.setHost("my-rmq-host.net,my-rmq-host-2.net");
|
||||
assertThat(this.properties.getHost()).isEqualTo("my-rmq-host.net,my-rmq-host-2.net");
|
||||
assertThatThrownBy(this.properties::determineAddresses)
|
||||
.isInstanceOf(InvalidConfigurationPropertyValueException.class)
|
||||
.hasMessageContaining("spring.rabbitmq.host");
|
||||
assertThatExceptionOfType(InvalidConfigurationPropertyValueException.class)
|
||||
.isThrownBy(this.properties::determineAddresses)
|
||||
.withMessageContaining("spring.rabbitmq.host");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import com.datastax.oss.driver.internal.core.session.throttling.PassThroughReque
|
||||
import com.datastax.oss.driver.internal.core.session.throttling.RateLimitingRequestThrottler;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration.PropertiesCassandraConnectionDetails;
|
||||
import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration;
|
||||
@ -42,7 +43,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatException;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link CassandraAutoConfiguration}
|
||||
@ -299,9 +300,10 @@ class CassandraAutoConfigurationTests {
|
||||
@Test
|
||||
void driverConfigLoaderWithRateLimitingRequiresExtraConfiguration() {
|
||||
this.contextRunner.withPropertyValues("spring.cassandra.request.throttler.type=rate-limiting")
|
||||
.run((context) -> assertThatThrownBy(() -> context.getBean(CqlSession.class))
|
||||
.hasMessageContaining("Error instantiating class RateLimitingRequestThrottler")
|
||||
.hasMessageContaining("No configuration setting found for key"));
|
||||
.run((context) -> assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> context.getBean(CqlSession.class))
|
||||
.withMessageContaining("Error instantiating class RateLimitingRequestThrottler")
|
||||
.withMessageContaining("No configuration setting found for key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -34,13 +34,14 @@ import org.testcontainers.images.builder.Transferable;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.testsupport.testcontainers.CassandraContainer;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
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 CassandraAutoConfiguration} that only uses password authentication.
|
||||
@ -77,8 +78,9 @@ class CassandraAutoConfigurationWithPasswordAuthenticationIntegrationTests {
|
||||
void authenticationWithInvalidCredentials() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cassandra.username=not-a-user", "spring.cassandra.password=invalid-password")
|
||||
.run((context) -> assertThatThrownBy(() -> context.getBean(CqlSession.class))
|
||||
.hasMessageContaining("Authentication error"));
|
||||
.run((context) -> assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> context.getBean(CqlSession.class))
|
||||
.withMessageContaining("Authentication error"));
|
||||
}
|
||||
|
||||
static final class PasswordAuthenticatorCassandraContainer extends CassandraContainer {
|
||||
|
@ -29,7 +29,7 @@ import org.springframework.context.annotation.ImportSelector;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
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 OnBeanCondition} when deduction of the bean's type fails
|
||||
@ -41,7 +41,7 @@ class OnBeanConditionTypeDeductionFailureTests {
|
||||
|
||||
@Test
|
||||
void conditionalOnMissingBeanWithDeducedTypeThatIsPartiallyMissingFromClassPath() {
|
||||
assertThatExceptionOfType(Exception.class)
|
||||
assertThatException()
|
||||
.isThrownBy(() -> new AnnotationConfigApplicationContext(ImportingConfiguration.class).close())
|
||||
.satisfies((ex) -> {
|
||||
Throwable beanTypeDeductionException = findNestedCause(ex, BeanTypeDeductionException.class);
|
||||
|
@ -34,7 +34,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@ -69,11 +69,11 @@ class IntegrationPropertiesEnvironmentPostProcessorTests {
|
||||
void registerIntegrationPropertiesPropertySourceWithUnknownResourceThrowsException() {
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
ClassPathResource unknown = new ClassPathResource("does-not-exist.properties", getClass());
|
||||
assertThatThrownBy(() -> new IntegrationPropertiesEnvironmentPostProcessor()
|
||||
.registerIntegrationPropertiesPropertySource(environment, unknown))
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.hasCauseInstanceOf(FileNotFoundException.class)
|
||||
.hasMessageContaining(unknown.toString());
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> new IntegrationPropertiesEnvironmentPostProcessor()
|
||||
.registerIntegrationPropertiesPropertySource(environment, unknown))
|
||||
.withCauseInstanceOf(FileNotFoundException.class)
|
||||
.withMessageContaining(unknown.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -75,7 +75,7 @@ import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
|
||||
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.entry;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@ -363,10 +363,10 @@ class JacksonAutoConfigurationTests {
|
||||
void disableDefaultLeniency() {
|
||||
this.contextRunner.withPropertyValues("spring.jackson.default-leniency:false").run((context) -> {
|
||||
ObjectMapper mapper = context.getBean(ObjectMapper.class);
|
||||
assertThatThrownBy(() -> mapper.readValue("{\"birthDate\": \"2010-12-30\"}", Person.class))
|
||||
.isInstanceOf(InvalidFormatException.class)
|
||||
.hasMessageContaining("expected format")
|
||||
.hasMessageContaining("yyyyMMdd");
|
||||
assertThatExceptionOfType(InvalidFormatException.class)
|
||||
.isThrownBy(() -> mapper.readValue("{\"birthDate\": \"2010-12-30\"}", Person.class))
|
||||
.withMessageContaining("expected format")
|
||||
.withMessageContaining("yyyyMMdd");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
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 ConditionEvaluationReportLoggingListener}.
|
||||
@ -67,7 +67,7 @@ class ConditionEvaluationReportLoggingListenerTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
context.register(ErrorConfig.class);
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(context::refresh)
|
||||
assertThatException().isThrownBy(context::refresh)
|
||||
.satisfies((ex) -> withDebugLogging(() -> context
|
||||
.publishEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex))));
|
||||
assertThat(output).contains("CONDITIONS EVALUATION REPORT");
|
||||
@ -78,7 +78,7 @@ class ConditionEvaluationReportLoggingListenerTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
context.register(ErrorConfig.class);
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(context::refresh)
|
||||
assertThatException().isThrownBy(context::refresh)
|
||||
.satisfies((ex) -> withInfoLogging(() -> context
|
||||
.publishEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex))));
|
||||
assertThat(output).doesNotContain("CONDITIONS EVALUATION REPORT")
|
||||
|
@ -24,8 +24,8 @@ import org.mockito.InOrder;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
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.assertThatThrownBy;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
@ -59,8 +59,8 @@ class ContextConsumerTests {
|
||||
given(predicate.test(24)).willReturn(false);
|
||||
ContextConsumer<ApplicationContext> firstConsumer = (context) -> assertThat(predicate.test(42)).isFalse();
|
||||
ContextConsumer<ApplicationContext> secondConsumer = (context) -> assertThat(predicate.test(24)).isFalse();
|
||||
assertThatThrownBy(() -> firstConsumer.andThen(secondConsumer).accept(mock(ApplicationContext.class)))
|
||||
.isInstanceOf(AssertionError.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> firstConsumer.andThen(secondConsumer).accept(mock(ApplicationContext.class)));
|
||||
then(predicate).should().test(42);
|
||||
then(predicate).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import org.springframework.boot.gradle.junit.GradleProjectBuilder;
|
||||
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThatException;
|
||||
|
||||
/**
|
||||
* Tests for {@link BuildInfo}.
|
||||
@ -167,8 +167,8 @@ class BuildInfoTests {
|
||||
@Test
|
||||
void nullAdditionalPropertyProducesInformativeFailure() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
assertThatThrownBy(() -> task.getProperties().getAdditional().put("a", null))
|
||||
.hasMessage("Cannot add an entry with a null value to a property of type Map.");
|
||||
assertThatException().isThrownBy(() -> task.getProperties().getAdditional().put("a", null))
|
||||
.withMessage("Cannot add an entry with a null value to a property of type Map.");
|
||||
}
|
||||
|
||||
private Project createProject(String projectName) {
|
||||
|
@ -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}.
|
||||
@ -186,8 +186,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();
|
||||
}
|
||||
|
||||
@ -197,7 +196,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();
|
||||
|
@ -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
|
||||
|
@ -102,6 +102,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;
|
||||
@ -722,11 +723,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
|
||||
@ -739,7 +739,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);
|
||||
});
|
||||
@ -747,8 +747,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);
|
||||
@ -922,8 +921,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);
|
||||
}
|
||||
@ -934,8 +932,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);
|
||||
}
|
||||
@ -951,8 +948,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);
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -31,7 +31,6 @@ 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;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@ -117,9 +116,9 @@ class DefaultSslBundleRegistryTests {
|
||||
|
||||
@Test
|
||||
void shouldFailIfUpdatingNonRegisteredBundle() {
|
||||
assertThatThrownBy(() -> this.registry.updateBundle("dummy", this.bundle1))
|
||||
.isInstanceOf(NoSuchSslBundleException.class)
|
||||
.hasMessageContaining("'dummy'");
|
||||
assertThatExceptionOfType(NoSuchSslBundleException.class)
|
||||
.isThrownBy(() -> this.registry.updateBundle("dummy", this.bundle1))
|
||||
.withMessageContaining("'dummy'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -30,7 +30,6 @@ import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
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 PemPrivateKeyParser}.
|
||||
@ -76,12 +75,12 @@ class PemPrivateKeyParserTests {
|
||||
})
|
||||
// @formatter:on
|
||||
void shouldNotParseUnsupportedTraditionalPkcs1(String file) {
|
||||
assertThatThrownBy(() -> PemPrivateKeyParser.parse(read("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(() -> PemPrivateKeyParser.parse(read("org/springframework/boot/web/server/pkcs1/" + file)))
|
||||
.withMessageContaining("Error loading private key file")
|
||||
.withCauseInstanceOf(IllegalStateException.class)
|
||||
.havingCause()
|
||||
.withMessageContaining("Unrecognized private key format");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ -119,12 +118,12 @@ class PemPrivateKeyParserTests {
|
||||
})
|
||||
// @formatter:on
|
||||
void shouldNotParseUnsupportedEcPkcs8(String file) {
|
||||
assertThatThrownBy(() -> PemPrivateKeyParser.parse(read("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(() -> PemPrivateKeyParser.parse(read("org/springframework/boot/web/server/pkcs8/" + file)))
|
||||
.withMessageContaining("Error loading private key file")
|
||||
.withCauseInstanceOf(IllegalStateException.class)
|
||||
.havingCause()
|
||||
.withMessageContaining("Unrecognized private key format");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ -190,12 +189,12 @@ class PemPrivateKeyParserTests {
|
||||
})
|
||||
// @formatter:on
|
||||
void shouldNotParseUnsupportedEcSec1(String file) {
|
||||
assertThatThrownBy(() -> PemPrivateKeyParser.parse(read("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(() -> PemPrivateKeyParser.parse(read("org/springframework/boot/web/server/sec1/" + file)))
|
||||
.withMessageContaining("Error loading private key file")
|
||||
.withCauseInstanceOf(IllegalStateException.class)
|
||||
.havingCause()
|
||||
.withMessageContaining("Unrecognized private key format");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -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
|
||||
|
@ -79,7 +79,6 @@ import org.springframework.web.reactive.function.client.WebClientRequestExceptio
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* Base for testing classes that extends {@link AbstractReactiveWebServerFactory}.
|
||||
@ -242,7 +241,8 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
}
|
||||
|
||||
protected void assertThatSslWithInvalidAliasCallFails(ThrowingCallable call) {
|
||||
assertThatThrownBy(call).hasStackTraceContaining("Keystore does not contain alias 'test-alias-404'");
|
||||
assertThatException().isThrownBy(call)
|
||||
.withStackTraceContaining("Keystore does not contain alias 'test-alias-404'");
|
||||
}
|
||||
|
||||
protected ReactorClientHttpConnector buildTrustAllSslConnector() {
|
||||
|
@ -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}.
|
||||
@ -66,17 +66,17 @@ class SslConfigurationValidatorTests {
|
||||
|
||||
@Test
|
||||
void validateKeyAliasWhenAliasNotFoundShouldThrowException() {
|
||||
assertThatThrownBy(() -> SslConfigurationValidator.validateKeyAlias(this.keyStore, INVALID_ALIAS))
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.hasMessage("Keystore does not contain alias '" + INVALID_ALIAS + "'");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> SslConfigurationValidator.validateKeyAlias(this.keyStore, INVALID_ALIAS))
|
||||
.withMessage("Keystore does not contain 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'");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import jakarta.servlet.DispatcherType;
|
||||
import jakarta.servlet.Filter;
|
||||
import jakarta.servlet.FilterRegistration;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
@ -34,7 +35,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@ -204,14 +205,16 @@ abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
void failsWithDoubleRegistration() {
|
||||
assertThatThrownBy(() -> {
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
bean.setName("double-registration");
|
||||
given(this.servletContext.addFilter(anyString(), any(Filter.class))).willReturn(null);
|
||||
bean.onStartup(this.servletContext);
|
||||
}).isInstanceOf(IllegalStateException.class)
|
||||
.hasMessage(
|
||||
"Failed to register 'filter double-registration' on the servlet context. Possibly already registered?");
|
||||
assertThatIllegalStateException().isThrownBy(() -> doubleRegistration())
|
||||
.withMessage("Failed to register 'filter double-registration' on the "
|
||||
+ "servlet context. Possibly already registered?");
|
||||
}
|
||||
|
||||
private void doubleRegistration() throws ServletException {
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
bean.setName("double-registration");
|
||||
given(this.servletContext.addFilter(anyString(), any(Filter.class))).willReturn(null);
|
||||
bean.onStartup(this.servletContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -24,6 +24,7 @@ import java.util.Map;
|
||||
|
||||
import jakarta.servlet.Servlet;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRegistration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@ -33,7 +34,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.boot.web.servlet.mock.MockServlet;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@ -68,14 +69,16 @@ class ServletRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
void failsWithDoubleRegistration() {
|
||||
assertThatThrownBy(() -> {
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<>(this.servlet);
|
||||
bean.setName("double-registration");
|
||||
given(this.servletContext.addServlet(anyString(), any(Servlet.class))).willReturn(null);
|
||||
bean.onStartup(this.servletContext);
|
||||
}).isInstanceOf(IllegalStateException.class)
|
||||
.hasMessage(
|
||||
"Failed to register 'servlet double-registration' on the servlet context. Possibly already registered?");
|
||||
assertThatIllegalStateException().isThrownBy(() -> doubleRegistration())
|
||||
.withMessage("Failed to register 'servlet double-registration' on "
|
||||
+ "the servlet context. Possibly already registered?");
|
||||
}
|
||||
|
||||
private void doubleRegistration() throws ServletException {
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<>(this.servlet);
|
||||
bean.setName("double-registration");
|
||||
given(this.servletContext.addServlet(anyString(), any(Servlet.class))).willReturn(null);
|
||||
bean.onStartup(this.servletContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -155,11 +155,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;
|
||||
@ -497,7 +497,8 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
}
|
||||
|
||||
protected void assertThatSslWithInvalidAliasCallFails(ThrowingCallable call) {
|
||||
assertThatThrownBy(call).hasStackTraceContaining("Keystore does not contain alias 'test-alias-404'");
|
||||
assertThatException().isThrownBy(call)
|
||||
.withStackTraceContaining("Keystore does not contain alias 'test-alias-404'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
package smoketest.test.web;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import smoketest.test.WelcomeCommandLineRunner;
|
||||
import smoketest.test.domain.VehicleIdentificationNumber;
|
||||
@ -31,6 +30,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@ -96,8 +96,8 @@ class UserVehicleControllerTests {
|
||||
@Test
|
||||
void welcomeCommandLineRunnerShouldNotBeAvailable() {
|
||||
// Since we're a @WebMvcTest WelcomeCommandLineRunner should not be available.
|
||||
Assertions.assertThatThrownBy(() -> this.applicationContext.getBean(WelcomeCommandLineRunner.class))
|
||||
.isInstanceOf(NoSuchBeanDefinitionException.class);
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.applicationContext.getBean(WelcomeCommandLineRunner.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user