From ffddbb586e60ce1b66a3b962612636db9c61ed81 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Tue, 2 Jan 2024 15:38:31 +0100 Subject: [PATCH] Upgrade to AssertJ 3.25.0 --- framework-platform/framework-platform.gradle | 2 +- .../beans/factory/config/YamlProcessorTests.java | 10 ++++++---- .../context/annotation/ImportSelectorTests.java | 5 +++-- .../aot/agent/RecordedInvocationTests.java | 5 +++-- .../ExceptionHandlerExceptionResolverTests.java | 13 +++++++------ 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/framework-platform/framework-platform.gradle b/framework-platform/framework-platform.gradle index 86bd9cc147f..3f497bc4037 100644 --- a/framework-platform/framework-platform.gradle +++ b/framework-platform/framework-platform.gradle @@ -109,7 +109,7 @@ dependencies { api("org.aspectj:aspectjrt:1.9.21") api("org.aspectj:aspectjtools:1.9.21") api("org.aspectj:aspectjweaver:1.9.21") - api("org.assertj:assertj-core:3.24.2") + api("org.assertj:assertj-core:3.25.0") api("org.awaitility:awaitility:4.2.0") api("org.bouncycastle:bcpkix-jdk18on:1.72") api("org.codehaus.jettison:jettison:1.5.4") diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java index d90186150dd..8468a880035 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Test; import org.yaml.snakeyaml.composer.ComposerException; import org.yaml.snakeyaml.parser.ParserException; @@ -145,10 +146,11 @@ class YamlProcessorTests { void standardTypesSupportedByDefault() { setYaml("value: !!set\n ? first\n ? second"); this.processor.process((properties, map) -> { - assertThat(properties).containsExactly(entry("value[0]", "first"), entry("value[1]", "second")); - assertThat(map.get("value")).isInstanceOf(Set.class); - Set set = (Set) map.get("value"); - assertThat(set).containsExactly("first", "second"); + // Assert on Properties as a Map due to bug in AssertJ 3.25.0 + Map propsAsMap = new LinkedHashMap<>(properties); + assertThat(propsAsMap).containsExactly(entry("value[0]", "first"), entry("value[1]", "second")); + assertThat(map.get("value")).asInstanceOf(InstanceOfAssertFactories.type(Set.class)) + .satisfies(set -> assertThat(set).containsExactly("first", "second")); }); } diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ImportSelectorTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ImportSelectorTests.java index ab5dedf319f..dcfcec7ded0 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ImportSelectorTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ImportSelectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,6 +51,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.InstanceOfAssertFactories.LIST; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.inOrder; @@ -126,7 +127,7 @@ public class ImportSelectorTests { ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any()); assertThat(TestImportGroup.instancesCount.get()).isEqualTo(1); assertThat(TestImportGroup.imports).hasSize(1); - assertThat(TestImportGroup.imports.values()).element(0).asList().hasSize(2); + assertThat(TestImportGroup.imports.values()).element(0).asInstanceOf(LIST).hasSize(2); } @Test diff --git a/spring-core-test/src/test/java/org/springframework/aot/agent/RecordedInvocationTests.java b/spring-core-test/src/test/java/org/springframework/aot/agent/RecordedInvocationTests.java index 35b633dd810..f0a8c57462b 100644 --- a/spring-core-test/src/test/java/org/springframework/aot/agent/RecordedInvocationTests.java +++ b/spring-core-test/src/test/java/org/springframework/aot/agent/RecordedInvocationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.aot.agent; import java.lang.reflect.Method; +import org.assertj.core.api.ThrowableAssert.ThrowingCallableWithValue; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -63,7 +64,7 @@ class RecordedInvocationTests { @Test void staticInvocationShouldThrowWhenGetInstance() { - assertThatThrownBy(staticInvocation::getInstance).isInstanceOf(IllegalStateException.class); + assertThatThrownBy((ThrowingCallableWithValue) staticInvocation::getInstance).isInstanceOf(IllegalStateException.class); assertThatThrownBy(staticInvocation::getInstanceTypeReference).isInstanceOf(IllegalStateException.class); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java index d6e1910a78a..614f6ba1a1a 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,6 +64,7 @@ import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import org.springframework.web.testfixture.servlet.MockHttpServletResponse; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.InstanceOfAssertFactories.LIST; /** * Test fixture with {@link ExceptionHandlerExceptionResolver}. @@ -75,7 +76,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rodolphe Lecocq */ @SuppressWarnings("unused") -public class ExceptionHandlerExceptionResolverTests { +class ExceptionHandlerExceptionResolverTests { private static int DEFAULT_RESOLVER_COUNT; @@ -89,7 +90,7 @@ public class ExceptionHandlerExceptionResolverTests { @BeforeAll - public static void setupOnce() { + static void setupOnce() { ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver(); resolver.afterPropertiesSet(); DEFAULT_RESOLVER_COUNT = resolver.getArgumentResolvers().getResolvers().size(); @@ -97,7 +98,7 @@ public class ExceptionHandlerExceptionResolverTests { } @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { this.resolver = new ExceptionHandlerExceptionResolver(); this.resolver.setWarnLogCategory(this.resolver.getClass().getName()); this.request = new MockHttpServletRequest("GET", "/"); @@ -146,9 +147,9 @@ public class ExceptionHandlerExceptionResolverTests { @Test void setResponseBodyAdvice() { this.resolver.setResponseBodyAdvice(Collections.singletonList(new JsonViewResponseBodyAdvice())); - assertThat(this.resolver).extracting("responseBodyAdvice").asList().hasSize(1); + assertThat(this.resolver).extracting("responseBodyAdvice").asInstanceOf(LIST).hasSize(1); this.resolver.setResponseBodyAdvice(Collections.singletonList(new CustomResponseBodyAdvice())); - assertThat(this.resolver).extracting("responseBodyAdvice").asList().hasSize(2); + assertThat(this.resolver).extracting("responseBodyAdvice").asInstanceOf(LIST).hasSize(2); } @Test