diff --git a/spring-jms/src/test/java/org/springframework/jms/core/JmsTemplateObservationTests.java b/spring-jms/src/test/java/org/springframework/jms/core/JmsTemplateObservationTests.java index 99ae2fe426a..2798b57683c 100644 --- a/spring-jms/src/test/java/org/springframework/jms/core/JmsTemplateObservationTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/core/JmsTemplateObservationTests.java @@ -27,13 +27,13 @@ import jakarta.jms.MessageConsumer; import jakarta.jms.Session; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.artemis.junit.EmbeddedActiveMQExtension; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import static io.micrometer.observation.tck.TestObservationRegistryAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for Observability related {@link JmsTemplate}. @@ -127,7 +127,7 @@ class JmsTemplateObservationTests { }); String responseBody = response.getBody(String.class); - Assertions.assertThat(responseBody).isEqualTo("response content"); + assertThat(responseBody).isEqualTo("response content"); assertThat(registry).hasNumberOfObservationsWithNameEqualTo("jms.message.publish", 2); assertThat(registry).hasObservationWithNameEqualTo("jms.message.process").that() diff --git a/spring-jms/src/test/java/org/springframework/jms/listener/MessageListenerContainerObservationTests.java b/spring-jms/src/test/java/org/springframework/jms/listener/MessageListenerContainerObservationTests.java index 1e175d46532..5a732071fd5 100644 --- a/spring-jms/src/test/java/org/springframework/jms/listener/MessageListenerContainerObservationTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/listener/MessageListenerContainerObservationTests.java @@ -26,7 +26,6 @@ import io.micrometer.observation.tck.TestObservationRegistry; import jakarta.jms.MessageListener; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.artemis.junit.EmbeddedActiveMQExtension; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -37,6 +36,7 @@ import org.junit.jupiter.params.provider.MethodSource; import org.springframework.jms.core.JmsTemplate; import static io.micrometer.observation.tck.TestObservationRegistryAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Named.named; import static org.junit.jupiter.params.provider.Arguments.arguments; @@ -101,7 +101,7 @@ class MessageListenerContainerObservationTests { JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory); jmsTemplate.convertAndSend("spring.test.observation", "message content"); latch.await(2, TimeUnit.SECONDS); - Assertions.assertThat(observationInErrorHandler.get()).isNotNull(); + assertThat(observationInErrorHandler.get()).isNotNull(); assertThat(registry).hasObservationWithNameEqualTo("jms.message.process") .that() .hasHighCardinalityKeyValue("messaging.destination.name", "spring.test.observation") diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideProcessor.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideProcessor.java index 4cca2c8c260..92799be829d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideProcessor.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideProcessor.java @@ -48,4 +48,5 @@ public interface BeanOverrideProcessor { * given field */ OverrideMetadata createMetadata(Annotation overrideAnnotation, Class testClass, Field field); + } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTestUtils.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTestUtils.java index 72d1c999905..9e01f72ca87 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTestUtils.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTestUtils.java @@ -33,7 +33,6 @@ import static org.mockito.Mockito.mock; */ public abstract class BeanOverrideContextCustomizerTestUtils { - private static final BeanOverrideContextCustomizerFactory factory = new BeanOverrideContextCustomizerFactory(); /** @@ -49,12 +48,12 @@ public abstract class BeanOverrideContextCustomizerTestUtils { } /** - * Configure the given {@linkplain ConfigurableApplicationContext application + * Customize the given {@linkplain ConfigurableApplicationContext application * context} for the given {@code testClass}. * @param testClass the test to process - * @param context the context to configure + * @param context the context to customize */ - public static void configureApplicationContext(Class testClass, ConfigurableApplicationContext context) { + public static void customizeApplicationContext(Class testClass, ConfigurableApplicationContext context) { ContextCustomizer contextCustomizer = createContextCustomizer(testClass); if (contextCustomizer != null) { contextCustomizer.customizeContext(context, mock(MergedContextConfiguration.class)); diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForInheritanceIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForInheritanceIntegrationTests.java index 0389dad6b05..d1c0674297c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForInheritanceIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForInheritanceIntegrationTests.java @@ -128,7 +128,6 @@ class TestBeanForInheritanceIntegrationTests { @DisplayName("Nested, concrete inherited tests with correct @TestBean setup") class NestedConcreteTestBeanIntegrationTests extends AbstractTestBeanIntegrationTestCase { - @Autowired ApplicationContext ctx; @@ -141,6 +140,7 @@ class TestBeanForInheritanceIntegrationTests { static Pojo someBean() { return new FakePojo("someBeanOverride"); } + // Hides otherBean() defined in AbstractTestBeanIntegrationTestCase. static Pojo otherBean() { return new FakePojo("otherBean in subclass"); @@ -169,4 +169,5 @@ class TestBeanForInheritanceIntegrationTests { assertThat(this.pojo2.getValue()).as("injection point").isEqualTo("in enclosing test class"); } } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForInterfaceIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForInterfaceIntegrationTests.java index 8ef08c77af2..d547f27e668 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForInterfaceIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanForInterfaceIntegrationTests.java @@ -26,8 +26,8 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** - * Integration tests for {@link TestBean} that use a bean factory methods - * defined in implemented interfaces. + * Integration tests for {@link TestBean} that use bean factory methods defined + * in implemented interfaces. * * @author Sam Brannen * @since 6.2 diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideProcessorTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideProcessorTests.java index 0ebbaddf44d..49428aa88cb 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideProcessorTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideProcessorTests.java @@ -124,8 +124,8 @@ class TestBeanOverrideProcessorTests { TestBean overrideAnnotation = field.getAnnotation(TestBean.class); assertThat(overrideAnnotation).isNotNull(); - assertThatIllegalStateException().isThrownBy(() -> this.processor.createMetadata( - overrideAnnotation, clazz, field)) + assertThatIllegalStateException() + .isThrownBy(() -> this.processor.createMetadata(overrideAnnotation, clazz, field)) .withMessage("No static method found named field() or someField() in %s with return type %s", clazz.getName(), returnType.getName()); } @@ -136,7 +136,8 @@ class TestBeanOverrideProcessorTests { Field field = clazz.getField("field"); NonNull badAnnotation = AnnotationUtils.synthesizeAnnotation(NonNull.class); - assertThatIllegalStateException().isThrownBy(() -> this.processor.createMetadata(badAnnotation, clazz, field)) + assertThatIllegalStateException() + .isThrownBy(() -> this.processor.createMetadata(badAnnotation, clazz, field)) .withMessage("Invalid annotation passed to TestBeanOverrideProcessor: expected @TestBean" + " on field %s.%s", field.getDeclaringClass().getName(), field.getName()); } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanTests.java index 03c2909d192..b6bd799a01b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanTests.java @@ -18,12 +18,13 @@ package org.springframework.test.context.bean.override.convention; import java.util.List; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.context.support.GenericApplicationContext; import org.springframework.test.context.bean.override.BeanOverrideContextCustomizerTestUtils; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; + /** * Tests for {@link TestBean}. * @@ -35,8 +36,9 @@ public class TestBeanTests { void contextCustomizerCannotBeCreatedWithNoSuchBeanName() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBean("anotherBean", String.class, () -> "example"); - BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByNameLookup.class, context); - Assertions.assertThatIllegalStateException().isThrownBy(context::refresh) + BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByNameLookup.class, context); + assertThatIllegalStateException() + .isThrownBy(context::refresh) .withMessage(""" Unable to override bean 'beanToOverride': there is no bean definition \ to replace with that name of type java.lang.String"""); @@ -45,8 +47,9 @@ public class TestBeanTests { @Test void contextCustomizerCannotBeCreatedWithNoSuchBeanType() { GenericApplicationContext context = new GenericApplicationContext(); - BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByTypeLookup.class, context); - Assertions.assertThatIllegalStateException().isThrownBy(context::refresh) + BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByTypeLookup.class, context); + assertThatIllegalStateException() + .isThrownBy(context::refresh) .withMessage(""" Unable to override bean: no bean definitions of \ type %s (as required by annotated field '%s.example')""".formatted( @@ -58,8 +61,9 @@ public class TestBeanTests { GenericApplicationContext context = new GenericApplicationContext(); context.registerBean("bean1", String.class, () -> "example1"); context.registerBean("bean2", String.class, () -> "example2"); - BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByTypeLookup.class, context); - Assertions.assertThatIllegalStateException().isThrownBy(context::refresh) + BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByTypeLookup.class, context); + assertThatIllegalStateException() + .isThrownBy(context::refresh) .withMessage(""" Unable to select a bean definition to override: found 2 bean definitions \ of type %s (as required by annotated field '%s.example'): %s""".formatted( @@ -70,8 +74,9 @@ public class TestBeanTests { void contextCustomizerCannotBeCreatedWithBeanOfWrongType() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBean("beanToOverride", Integer.class, () -> 42); - BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByNameLookup.class, context); - Assertions.assertThatIllegalStateException().isThrownBy(context::refresh) + BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByNameLookup.class, context); + assertThatIllegalStateException() + .isThrownBy(context::refresh) .withMessage(""" Unable to override bean 'beanToOverride': there is no bean definition \ to replace with that name of type %s""".formatted( @@ -81,8 +86,8 @@ public class TestBeanTests { @Test void contextCustomizerCannotBeCreatedWithMissingOverrideMethod() { GenericApplicationContext context = new GenericApplicationContext(); - Assertions.assertThatIllegalStateException() - .isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext( + assertThatIllegalStateException() + .isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext( FailureMissingDefaultOverrideMethod.class, context)) .withMessage("No static method found named example() or beanToOverride() in %s with return type %s" .formatted(FailureMissingDefaultOverrideMethod.class.getName(), String.class.getName())); @@ -91,8 +96,8 @@ public class TestBeanTests { @Test void contextCustomizerCannotBeCreatedWithMissingExplicitOverrideMethod() { GenericApplicationContext context = new GenericApplicationContext(); - Assertions.assertThatIllegalStateException() - .isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext( + assertThatIllegalStateException() + .isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext( FailureMissingExplicitOverrideMethod.class, context)) .withMessage("No static method found named createExample() in %s with return type %s" .formatted(FailureMissingExplicitOverrideMethod.class.getName(), String.class.getName())); @@ -102,8 +107,8 @@ public class TestBeanTests { void contextCustomizerCannotBeCreatedWithFieldInParentAndMissingOverrideMethod() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBean("beanToOverride", String.class, () -> "example"); - Assertions.assertThatIllegalStateException() - .isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext( + assertThatIllegalStateException() + .isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext( FailureOverrideInParentWithoutFactoryMethod.class, context)) .withMessage("No static method found named beanToOverride() in %s with return type %s" .formatted(FailureOverrideInParentWithoutFactoryMethod.class.getName(), String.class.getName())); @@ -113,8 +118,8 @@ public class TestBeanTests { void contextCustomizerCannotBeCreatedWitCompetingOverrideMethods() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBean("bean", String.class, () -> "example"); - Assertions.assertThatIllegalStateException() - .isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext( + assertThatIllegalStateException() + .isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext( FailureCompetingOverrideMethods.class, context)) .withMessage("Found 2 competing static methods named example() or beanToOverride() in %s with return type %s" .formatted(FailureCompetingOverrideMethods.class.getName(), String.class.getName())); diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanContextCustomizerEqualityTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanContextCustomizerEqualityTests.java index 8ea5de3c786..a801171ca30 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanContextCustomizerEqualityTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanContextCustomizerEqualityTests.java @@ -32,7 +32,6 @@ import static org.assertj.core.api.Assertions.assertThat; */ class MockitoBeanContextCustomizerEqualityTests { - @Test void contextCustomizerWithSameMockByNameInDifferentClassIsEqual() { assertThat(createContextCustomizer(Case1ByName.class)).isEqualTo(createContextCustomizer(Case2ByName.class)); diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanForBeanFactoryIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanForBeanFactoryIntegrationTests.java index 962df47e9db..7932248128a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanForBeanFactoryIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanForBeanFactoryIntegrationTests.java @@ -17,14 +17,13 @@ package org.springframework.test.context.bean.override.mockito; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; @@ -35,11 +34,9 @@ import static org.mockito.Mockito.mock; * * @author Phillip Webb */ -@ExtendWith(SpringExtension.class) +@SpringJUnitConfig class MockitoBeanForBeanFactoryIntegrationTests { - // spring-boot/gh-7439 - @MockitoBean private TestFactoryBean testFactoryBean; diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanForByTypeLookupIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanForByTypeLookupIntegrationTests.java index 5d326c20fef..5e33a424d22 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanForByTypeLookupIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanForByTypeLookupIntegrationTests.java @@ -122,6 +122,7 @@ public class MockitoBeanForByTypeLookupIntegrationTests { verifyNoMoreInteractions(this.ambiguousMeta); } + interface AnotherService { String hello(); diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideProcessorTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideProcessorTests.java index 084ca5ab0b6..eed7c1a8443 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideProcessorTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideProcessorTests.java @@ -62,7 +62,8 @@ public class MockitoBeanOverrideProcessorTests { Field field = clazz.getField("a"); Annotation annotation = field.getAnnotation(Nullable.class); - assertThatIllegalStateException().isThrownBy(() -> this.processor.createMetadata(annotation, clazz, field)) + assertThatIllegalStateException() + .isThrownBy(() -> this.processor.createMetadata(annotation, clazz, field)) .withMessage("Invalid annotation passed to MockitoBeanOverrideProcessor: expected " + "@MockitoBean/@MockitoSpyBean on field %s.%s", field.getDeclaringClass().getName(), field.getName()); diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoMockBeanTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoMockBeanTests.java index 9cd42b32e84..472bec1c04c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoMockBeanTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoMockBeanTests.java @@ -18,12 +18,13 @@ package org.springframework.test.context.bean.override.mockito; import java.util.List; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.context.support.GenericApplicationContext; import org.springframework.test.context.bean.override.BeanOverrideContextCustomizerTestUtils; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; + /** * Tests for {@link MockitoBean}. * @@ -36,8 +37,9 @@ class MockitoMockBeanTests { GenericApplicationContext context = new GenericApplicationContext(); context.registerBean("bean1", String.class, () -> "example1"); context.registerBean("bean2", String.class, () -> "example2"); - BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByTypeSingleLookup.class, context); - Assertions.assertThatIllegalStateException().isThrownBy(context::refresh) + BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByTypeSingleLookup.class, context); + assertThatIllegalStateException() + .isThrownBy(context::refresh) .withMessage(""" Unable to select a bean definition to override: found 2 bean definitions \ of type %s (as required by annotated field '%s.example'): %s""".formatted( @@ -51,4 +53,5 @@ class MockitoMockBeanTests { String example; } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanTests.java index 6d6a7077f94..d74e8b16e62 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanTests.java @@ -18,12 +18,13 @@ package org.springframework.test.context.bean.override.mockito; import java.util.List; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.context.support.GenericApplicationContext; import org.springframework.test.context.bean.override.BeanOverrideContextCustomizerTestUtils; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; + /** * Tests for {@link MockitoSpyBean}. * @@ -35,8 +36,9 @@ class MockitoSpyBeanTests { void contextCustomizerCannotBeCreatedWithNoSuchBeanName() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBean("present", String.class, () -> "example"); - BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByNameSingleLookup.class, context); - Assertions.assertThatIllegalStateException().isThrownBy(context::refresh) + BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByNameSingleLookup.class, context); + assertThatIllegalStateException() + .isThrownBy(context::refresh) .withMessage(""" Unable to override bean 'beanToSpy' by wrapping: \ there is no existing bean instance with that name of type %s""".formatted( @@ -46,8 +48,9 @@ class MockitoSpyBeanTests { @Test void contextCustomizerCannotBeCreatedWithNoSuchBeanType() { GenericApplicationContext context = new GenericApplicationContext(); - BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByTypeSingleLookup.class, context); - Assertions.assertThatIllegalStateException().isThrownBy(context::refresh) + BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByTypeSingleLookup.class, context); + assertThatIllegalStateException() + .isThrownBy(context::refresh) .withMessage(""" Unable to select a bean to override by wrapping: found 0 bean instances of \ type %s (as required by annotated field '%s.example')""".formatted( @@ -59,8 +62,9 @@ class MockitoSpyBeanTests { GenericApplicationContext context = new GenericApplicationContext(); context.registerBean("bean1", String.class, () -> "example1"); context.registerBean("bean2", String.class, () -> "example2"); - BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByTypeSingleLookup.class, context); - Assertions.assertThatIllegalStateException().isThrownBy(context::refresh) + BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByTypeSingleLookup.class, context); + assertThatIllegalStateException() + .isThrownBy(context::refresh) .withMessage(""" Unable to select a bean to override by wrapping: found 2 bean instances \ of type %s (as required by annotated field '%s.example'): %s""".formatted( diff --git a/spring-test/src/test/java/org/springframework/test/http/HttpHeadersAssertTests.java b/spring-test/src/test/java/org/springframework/test/http/HttpHeadersAssertTests.java index 4d1af3c3454..36dc3c92534 100644 --- a/spring-test/src/test/java/org/springframework/test/http/HttpHeadersAssertTests.java +++ b/spring-test/src/test/java/org/springframework/test/http/HttpHeadersAssertTests.java @@ -20,13 +20,14 @@ import java.time.Instant; import java.util.List; import java.util.Map; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + /** * Tests for {@link HttpHeadersAssert}. * @@ -42,7 +43,7 @@ class HttpHeadersAssertTests { @Test void containsHeaderWithNameNotPresent() { Map map = Map.of("first", "1"); - Assertions.assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(map).containsHeader("wrong-name")) .withMessageContainingAll("HTTP headers", "first", "wrong-name"); } @@ -56,7 +57,7 @@ class HttpHeadersAssertTests { @Test void containsHeadersWithSeveralNamesNotPresent() { Map map = Map.of("first", "1", "second", "2", "third", "3"); - Assertions.assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(map).containsHeaders("first", "wrong-name", "another-wrong-name", "third")) .withMessageContainingAll("HTTP headers", "first", "wrong-name", "another-wrong-name"); } @@ -69,7 +70,7 @@ class HttpHeadersAssertTests { @Test void doesNotContainHeaderWithNamePresent() { Map map = Map.of("first", "1"); - Assertions.assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(map).doesNotContainKey("first")) .withMessageContainingAll("HTTP headers", "first"); } @@ -83,7 +84,7 @@ class HttpHeadersAssertTests { @Test void doesNotContainHeadersWithSeveralNamesPresent() { Map map = Map.of("first", "1", "second", "2", "third", "3"); - Assertions.assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(map).doesNotContainsHeaders("first", "another-wrong-name", "second")) .withMessageContainingAll("HTTP headers", "first", "second"); } @@ -100,7 +101,7 @@ class HttpHeadersAssertTests { void hasValueWithStringMatchOnSecondaryValue() { HttpHeaders headers = new HttpHeaders(); headers.addAll("header", List.of("first", "second", "third")); - Assertions.assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(headers).hasValue("header", "second")) .withMessageContainingAll("check primary value for HTTP header 'header'", "first", "second"); } @@ -109,7 +110,7 @@ class HttpHeadersAssertTests { void hasValueWithNoStringMatch() { HttpHeaders headers = new HttpHeaders(); headers.addAll("header", List.of("first", "second", "third")); - Assertions.assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(headers).hasValue("wrong-name", "second")) .withMessageContainingAll("HTTP headers", "header", "wrong-name"); } @@ -118,7 +119,7 @@ class HttpHeadersAssertTests { void hasValueWithNonPresentHeader() { HttpHeaders map = new HttpHeaders(); map.add("test-header", "a"); - Assertions.assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(map).hasValue("wrong-name", "a")) .withMessageContainingAll("HTTP headers", "test-header", "wrong-name"); } @@ -134,7 +135,7 @@ class HttpHeadersAssertTests { void hasValueWithLongMatchOnSecondaryValue() { HttpHeaders map = new HttpHeaders(); map.addAll("header", List.of("123", "456", "789")); - Assertions.assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(map).hasValue("header", 456)) .withMessageContainingAll("check primary long value for HTTP header 'header'", "123", "456"); } @@ -143,7 +144,7 @@ class HttpHeadersAssertTests { void hasValueWithNoLongMatch() { HttpHeaders map = new HttpHeaders(); map.addAll("header", List.of("123", "456", "789")); - Assertions.assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(map).hasValue("wrong-name", 456)) .withMessageContainingAll("HTTP headers", "header", "wrong-name"); } @@ -161,7 +162,7 @@ class HttpHeadersAssertTests { Instant instant = Instant.now(); HttpHeaders map = new HttpHeaders(); map.setInstant("header", instant); - Assertions.assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(map).hasValue("wrong-name", instant.minusSeconds(30))) .withMessageContainingAll("HTTP headers", "header", "wrong-name"); } @@ -171,7 +172,7 @@ class HttpHeadersAssertTests { Instant instant = Instant.now(); HttpHeaders map = new HttpHeaders(); map.setInstant("header", instant); - Assertions.assertThatExceptionOfType(AssertionError.class) + assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(map).hasValue("wrong-name", instant.minusSeconds(1))) .withMessageContainingAll("HTTP headers", "header", "wrong-name"); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletRequestAssertTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletRequestAssertTests.java index eb8dcd6ed35..32aa6194f45 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletRequestAssertTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletRequestAssertTests.java @@ -21,7 +21,6 @@ import java.util.Map; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -37,7 +36,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; */ public class AbstractHttpServletRequestAssertTests { - @Nested class AttributesTests { @@ -90,7 +88,6 @@ public class AbstractHttpServletRequestAssertTests { private HttpServletRequest createRequest(Map attributes) { MockHttpServletRequest request = new MockHttpServletRequest(); HttpSession session = request.getSession(); - Assertions.assertThat(session).isNotNull(); attributes.forEach(session::setAttribute); return request; } @@ -127,19 +124,18 @@ public class AbstractHttpServletRequestAssertTests { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(request).hasAsyncStarted(false)) .withMessage("Async expected not to have started"); - } - private static ResponseAssert assertThat(HttpServletRequest response) { - return new ResponseAssert(response); + private static RequestAssert assertThat(HttpServletRequest request) { + return new RequestAssert(request); } - private static final class ResponseAssert extends AbstractHttpServletRequestAssert { + private static final class RequestAssert extends AbstractHttpServletRequestAssert { - ResponseAssert(HttpServletRequest actual) { - super(actual, ResponseAssert.class); + RequestAssert(HttpServletRequest actual) { + super(actual, RequestAssert.class); } } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/HandlerResultAssertTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/HandlerResultAssertTests.java index 94532bbfba3..ea9e483c7b3 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/HandlerResultAssertTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/HandlerResultAssertTests.java @@ -19,7 +19,6 @@ package org.springframework.test.web.servlet.assertj; import java.lang.reflect.Method; import org.assertj.core.api.AssertProvider; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.http.ResponseEntity; @@ -120,7 +119,7 @@ class HandlerResultAssertTests { private static Method method(Class target, String name, Class... parameterTypes) { Method method = ReflectionUtils.findMethod(target, name, parameterTypes); - Assertions.assertThat(method).isNotNull(); + assertThat(method).isNotNull(); return method; }