Simplify AssertJ usage

See gh-28862
pull/29090/head
Stefano Cordio 3 years ago committed by Stephane Nicoll
parent b093ae0113
commit a5c56043b9

@ -233,7 +233,7 @@ class CloudFoundryActuatorAutoConfigurationTests {
ExposableWebEndpoint endpoint = endpoints.iterator().next();
assertThat(endpoint.getOperations()).hasSize(2);
WebOperation webOperation = findOperationWithRequestPath(endpoint, "health");
assertThat(webOperation).extracting("invoker").extracting("target")
assertThat(webOperation).extracting("invoker.target")
.isInstanceOf(CloudFoundryHealthEndpointWebExtension.class);
});
}

@ -34,6 +34,7 @@ import org.springframework.boot.actuate.endpoint.OperationArgumentResolver;
import org.springframework.boot.actuate.endpoint.SecurityContext;
import org.springframework.boot.actuate.endpoint.invoke.OperationInvoker;
import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.given;
@ -115,8 +116,7 @@ class CachingOperationInvokerTests {
Thread.sleep(10);
}
invokeWithUniquePrincipal(invoker);
assertThat(invoker).extracting("cachedResponses").asInstanceOf(InstanceOfAssertFactories.MAP)
.hasSizeLessThan(count);
assertThat(invoker).extracting("cachedResponses", as(InstanceOfAssertFactories.MAP)).hasSizeLessThan(count);
}
private void invokeWithUniquePrincipal(CachingOperationInvoker invoker) {

@ -58,7 +58,7 @@ class MetricsWebClientCustomizerTests {
this.clientBuilder.filters((filters) -> assertThat(filters).hasSize(1));
this.customizer.customize(this.clientBuilder);
this.clientBuilder.filters(
(filters) -> assertThat(filters).hasSize(1).first().isInstanceOf(MetricsWebClientFilterFunction.class));
(filters) -> assertThat(filters).singleElement().isInstanceOf(MetricsWebClientFilterFunction.class));
}
}

@ -39,6 +39,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@ -80,7 +81,7 @@ class CouchbaseAutoConfigurationTests {
expectedModuleIds.add(new JsonValueModule().getTypeId());
JsonSerializer serializer = env.jsonSerializer();
assertThat(serializer).extracting("wrapped").isInstanceOf(JacksonJsonSerializer.class)
.extracting("mapper").asInstanceOf(InstanceOfAssertFactories.type(ObjectMapper.class))
.extracting("mapper", as(InstanceOfAssertFactories.type(ObjectMapper.class)))
.extracting(ObjectMapper::getRegisteredModuleIds).isEqualTo(expectedModuleIds);
});
}

