From e0a3fe0a033f7bc0f4a63b93ae3b096517dd8b52 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Thu, 7 Dec 2023 10:16:02 +0800 Subject: [PATCH] Use idiomatic AssertJ assertions 1. Replace assertThat(x.isEmpty()).isTrue() with assertThat(x).isEmpty() Search for : assertThat\((.+).isEmpty\(\)\).isTrue\(\) Replace with : assertThat($1).isEmpty() Search for : assertThat\((.+).isEmpty\(\)\).isFalse\(\) Replace with : assertThat($1).isNotEmpty() 2. Replace assertThat(x.iterator().next()) with assertThat(x).element(0) Search for : assertThat\((.+).iterator\(\).next\(\)\) Replace with : assertThat($1).element(0) 3. Replace assertThat(x.get(i)). with assertThat(x).element(i). Search for : assertThat\((.+)\.get\((\d+)\)\)\. Replace with : assertThat($1).element($2). --- .../ObservationAutoConfigurationTests.java | 14 ++-- .../ObservationHandlerGroupingTests.java | 8 +-- ...mentWebSecurityAutoConfigurationTests.java | 4 +- ...crometerTracingAutoConfigurationTests.java | 2 +- ...rtiesReportEndpointSerializationTests.java | 2 +- ...gurationPropertiesReportEndpointTests.java | 4 +- .../cache/CacheAutoConfigurationTests.java | 2 +- .../http/HttpMessageConvertersTests.java | 8 +-- .../codec/CodecsAutoConfigurationTests.java | 2 +- .../jms/activemq/ActiveMQPropertiesTests.java | 2 +- .../RestTemplateAutoConfigurationTests.java | 6 +- .../HttpEncodingAutoConfigurationTests.java | 4 +- .../servlet/WebMvcAutoConfigurationTests.java | 4 +- .../livereload/LiveReloadServerTests.java | 8 +-- .../build/BuildpackResolversTests.java | 8 +-- .../platform/docker/LogUpdateEventTests.java | 6 +- .../boot/loader/jar/StringSequenceTests.java | 4 +- .../launch/PropertiesLauncherTests.java | 2 +- .../boot/maven/DependencyFilterMojoTests.java | 4 +- .../boot/maven/ExcludeFilterTests.java | 10 +-- .../boot/maven/IncludeFilterTests.java | 4 +- .../ConfigDataLocationResolversTests.java | 12 ++-- .../ConversionServiceDeducerTests.java | 6 +- .../bind/CollectionBinderTests.java | 4 +- ...rrentlyInCreationFailureAnalyzerTests.java | 64 +++++++++++-------- ...PostProcessorApplicationListenerTests.java | 2 +- ...EnvironmentPostProcessorsFactoryTests.java | 4 +- .../boot/json/AbstractJsonParserTests.java | 4 +- .../boot/util/InstantiatorTests.java | 4 +- 29 files changed, 110 insertions(+), 98 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java index 16b837042245..927c5bdaec15 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationAutoConfigurationTests.java @@ -249,11 +249,11 @@ void autoConfiguresObservationHandlers() { assertThat(handlers).hasSize(2); // Multiple MeterObservationHandler are wrapped in // FirstMatchingCompositeObservationHandler, which calls only the first one - assertThat(handlers.get(0)).isInstanceOf(CustomMeterObservationHandler.class); + assertThat(handlers).element(0).isInstanceOf(CustomMeterObservationHandler.class); assertThat(((CustomMeterObservationHandler) handlers.get(0)).getName()) .isEqualTo("customMeterObservationHandler1"); // Regular handlers are registered last - assertThat(handlers.get(1)).isInstanceOf(CustomObservationHandler.class); + assertThat(handlers).element(1).isInstanceOf(CustomObservationHandler.class); assertThat(context).doesNotHaveBean(DefaultMeterObservationHandler.class); assertThat(context).doesNotHaveBean(TracingAwareMeterObservationHandler.class); }); @@ -268,7 +268,7 @@ void autoConfiguresObservationHandlerWithCustomContext() { CustomContext customContext = new CustomContext(); Observation.start("test-observation", () -> customContext, observationRegistry).stop(); assertThat(handlers).hasSize(1); - assertThat(handlers.get(0)).isInstanceOf(ObservationHandlerWithCustomContext.class); + assertThat(handlers).element(0).isInstanceOf(ObservationHandlerWithCustomContext.class); assertThat(context).hasSingleBean(DefaultMeterObservationHandler.class); assertThat(context).doesNotHaveBean(TracingAwareMeterObservationHandler.class); }); @@ -283,7 +283,7 @@ void autoConfiguresTracingAwareMeterObservationHandler() { // TracingAwareMeterObservationHandler that we don't test here Observation.start("test-observation", observationRegistry); assertThat(handlers).hasSize(1); - assertThat(handlers.get(0)).isInstanceOf(CustomTracingObservationHandler.class); + assertThat(handlers).element(0).isInstanceOf(CustomTracingObservationHandler.class); assertThat(context).hasSingleBean(TracingAwareMeterObservationHandler.class); assertThat(context.getBeansOfType(ObservationHandler.class)).hasSize(2); }); @@ -298,16 +298,16 @@ void autoConfiguresObservationHandlerWhenTracingIsActive() { assertThat(handlers).hasSize(3); // Multiple TracingObservationHandler are wrapped in // FirstMatchingCompositeObservationHandler, which calls only the first one - assertThat(handlers.get(0)).isInstanceOf(CustomTracingObservationHandler.class); + assertThat(handlers).element(0).isInstanceOf(CustomTracingObservationHandler.class); assertThat(((CustomTracingObservationHandler) handlers.get(0)).getName()) .isEqualTo("customTracingHandler1"); // Multiple MeterObservationHandler are wrapped in // FirstMatchingCompositeObservationHandler, which calls only the first one - assertThat(handlers.get(1)).isInstanceOf(CustomMeterObservationHandler.class); + assertThat(handlers).element(1).isInstanceOf(CustomMeterObservationHandler.class); assertThat(((CustomMeterObservationHandler) handlers.get(1)).getName()) .isEqualTo("customMeterObservationHandler1"); // Regular handlers are registered last - assertThat(handlers.get(2)).isInstanceOf(CustomObservationHandler.class); + assertThat(handlers).element(2).isInstanceOf(CustomObservationHandler.class); assertThat(context).doesNotHaveBean(TracingAwareMeterObservationHandler.class); assertThat(context).doesNotHaveBean(DefaultMeterObservationHandler.class); }); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationHandlerGroupingTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationHandlerGroupingTests.java index b42d0a155c81..a9319a2e6303 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationHandlerGroupingTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/observation/ObservationHandlerGroupingTests.java @@ -50,12 +50,12 @@ void shouldGroupCategoriesIntoFirstMatchingHandlerAndRespectCategoryOrder() { List> handlers = getObservationHandlers(config); assertThat(handlers).hasSize(2); // Category A is first - assertThat(handlers.get(0)).isInstanceOf(FirstMatchingCompositeObservationHandler.class); + assertThat(handlers).element(0).isInstanceOf(FirstMatchingCompositeObservationHandler.class); FirstMatchingCompositeObservationHandler firstMatching0 = (FirstMatchingCompositeObservationHandler) handlers .get(0); assertThat(firstMatching0.getHandlers()).containsExactly(handlerA1, handlerA2); // Category B is second - assertThat(handlers.get(1)).isInstanceOf(FirstMatchingCompositeObservationHandler.class); + assertThat(handlers).element(1).isInstanceOf(FirstMatchingCompositeObservationHandler.class); FirstMatchingCompositeObservationHandler firstMatching1 = (FirstMatchingCompositeObservationHandler) handlers .get(1); assertThat(firstMatching1.getHandlers()).containsExactly(handlerB1, handlerB2); @@ -72,12 +72,12 @@ void uncategorizedHandlersShouldBeOrderedAfterCategories() { List> handlers = getObservationHandlers(config); assertThat(handlers).hasSize(2); // Category A is first - assertThat(handlers.get(0)).isInstanceOf(FirstMatchingCompositeObservationHandler.class); + assertThat(handlers).element(0).isInstanceOf(FirstMatchingCompositeObservationHandler.class); FirstMatchingCompositeObservationHandler firstMatching0 = (FirstMatchingCompositeObservationHandler) handlers .get(0); // Uncategorized handlers follow assertThat(firstMatching0.getHandlers()).containsExactly(handlerA1, handlerA2); - assertThat(handlers.get(1)).isEqualTo(handlerB1); + assertThat(handlers).element(1).isEqualTo(handlerB1); } @SuppressWarnings("unchecked") diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/reactive/ReactiveManagementWebSecurityAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/reactive/ReactiveManagementWebSecurityAutoConfigurationTests.java index e41082b893a4..4c59cb042018 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/reactive/ReactiveManagementWebSecurityAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/reactive/ReactiveManagementWebSecurityAutoConfigurationTests.java @@ -82,7 +82,7 @@ void permitAllForHealth() { @Test void securesEverythingElse() { this.contextRunner.run((context) -> { - assertThat(getAuthenticateHeader(context, "/actuator").get(0)).contains("Basic realm="); + assertThat(getAuthenticateHeader(context, "/actuator")).element(0).asString().contains("Basic realm="); assertThat(getAuthenticateHeader(context, "/foo").toString()).contains("Basic realm="); }); } @@ -91,7 +91,7 @@ void securesEverythingElse() { void usesMatchersBasedOffConfiguredActuatorBasePath() { this.contextRunner.withPropertyValues("management.endpoints.web.base-path=/").run((context) -> { assertThat(getAuthenticateHeader(context, "/health")).isNull(); - assertThat(getAuthenticateHeader(context, "/foo").get(0)).contains("Basic realm="); + assertThat(getAuthenticateHeader(context, "/foo")).element(0).asString().contains("Basic realm="); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfigurationTests.java index 9c6c61f6f012..f498648c70a9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/MicrometerTracingAutoConfigurationTests.java @@ -80,7 +80,7 @@ void shouldSupplyBeansInCorrectOrder() { .isInstanceOf(PropagatingReceiverTracingObservationHandler.class); assertThat(tracingObservationHandlers.get(1)) .isInstanceOf(PropagatingSenderTracingObservationHandler.class); - assertThat(tracingObservationHandlers.get(2)).isInstanceOf(DefaultTracingObservationHandler.class); + assertThat(tracingObservationHandlers).element(2).isInstanceOf(DefaultTracingObservationHandler.class); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointSerializationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointSerializationTests.java index 3acea77a8b68..e98d2798e519 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointSerializationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointSerializationTests.java @@ -203,7 +203,7 @@ void testList() { Map map = foo.getProperties(); assertThat(map).isNotNull(); assertThat(map).hasSize(3); - assertThat(((List) map.get("list")).get(0)).isEqualTo("foo"); + assertThat(((List) map.get("list"))).element(0).isEqualTo("foo"); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointTests.java index 8180021e5f88..378867075678 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointTests.java @@ -127,8 +127,8 @@ void descriptorWithSimpleList() { assertThat(properties.get("simpleList")).isInstanceOf(List.class); List list = (List) properties.get("simpleList"); assertThat(list).hasSize(2); - assertThat(list.get(0)).isEqualTo("a"); - assertThat(list.get(1)).isEqualTo("b"); + assertThat(list).element(0).isEqualTo("a"); + assertThat(list).element(1).isEqualTo("b"); }, (inputs) -> { List list = (List) inputs.get("simpleList"); assertThat(list).hasSize(2); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java index 9a84e99eb3d3..c6e59f205401 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java @@ -762,7 +762,7 @@ void autoConfiguredCacheManagerCanBeSwapped() { getCacheManager(context, SimpleCacheManager.class); CacheManagerPostProcessor postProcessor = context.getBean(CacheManagerPostProcessor.class); assertThat(postProcessor.cacheManagers).hasSize(1); - assertThat(postProcessor.cacheManagers.get(0)).isInstanceOf(CaffeineCacheManager.class); + assertThat(postProcessor.cacheManagers).element(0).isInstanceOf(CaffeineCacheManager.class); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java index 4a93124f2d5e..de86ac8929fe 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java @@ -93,8 +93,8 @@ void addNewConverters() { HttpMessageConverter converter1 = mock(HttpMessageConverter.class); HttpMessageConverter converter2 = mock(HttpMessageConverter.class); HttpMessageConverters converters = new HttpMessageConverters(converter1, converter2); - assertThat(converters.getConverters().get(0)).isEqualTo(converter1); - assertThat(converters.getConverters().get(1)).isEqualTo(converter2); + assertThat(converters.getConverters()).element(0).isEqualTo(converter1); + assertThat(converters.getConverters()).element(1).isEqualTo(converter2); } @Test @@ -103,8 +103,8 @@ void convertersAreAddedToFormPartConverter() { HttpMessageConverter converter2 = mock(HttpMessageConverter.class); List> converters = new HttpMessageConverters(converter1, converter2).getConverters(); List> partConverters = extractFormPartConverters(converters); - assertThat(partConverters.get(0)).isEqualTo(converter1); - assertThat(partConverters.get(1)).isEqualTo(converter2); + assertThat(partConverters).element(0).isEqualTo(converter1); + assertThat(partConverters).element(1).isEqualTo(converter2); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/codec/CodecsAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/codec/CodecsAutoConfigurationTests.java index a32ee3da12e7..ef855e26e9e7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/codec/CodecsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/codec/CodecsAutoConfigurationTests.java @@ -95,7 +95,7 @@ void userProvidedCustomizerCanOverrideJacksonCodecCustomizer() { .run((context) -> { List codecCustomizers = context.getBean(CodecCustomizers.class).codecCustomizers; assertThat(codecCustomizers).hasSize(3); - assertThat(codecCustomizers.get(2)).isInstanceOf(TestCodecCustomizer.class); + assertThat(codecCustomizers).element(2).isInstanceOf(TestCodecCustomizer.class); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java index a839b4d03d89..1df4f4f593eb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java @@ -63,7 +63,7 @@ void setTrustedPackages() { .createConnectionFactory(ActiveMQConnectionFactory.class); assertThat(factory.isTrustAllPackages()).isFalse(); assertThat(factory.getTrustedPackages()).hasSize(1); - assertThat(factory.getTrustedPackages().get(0)).isEqualTo("trusted.package"); + assertThat(factory.getTrustedPackages()).element(0).isEqualTo("trusted.package"); } private ActiveMQConnectionFactoryFactory createFactory(ActiveMQProperties properties) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java index 582752925976..bd45bba25ce4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java @@ -136,7 +136,8 @@ void restTemplateWhenHasCustomBuilderShouldUseCustomBuilder() { assertThat(context).hasSingleBean(RestTemplate.class); RestTemplate restTemplate = context.getBean(RestTemplate.class); assertThat(restTemplate.getMessageConverters()).hasSize(1); - assertThat(restTemplate.getMessageConverters().get(0)).isInstanceOf(CustomHttpMessageConverter.class); + assertThat(restTemplate.getMessageConverters()).element(0) + .isInstanceOf(CustomHttpMessageConverter.class); then(context.getBean(RestTemplateCustomizer.class)).shouldHaveNoInteractions(); }); } @@ -150,7 +151,8 @@ void restTemplateWhenHasCustomBuilderCouldReuseBuilderConfigurer() { assertThat(context).hasSingleBean(RestTemplate.class); RestTemplate restTemplate = context.getBean(RestTemplate.class); assertThat(restTemplate.getMessageConverters()).hasSize(1); - assertThat(restTemplate.getMessageConverters().get(0)).isInstanceOf(CustomHttpMessageConverter.class); + assertThat(restTemplate.getMessageConverters()).element(0) + .isInstanceOf(CustomHttpMessageConverter.class); RestTemplateCustomizer customizer = context.getBean(RestTemplateCustomizer.class); then(customizer).should().customize(restTemplate); }); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/HttpEncodingAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/HttpEncodingAutoConfigurationTests.java index cde862aba143..11086e4182de 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/HttpEncodingAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/HttpEncodingAutoConfigurationTests.java @@ -124,8 +124,8 @@ void filterIsOrderedHighest() { load(OrderedConfiguration.class); List beans = new ArrayList<>(this.context.getBeansOfType(Filter.class).values()); AnnotationAwareOrderComparator.sort(beans); - assertThat(beans.get(0)).isInstanceOf(CharacterEncodingFilter.class); - assertThat(beans.get(1)).isInstanceOf(HiddenHttpMethodFilter.class); + assertThat(beans).element(0).isInstanceOf(CharacterEncodingFilter.class); + assertThat(beans).element(1).isInstanceOf(HiddenHttpMethodFilter.class); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java index 7ccc5e12bff4..9afff8f2cf22 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java @@ -219,7 +219,7 @@ void resourceHandlerMappingOverrideWebjars() { this.contextRunner.withUserConfiguration(WebJars.class).run((context) -> { Map> locations = getResourceMappingLocations(context); assertThat(locations.get("/webjars/**")).hasSize(1); - assertThat(locations.get("/webjars/**").get(0)).isEqualTo(new ClassPathResource("/foo/")); + assertThat(locations.get("/webjars/**")).element(0).isEqualTo(new ClassPathResource("/foo/")); }); } @@ -228,7 +228,7 @@ void resourceHandlerMappingOverrideAll() { this.contextRunner.withUserConfiguration(AllResources.class).run((context) -> { Map> locations = getResourceMappingLocations(context); assertThat(locations.get("/**")).hasSize(1); - assertThat(locations.get("/**").get(0)).isEqualTo(new ClassPathResource("/foo/")); + assertThat(locations.get("/**")).element(0).isEqualTo(new ClassPathResource("/foo/")); }); } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java index 2211602fcbc8..791ddb9c736b 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java @@ -115,8 +115,8 @@ void triggerReload() throws Exception { this.server.triggerReload(); List messages = await().atMost(Duration.ofSeconds(10)) .until(handler::getMessages, (msgs) -> msgs.size() == 2); - assertThat(messages.get(0)).contains("http://livereload.com/protocols/official-7"); - assertThat(messages.get(1)).contains("command\":\"reload\""); + assertThat(messages).element(0).asString().contains("http://livereload.com/protocols/official-7"); + assertThat(messages).element(1).asString().contains("command\":\"reload\""); } @Test // gh-26813 @@ -125,8 +125,8 @@ void triggerReloadWithUppercaseHeaders() throws Exception { this.server.triggerReload(); List messages = await().atMost(Duration.ofSeconds(10)) .until(handler::getMessages, (msgs) -> msgs.size() == 2); - assertThat(messages.get(0)).contains("http://livereload.com/protocols/official-7"); - assertThat(messages.get(1)).contains("command\":\"reload\""); + assertThat(messages).element(0).asString().contains("http://livereload.com/protocols/official-7"); + assertThat(messages).element(1).asString().contains("command\":\"reload\""); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackResolversTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackResolversTests.java index 47daf7ee2b8d..674cdf157aeb 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackResolversTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackResolversTests.java @@ -57,7 +57,7 @@ void resolveAllWithBuilderBuildpackReferenceReturnsExpectedBuildpack() { BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:paketo-buildpacks/spring-boot@3.5.0"); Buildpacks buildpacks = BuildpackResolvers.resolveAll(this.resolverContext, Collections.singleton(reference)); assertThat(buildpacks.getBuildpacks()).hasSize(1); - assertThat(buildpacks.getBuildpacks().get(0)).isInstanceOf(BuilderBuildpack.class); + assertThat(buildpacks.getBuildpacks()).element(0).isInstanceOf(BuilderBuildpack.class); } @Test @@ -67,7 +67,7 @@ void resolveAllWithDirectoryBuildpackReferenceReturnsExpectedBuildpack(@TempDir BuildpackReference reference = BuildpackReference.of(temp.toAbsolutePath().toString()); Buildpacks buildpacks = BuildpackResolvers.resolveAll(this.resolverContext, Collections.singleton(reference)); assertThat(buildpacks.getBuildpacks()).hasSize(1); - assertThat(buildpacks.getBuildpacks().get(0)).isInstanceOf(DirectoryBuildpack.class); + assertThat(buildpacks.getBuildpacks()).element(0).isInstanceOf(DirectoryBuildpack.class); } @Test @@ -77,7 +77,7 @@ void resolveAllWithTarGzipBuildpackReferenceReturnsExpectedBuildpack(@TempDir Fi BuildpackReference reference = BuildpackReference.of(archive.toString()); Buildpacks buildpacks = BuildpackResolvers.resolveAll(this.resolverContext, Collections.singleton(reference)); assertThat(buildpacks.getBuildpacks()).hasSize(1); - assertThat(buildpacks.getBuildpacks().get(0)).isInstanceOf(TarGzipBuildpack.class); + assertThat(buildpacks.getBuildpacks()).element(0).isInstanceOf(TarGzipBuildpack.class); } @Test @@ -89,7 +89,7 @@ void resolveAllWithImageBuildpackReferenceReturnsExpectedBuildpack() throws IOEx BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1:latest"); Buildpacks buildpacks = BuildpackResolvers.resolveAll(resolverContext, Collections.singleton(reference)); assertThat(buildpacks.getBuildpacks()).hasSize(1); - assertThat(buildpacks.getBuildpacks().get(0)).isInstanceOf(ImageBuildpack.class); + assertThat(buildpacks.getBuildpacks()).element(0).isInstanceOf(ImageBuildpack.class); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEventTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEventTests.java index ab351ac8ebb8..f8386723b67b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEventTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEventTests.java @@ -49,15 +49,15 @@ void readAllWhenAnsiStreamReturnsEvents() throws Exception { List events = readAll("log-update-event-ansi.stream"); assertThat(events).hasSize(20); assertThat(events.get(0).toString()).isEmpty(); - assertThat(events.get(1)).hasToString("Cloud Foundry OpenJDK Buildpack v1.0.64"); - assertThat(events.get(2)).hasToString(" OpenJDK JRE 11.0.5: Reusing cached layer"); + assertThat(events).element(1).hasToString("Cloud Foundry OpenJDK Buildpack v1.0.64"); + assertThat(events).element(2).hasToString(" OpenJDK JRE 11.0.5: Reusing cached layer"); } @Test void readSucceedsWhenStreamTypeIsInvalid() throws IOException { List events = readAll("log-update-event-invalid-stream-type.stream"); assertThat(events).hasSize(1); - assertThat(events.get(0)).hasToString("Stream type is out of bounds. Must be >= 0 and < 3, but was 3"); + assertThat(events).element(0).hasToString("Stream type is out of bounds. Must be >= 0 and < 3, but was 3"); } private List readAll(String name) throws IOException { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-classic/src/test/java/org/springframework/boot/loader/jar/StringSequenceTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-classic/src/test/java/org/springframework/boot/loader/jar/StringSequenceTests.java index ee7170f08c25..779636e06447 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-classic/src/test/java/org/springframework/boot/loader/jar/StringSequenceTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-classic/src/test/java/org/springframework/boot/loader/jar/StringSequenceTests.java @@ -92,12 +92,12 @@ void subSequenceWhenStartPastExistingEndShouldThrowException() { @Test void isEmptyWhenEmptyShouldReturnTrue() { - assertThat(new StringSequence("").isEmpty()).isTrue(); + assertThat(new StringSequence("")).isEmpty(); } @Test void isEmptyWhenNotEmptyShouldReturnFalse() { - assertThat(new StringSequence("x").isEmpty()).isFalse(); + assertThat(new StringSequence("x")).isNotEmpty(); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/PropertiesLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/PropertiesLauncherTests.java index 9bac00e9e74c..86fd44fdd4aa 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/PropertiesLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/PropertiesLauncherTests.java @@ -345,7 +345,7 @@ void encodedFileUrlLoaderPathIsHandledCorrectly() throws Exception { this.launcher = new PropertiesLauncher(); Set urls = this.launcher.getClassPathUrls(); assertThat(urls).hasSize(1); - assertThat(urls.iterator().next()).isEqualTo(loaderPath.toURI().toURL()); + assertThat(urls).element(0).isEqualTo(loaderPath.toURI().toURL()); } @Test // gh-21575 diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java index 55dca3cf7712..575b0549b191 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java @@ -58,7 +58,7 @@ void filterDependencies() throws MojoExecutionException { Set artifacts = mojo.filterDependencies(createArtifact("com.foo", "one"), createArtifact("com.foo", "two"), artifact); assertThat(artifacts).hasSize(1); - assertThat(artifacts.iterator().next()).isSameAs(artifact); + assertThat(artifacts).element(0).isSameAs(artifact); } @Test @@ -69,7 +69,7 @@ void filterGroupIdExactMatch() throws MojoExecutionException { Set artifacts = mojo.filterDependencies(createArtifact("com.foo", "one"), createArtifact("com.foo", "two"), artifact); assertThat(artifacts).hasSize(1); - assertThat(artifacts.iterator().next()).isSameAs(artifact); + assertThat(artifacts).element(0).isSameAs(artifact); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ExcludeFilterTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ExcludeFilterTests.java index cceca0c8b3db..b363c1e2da4d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ExcludeFilterTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ExcludeFilterTests.java @@ -51,7 +51,7 @@ void excludeGroupIdNoMatch() throws ArtifactFilterException { Artifact artifact = createArtifact("com.baz", "bar"); Set result = filter.filter(Collections.singleton(artifact)); assertThat(result).hasSize(1); - assertThat(result.iterator().next()).isSameAs(artifact); + assertThat(result).element(0).isSameAs(artifact); } @Test @@ -60,7 +60,7 @@ void excludeArtifactIdNoMatch() throws ArtifactFilterException { Artifact artifact = createArtifact("com.foo", "biz"); Set result = filter.filter(Collections.singleton(artifact)); assertThat(result).hasSize(1); - assertThat(result.iterator().next()).isSameAs(artifact); + assertThat(result).element(0).isSameAs(artifact); } @Test @@ -76,7 +76,7 @@ void excludeClassifierNoTargetClassifier() throws ArtifactFilterException { Artifact artifact = createArtifact("com.foo", "bar"); Set result = filter.filter(Collections.singleton(artifact)); assertThat(result).hasSize(1); - assertThat(result.iterator().next()).isSameAs(artifact); + assertThat(result).element(0).isSameAs(artifact); } @Test @@ -85,7 +85,7 @@ void excludeClassifierNoMatch() throws ArtifactFilterException { Artifact artifact = createArtifact("com.foo", "bar", "jdk6"); Set result = filter.filter(Collections.singleton(artifact)); assertThat(result).hasSize(1); - assertThat(result.iterator().next()).isSameAs(artifact); + assertThat(result).element(0).isSameAs(artifact); } @Test @@ -99,7 +99,7 @@ void excludeMulti() throws ArtifactFilterException { artifacts.add(anotherAcme); Set result = filter.filter(artifacts); assertThat(result).hasSize(1); - assertThat(result.iterator().next()).isSameAs(anotherAcme); + assertThat(result).element(0).isSameAs(anotherAcme); } private Exclude createExclude(String groupId, String artifactId) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/IncludeFilterTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/IncludeFilterTests.java index 1d63e6088a64..575e3fdbc445 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/IncludeFilterTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/IncludeFilterTests.java @@ -43,7 +43,7 @@ void includeSimple() throws ArtifactFilterException { Artifact artifact = createArtifact("com.foo", "bar"); Set result = filter.filter(Collections.singleton(artifact)); assertThat(result).hasSize(1); - assertThat(result.iterator().next()).isSameAs(artifact); + assertThat(result).element(0).isSameAs(artifact); } @Test @@ -68,7 +68,7 @@ void includeClassifier() throws ArtifactFilterException { Artifact artifact = createArtifact("com.foo", "bar", "jdk5"); Set result = filter.filter(Collections.singleton(artifact)); assertThat(result).hasSize(1); - assertThat(result.iterator().next()).isSameAs(artifact); + assertThat(result).element(0).isSameAs(artifact); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java index 517b609b141b..bc1972b0c229 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java @@ -74,7 +74,7 @@ void createWhenInjectingDeferredLogFactoryCreatesResolver() { ConfigDataLocationResolvers resolvers = new ConfigDataLocationResolvers(this.logFactory, this.bootstrapContext, this.binder, new DefaultResourceLoader(), springFactoriesLoader); assertThat(resolvers.getResolvers()).hasSize(1); - assertThat(resolvers.getResolvers().get(0)).isExactlyInstanceOf(TestLogResolver.class); + assertThat(resolvers.getResolvers()).element(0).isExactlyInstanceOf(TestLogResolver.class); TestLogResolver resolver = (TestLogResolver) resolvers.getResolvers().get(0); assertThat(resolver.getDeferredLogFactory()).isSameAs(this.logFactory); } @@ -86,7 +86,7 @@ void createWhenInjectingBinderCreatesResolver() { ConfigDataLocationResolvers resolvers = new ConfigDataLocationResolvers(this.logFactory, this.bootstrapContext, this.binder, new DefaultResourceLoader(), springFactoriesLoader); assertThat(resolvers.getResolvers()).hasSize(1); - assertThat(resolvers.getResolvers().get(0)).isExactlyInstanceOf(TestBoundResolver.class); + assertThat(resolvers.getResolvers()).element(0).isExactlyInstanceOf(TestBoundResolver.class); assertThat(((TestBoundResolver) resolvers.getResolvers().get(0)).getBinder()).isSameAs(this.binder); } @@ -97,7 +97,7 @@ void createWhenNotInjectingBinderCreatesResolver() { ConfigDataLocationResolvers resolvers = new ConfigDataLocationResolvers(this.logFactory, this.bootstrapContext, this.binder, new DefaultResourceLoader(), springFactoriesLoader); assertThat(resolvers.getResolvers()).hasSize(1); - assertThat(resolvers.getResolvers().get(0)).isExactlyInstanceOf(TestResolver.class); + assertThat(resolvers.getResolvers()).element(0).isExactlyInstanceOf(TestResolver.class); } @Test @@ -116,9 +116,9 @@ void createOrdersResolvers() { HighestTestResolver.class); ConfigDataLocationResolvers resolvers = new ConfigDataLocationResolvers(this.logFactory, this.bootstrapContext, this.binder, new DefaultResourceLoader(), springFactoriesLoader); - assertThat(resolvers.getResolvers().get(0)).isExactlyInstanceOf(HighestTestResolver.class); - assertThat(resolvers.getResolvers().get(1)).isExactlyInstanceOf(TestResolver.class); - assertThat(resolvers.getResolvers().get(2)).isExactlyInstanceOf(LowestTestResolver.class); + assertThat(resolvers.getResolvers()).element(0).isExactlyInstanceOf(HighestTestResolver.class); + assertThat(resolvers.getResolvers()).element(1).isExactlyInstanceOf(TestResolver.class); + assertThat(resolvers.getResolvers()).element(2).isExactlyInstanceOf(LowestTestResolver.class); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConversionServiceDeducerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConversionServiceDeducerTests.java index 06b27871c9ed..3e8c44b4ac61 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConversionServiceDeducerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConversionServiceDeducerTests.java @@ -66,7 +66,7 @@ void getConversionServiceWhenHasNoConversionServiceBeanAndNoQualifiedBeansAndBea ConversionServiceDeducer deducer = new ConversionServiceDeducer(applicationContext); List conversionServices = deducer.getConversionServices(); assertThat(conversionServices).containsOnly(conversionService); - assertThat(conversionServices.get(0)).isSameAs(conversionService); + assertThat(conversionServices).element(0).isSameAs(conversionService); } @Test @@ -76,9 +76,9 @@ void getConversionServiceWhenHasQualifiedConverterBeansContainsCustomizedFormatt ConversionServiceDeducer deducer = new ConversionServiceDeducer(applicationContext); List conversionServices = deducer.getConversionServices(); assertThat(conversionServices).hasSize(2); - assertThat(conversionServices.get(0)).isExactlyInstanceOf(FormattingConversionService.class); + assertThat(conversionServices).element(0).isExactlyInstanceOf(FormattingConversionService.class); assertThat(conversionServices.get(0).canConvert(InputStream.class, OutputStream.class)).isTrue(); - assertThat(conversionServices.get(1)).isSameAs(ApplicationConversionService.getSharedInstance()); + assertThat(conversionServices).element(1).isSameAs(ApplicationConversionService.getSharedInstance()); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java index 8d3ca49f126e..0a9a5debb6a5 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java @@ -90,8 +90,8 @@ void bindToCollectionWhenNestedShouldReturnPopulatedCollection() { .of(ResolvableType.forClassWithGenerics(List.class, INTEGER_LIST.getType())); List> result = this.binder.bind("foo", target).get(); assertThat(result).hasSize(2); - assertThat(result.get(0)).containsExactly(1, 2); - assertThat(result.get(1)).containsExactly(3, 4); + assertThat(result).element(0).asList().containsExactly(1, 2); + assertThat(result).element(1).asList().containsExactly(3, 4); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java index 1a11453bdd23..5923066bd0a8 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java @@ -58,14 +58,18 @@ void cyclicBeanMethods() throws IOException { assertThat(lines).hasSize(9); assertThat(lines.get(0)) .isEqualTo("The dependencies of some of the beans in the application context form a cycle:"); - assertThat(lines.get(1)).isEmpty(); - assertThat(lines.get(2)).isEqualTo("┌─────┐"); - assertThat(lines.get(3)).startsWith("| one defined in " + InnerInnerConfiguration.class.getName()); - assertThat(lines.get(4)).isEqualTo("↑ ↓"); - assertThat(lines.get(5)).startsWith("| two defined in " + InnerConfiguration.class.getName()); - assertThat(lines.get(6)).isEqualTo("↑ ↓"); - assertThat(lines.get(7)).startsWith("| three defined in " + CyclicBeanMethodsConfiguration.class.getName()); - assertThat(lines.get(8)).isEqualTo("└─────┘"); + assertThat(lines).element(1).asString().isEmpty(); + assertThat(lines).element(2).isEqualTo("┌─────┐"); + assertThat(lines).element(3) + .asString() + .startsWith("| one defined in " + InnerInnerConfiguration.class.getName()); + assertThat(lines).element(4).isEqualTo("↑ ↓"); + assertThat(lines).element(5).asString().startsWith("| two defined in " + InnerConfiguration.class.getName()); + assertThat(lines).element(6).isEqualTo("↑ ↓"); + assertThat(lines).element(7) + .asString() + .startsWith("| three defined in " + CyclicBeanMethodsConfiguration.class.getName()); + assertThat(lines).element(8).isEqualTo("└─────┘"); assertThat(analysis.getAction()).isNotNull(); } @@ -78,15 +82,19 @@ void cycleWithAutowiredFields() throws IOException { assertThat(lines).hasSize(9); assertThat(lines.get(0)) .isEqualTo("The dependencies of some of the beans in the application context form a cycle:"); - assertThat(lines.get(1)).isEmpty(); - assertThat(lines.get(2)).isEqualTo("┌─────┐"); - assertThat(lines.get(3)).startsWith("| three defined in " + BeanThreeConfiguration.class.getName()); - assertThat(lines.get(4)).isEqualTo("↑ ↓"); - assertThat(lines.get(5)).startsWith("| one defined in " + CycleWithAutowiredFields.class.getName()); - assertThat(lines.get(6)).isEqualTo("↑ ↓"); + assertThat(lines).element(1).asString().isEmpty(); + assertThat(lines).element(2).isEqualTo("┌─────┐"); + assertThat(lines).element(3) + .asString() + .startsWith("| three defined in " + BeanThreeConfiguration.class.getName()); + assertThat(lines).element(4).isEqualTo("↑ ↓"); + assertThat(lines).element(5) + .asString() + .startsWith("| one defined in " + CycleWithAutowiredFields.class.getName()); + assertThat(lines).element(6).isEqualTo("↑ ↓"); assertThat(lines.get(7)) .startsWith("| " + BeanTwoConfiguration.class.getName() + " (field private " + BeanThree.class.getName()); - assertThat(lines.get(8)).isEqualTo("└─────┘"); + assertThat(lines).element(8).isEqualTo("└─────┘"); assertThat(analysis.getAction()).isNotNull(); } @@ -97,20 +105,20 @@ void cycleReferencedViaOtherBeans() throws IOException { assertThat(lines).hasSize(12); assertThat(lines.get(0)) .isEqualTo("The dependencies of some of the beans in the application context form a cycle:"); - assertThat(lines.get(1)).isEmpty(); - assertThat(lines.get(2)).contains("refererOne (field " + RefererTwo.class.getName()); - assertThat(lines.get(3)).isEqualTo(" ↓"); - assertThat(lines.get(4)).contains("refererTwo (field " + BeanOne.class.getName()); - assertThat(lines.get(5)).isEqualTo("┌─────┐"); + assertThat(lines).element(1).asString().isEmpty(); + assertThat(lines).element(2).asString().contains("refererOne (field " + RefererTwo.class.getName()); + assertThat(lines).element(3).isEqualTo(" ↓"); + assertThat(lines).element(4).asString().contains("refererTwo (field " + BeanOne.class.getName()); + assertThat(lines).element(5).isEqualTo("┌─────┐"); assertThat(lines.get(6)) .startsWith("| one defined in " + CycleReferencedViaOtherBeansConfiguration.class.getName()); - assertThat(lines.get(7)).isEqualTo("↑ ↓"); + assertThat(lines).element(7).isEqualTo("↑ ↓"); assertThat(lines.get(8)) .startsWith("| two defined in " + CycleReferencedViaOtherBeansConfiguration.class.getName()); - assertThat(lines.get(9)).isEqualTo("↑ ↓"); + assertThat(lines).element(9).isEqualTo("↑ ↓"); assertThat(lines.get(10)) .startsWith("| three defined in " + CycleReferencedViaOtherBeansConfiguration.class.getName()); - assertThat(lines.get(11)).isEqualTo("└─────┘"); + assertThat(lines).element(11).isEqualTo("└─────┘"); assertThat(analysis.getAction()).isNotNull(); } @@ -121,10 +129,12 @@ void testSelfReferenceCycle() throws IOException { assertThat(lines).hasSize(5); assertThat(lines.get(0)) .isEqualTo("The dependencies of some of the beans in the application context form a cycle:"); - assertThat(lines.get(1)).isEmpty(); - assertThat(lines.get(2)).isEqualTo("┌──->──┐"); - assertThat(lines.get(3)).startsWith("| bean defined in " + SelfReferenceBeanConfiguration.class.getName()); - assertThat(lines.get(4)).isEqualTo("└──<-──┘"); + assertThat(lines).element(1).asString().isEmpty(); + assertThat(lines).element(2).isEqualTo("┌──->──┐"); + assertThat(lines).element(3) + .asString() + .startsWith("| bean defined in " + SelfReferenceBeanConfiguration.class.getName()); + assertThat(lines).element(4).isEqualTo("└──<-──┘"); assertThat(analysis.getAction()).isNotNull(); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorApplicationListenerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorApplicationListenerTests.java index 40145f2ce7a7..3508980653a4 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorApplicationListenerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorApplicationListenerTests.java @@ -75,7 +75,7 @@ void createWhenHasFactoryUsesFactory() { List postProcessors = listener.getEnvironmentPostProcessors(null, this.bootstrapContext); assertThat(postProcessors).hasSize(1); - assertThat(postProcessors.get(0)).isInstanceOf(TestEnvironmentPostProcessor.class); + assertThat(postProcessors).element(0).isInstanceOf(TestEnvironmentPostProcessor.class); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorsFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorsFactoryTests.java index 6398bab32136..75c7afc23e7c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorsFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/EnvironmentPostProcessorsFactoryTests.java @@ -55,7 +55,7 @@ void ofClassesReturnsFactory() { List processors = factory.getEnvironmentPostProcessors(this.logFactory, this.bootstrapContext); assertThat(processors).hasSize(1); - assertThat(processors.get(0)).isInstanceOf(TestEnvironmentPostProcessor.class); + assertThat(processors).element(0).isInstanceOf(TestEnvironmentPostProcessor.class); } @Test @@ -65,7 +65,7 @@ void ofClassNamesReturnsFactory() { List processors = factory.getEnvironmentPostProcessors(this.logFactory, this.bootstrapContext); assertThat(processors).hasSize(1); - assertThat(processors.get(0)).isInstanceOf(TestEnvironmentPostProcessor.class); + assertThat(processors).element(0).isInstanceOf(TestEnvironmentPostProcessor.class); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/json/AbstractJsonParserTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/json/AbstractJsonParserTests.java index 446d0ffe236b..0e641294f1ca 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/json/AbstractJsonParserTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/json/AbstractJsonParserTests.java @@ -81,7 +81,7 @@ void emptyMap() { void simpleList() { List list = this.parser.parseList("[\"foo\",\"bar\",1]"); assertThat(list).hasSize(3); - assertThat(list.get(1)).isEqualTo("bar"); + assertThat(list).element(1).isEqualTo("bar"); } @Test @@ -152,7 +152,7 @@ void listWithMapThrowsARuntimeException() { void listWithLeadingWhitespace() { List list = this.parser.parseList("\n\t[\"foo\"]"); assertThat(list).hasSize(1); - assertThat(list.get(0)).isEqualTo("foo"); + assertThat(list).element(0).isEqualTo("foo"); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/InstantiatorTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/InstantiatorTests.java index bb208ff4c972..0fb88fcad2c2 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/InstantiatorTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/InstantiatorTests.java @@ -69,8 +69,8 @@ void instantiateOrdersInstances() { List instances = createInstantiator(Object.class).instantiate( Arrays.asList(WithMultipleConstructors.class.getName(), WithAdditionalConstructor.class.getName())); assertThat(instances).hasSize(2); - assertThat(instances.get(0)).isInstanceOf(WithAdditionalConstructor.class); - assertThat(instances.get(1)).isInstanceOf(WithMultipleConstructors.class); + assertThat(instances).element(0).isInstanceOf(WithAdditionalConstructor.class); + assertThat(instances).element(1).isInstanceOf(WithMultipleConstructors.class); } @Test