@ -276,8 +276,8 @@ class ReactiveElasticsearchRestClientAutoConfigurationTests {
void whenMaxInMemorySizeIsConfiguredThenUnderlyingWebClientHasCustomMaxInMemorySize(String prefix) {
this.contextRunner.withPropertyValues(prefix + "max-in-memory-size=1MB").run((context) -> {
WebClient client = configureWebClient(context.getBean(ClientConfiguration.class).getClientConfigurers());
assertThat(client).extracting("exchangeFunction").extracting("strategies").extracting("codecConfigurer")
.extracting("defaultCodecs").asInstanceOf(InstanceOfAssertFactories.type(DefaultCodecConfig.class))
assertThat(client).extracting("exchangeFunction.strategies.codecConfigurer.defaultCodecs")
.asInstanceOf(InstanceOfAssertFactories.type(DefaultCodecConfig.class))
.extracting(DefaultCodecConfig::maxInMemorySize).isEqualTo(1024 * 1024);
});
}

@ -161,8 +161,8 @@ class ElasticsearchRestClientAutoConfigurationTests {
RestClient client = context.getBean(RestHighLevelClient.class).getLowLevelClient();
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
.containsExactly("http://localhost:9200");
assertThat(client).extracting("client")
.extracting("credentialsProvider", InstanceOfAssertFactories.type(CredentialsProvider.class))
assertThat(client)
.extracting("client.credentialsProvider", InstanceOfAssertFactories.type(CredentialsProvider.class))
.satisfies((credentialsProvider) -> {
Credentials credentials = credentialsProvider.getCredentials(new AuthScope("localhost", 9200));
assertThat(credentials.getUserPrincipal().getName()).isEqualTo("user");
@ -177,8 +177,8 @@ class ElasticsearchRestClientAutoConfigurationTests {
RestClient client = context.getBean(RestHighLevelClient.class).getLowLevelClient();
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
.containsExactly("http://localhost:9200");
assertThat(client).extracting("client")
.extracting("credentialsProvider", InstanceOfAssertFactories.type(CredentialsProvider.class))
assertThat(client)
.extracting("client.credentialsProvider", InstanceOfAssertFactories.type(CredentialsProvider.class))
.satisfies((credentialsProvider) -> {
Credentials credentials = credentialsProvider.getCredentials(new AuthScope("localhost", 9200));
assertThat(credentials.getUserPrincipal().getName()).isEqualTo("user");
@ -194,8 +194,8 @@ class ElasticsearchRestClientAutoConfigurationTests {
RestClient client = context.getBean(RestHighLevelClient.class).getLowLevelClient();
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
.containsExactly("http://localhost:9200", "http://localhost:9201");
assertThat(client).extracting("client")
.extracting("credentialsProvider",
assertThat(client)
.extracting("client.credentialsProvider",
InstanceOfAssertFactories.type(CredentialsProvider.class))
.satisfies((credentialsProvider) -> {
Credentials uriCredentials = credentialsProvider

@ -74,8 +74,7 @@ class SendGridAutoConfigurationTests {
loadContext("spring.sendgrid.api-key:SG.SECRET-API-KEY", "spring.sendgrid.proxy.host:localhost",
"spring.sendgrid.proxy.port:5678");
SendGrid sendGrid = this.context.getBean(SendGrid.class);
assertThat(sendGrid).extracting("client").extracting("httpClient").extracting("routePlanner")
.isInstanceOf(DefaultProxyRoutePlanner.class);
assertThat(sendGrid).extracting("client.httpClient.routePlanner").isInstanceOf(DefaultProxyRoutePlanner.class);
}
private void loadContext(String... environment) {

@ -190,8 +190,7 @@ class SessionAutoConfigurationJdbcTests extends AbstractSessionAutoConfiguration
JdbcIndexedSessionRepository repository = validateSessionRepository(context,
JdbcIndexedSessionRepository.class);
DataSource sessionDataSource = context.getBean("sessionDataSource", DataSource.class);
assertThat(repository).extracting("jdbcOperations").extracting("dataSource")
.isEqualTo(sessionDataSource);
assertThat(repository).extracting("jdbcOperations.dataSource").isEqualTo(sessionDataSource);
assertThat(context.getBean(JdbcSessionDataSourceScriptDatabaseInitializer.class))
.hasFieldOrPropertyWithValue("dataSource", sessionDataSource);
assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(

@ -160,7 +160,7 @@ class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurationTest
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class)
.withPropertyValues("server.port=0").run((context) -> {
SessionRepositoryFilter<?> filter = context.getBean(SessionRepositoryFilter.class);
assertThat(filter).extracting("httpSessionIdResolver").extracting("cookieSerializer")
assertThat(filter).extracting("httpSessionIdResolver.cookieSerializer")
.isSameAs(context.getBean(DefaultCookieSerializer.class));
});
}

@ -131,7 +131,7 @@ class TransactionAutoConfigurationTests {
this.contextRunner.withUserConfiguration(SeveralPlatformTransactionManagersConfiguration.class)
.run((context) -> {
TransactionManagerCustomizers customizers = context.getBean(TransactionManagerCustomizers.class);
assertThat(customizers).extracting("customizers").asList().hasSize(1).first()
assertThat(customizers).extracting("customizers").asList().singleElement()
.isInstanceOf(TransactionProperties.class);
});
}

@ -304,8 +304,7 @@ class SpringApplicationBuilderTests {
}
};
SpringApplication application = applicationBuilder.build();
assertThat(application).isInstanceOf(CustomSpringApplication.class)
.asInstanceOf(InstanceOfAssertFactories.type(CustomSpringApplication.class))
assertThat(application).asInstanceOf(InstanceOfAssertFactories.type(CustomSpringApplication.class))
.satisfies((customApp) -> assertThat(customApp.resourceLoader).isEqualTo(resourceLoader));
}

@ -102,8 +102,7 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto
void defaultTomcatListeners() {
TomcatReactiveWebServerFactory factory = getFactory();
if (AprLifecycleListener.isAprAvailable()) {
assertThat(factory.getContextLifecycleListeners()).hasSize(1).first()
.isInstanceOf(AprLifecycleListener.class);
assertThat(factory.getContextLifecycleListeners()).singleElement().isInstanceOf(AprLifecycleListener.class);
}
else {
assertThat(factory.getContextLifecycleListeners()).isEmpty();

@ -135,8 +135,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory
void defaultTomcatListeners() {
TomcatServletWebServerFactory factory = getFactory();
if (AprLifecycleListener.isAprAvailable()) {
assertThat(factory.getContextLifecycleListeners()).hasSize(1).first()
.isInstanceOf(AprLifecycleListener.class);
assertThat(factory.getContextLifecycleListeners()).singleElement().isInstanceOf(AprLifecycleListener.class);
}
else {
assertThat(factory.getContextLifecycleListeners()).isEmpty();

Loading…
Cancel
Save