diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java index b3576fb88d..30559d8bdf 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java @@ -1300,8 +1300,8 @@ class MergedAnnotationsTests { @Test void getDirectWithAttributeAliasesWithDifferentValues() throws Exception { Method method = WebController.class.getMethod("handleMappedWithDifferentPathAndValueAttributes"); - assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> - MergedAnnotations.from(method).get(RequestMapping.class)) + assertThatExceptionOfType(AnnotationConfigurationException.class) + .isThrownBy(() -> MergedAnnotations.from(method).get(RequestMapping.class)) .withMessageContaining("attribute 'path' and its alias 'value'") .withMessageContaining("values of [{/test}] and [{/enigma}]"); } @@ -1363,16 +1363,16 @@ class MergedAnnotationsTests { @Test @SuppressWarnings("deprecation") void streamRepeatableDeclaredOnClassWithAttributeAliases() { - assertThat(MergedAnnotations.from(HierarchyClass.class).stream( - TestConfiguration.class)).isEmpty(); - RepeatableContainers containers = RepeatableContainers.of(TestConfiguration.class, - Hierarchy.class); + assertThat(MergedAnnotations.from(HierarchyClass.class).stream(TestConfiguration.class)).isEmpty(); + RepeatableContainers containers = RepeatableContainers.of(TestConfiguration.class, Hierarchy.class); MergedAnnotations annotations = MergedAnnotations.from(HierarchyClass.class, SearchStrategy.DIRECT, containers, AnnotationFilter.NONE); - assertThat(annotations.stream(TestConfiguration.class).map( - annotation -> annotation.getString("location"))).containsExactly("A", "B"); - assertThat(annotations.stream(TestConfiguration.class).map( - annotation -> annotation.getString("value"))).containsExactly("A", "B"); + assertThat(annotations.stream(TestConfiguration.class) + .map(annotation -> annotation.getString("location"))) + .containsExactly("A", "B"); + assertThat(annotations.stream(TestConfiguration.class) + .map(annotation -> annotation.getString("value"))) + .containsExactly("A", "B"); } @Test @@ -1435,14 +1435,12 @@ class MergedAnnotationsTests { MyRepeatable[] annotations = searchStrategy == SearchStrategy.DIRECT ? element.getDeclaredAnnotationsByType(MyRepeatable.class) : element.getAnnotationsByType(MyRepeatable.class); - assertThat(Arrays.stream(annotations).map(MyRepeatable::value)).containsExactly( - expected); + assertThat(annotations).extracting(MyRepeatable::value).containsExactly(expected); } private void testExplicitRepeatables(SearchStrategy searchStrategy, Class element, String[] expected) { MergedAnnotations annotations = MergedAnnotations.from(element, searchStrategy, - RepeatableContainers.of(MyRepeatable.class, MyRepeatableContainer.class), - AnnotationFilter.PLAIN); + RepeatableContainers.of(MyRepeatable.class, MyRepeatableContainer.class)); Stream values = annotations.stream(MyRepeatable.class) .filter(MergedAnnotationPredicates.firstRunOf(MergedAnnotation::getAggregateIndex)) .map(annotation -> annotation.getString("value")); @@ -1594,8 +1592,8 @@ class MergedAnnotationsTests { AliasForWithMissingAttributeDeclarationClass.class.getAnnotation( AliasForWithMissingAttributeDeclaration.class); - assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy( - () -> MergedAnnotation.from(annotation)) + assertThatExceptionOfType(AnnotationConfigurationException.class) + .isThrownBy(() -> MergedAnnotation.from(annotation)) .withMessageStartingWith("@AliasFor declaration on attribute 'foo' in annotation") .withMessageContaining(AliasForWithMissingAttributeDeclaration.class.getName()) .withMessageContaining("points to itself"); @@ -1607,8 +1605,8 @@ class MergedAnnotationsTests { AliasForWithDuplicateAttributeDeclarationClass.class.getAnnotation( AliasForWithDuplicateAttributeDeclaration.class); - assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy( - () -> MergedAnnotation.from(annotation)) + assertThatExceptionOfType(AnnotationConfigurationException.class) + .isThrownBy(() -> MergedAnnotation.from(annotation)) .withMessageStartingWith("In @AliasFor declared on attribute 'foo' in annotation") .withMessageContaining(AliasForWithDuplicateAttributeDeclaration.class.getName()) .withMessageContaining("attribute 'attribute' and its alias 'value' are present with values of 'baz' and 'bar'"); @@ -1619,8 +1617,8 @@ class MergedAnnotationsTests { AliasForNonexistentAttribute annotation = AliasForNonexistentAttributeClass.class.getAnnotation( AliasForNonexistentAttribute.class); - assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy( - () -> MergedAnnotation.from(annotation)) + assertThatExceptionOfType(AnnotationConfigurationException.class) + .isThrownBy(() -> MergedAnnotation.from(annotation)) .withMessageStartingWith("@AliasFor declaration on attribute 'foo' in annotation") .withMessageContaining(AliasForNonexistentAttribute.class.getName()) .withMessageContaining("declares an alias for 'bar' which is not present"); @@ -1632,8 +1630,8 @@ class MergedAnnotationsTests { AliasForWithMirroredAliasForWrongAttributeClass.class.getAnnotation( AliasForWithMirroredAliasForWrongAttribute.class); - assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy( - () -> MergedAnnotation.from(annotation)) + assertThatExceptionOfType(AnnotationConfigurationException.class) + .isThrownBy(() -> MergedAnnotation.from(annotation)) .withMessage("@AliasFor declaration on attribute 'bar' in annotation [" + AliasForWithMirroredAliasForWrongAttribute.class.getName() + "] declares an alias for 'quux' which is not present."); @@ -1688,8 +1686,8 @@ class MergedAnnotationsTests { AliasedComposedTestConfigurationNotMetaPresentClass.class.getAnnotation( AliasedComposedTestConfigurationNotMetaPresent.class); - assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy( - () -> MergedAnnotation.from(annotation)) + assertThatExceptionOfType(AnnotationConfigurationException.class) + .isThrownBy(() -> MergedAnnotation.from(annotation)) .withMessageStartingWith("@AliasFor declaration on attribute 'xmlConfigFile' in annotation") .withMessageContaining(AliasedComposedTestConfigurationNotMetaPresent.class.getName()) .withMessageContaining("declares an alias for attribute 'location' in annotation") @@ -1781,8 +1779,8 @@ class MergedAnnotationsTests { ImplicitAliasesWithMissingDefaultValuesTestConfiguration.class; ImplicitAliasesWithMissingDefaultValuesTestConfiguration config = clazz.getAnnotation(annotationType); - assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy( - () -> MergedAnnotation.from(clazz, config)) + assertThatExceptionOfType(AnnotationConfigurationException.class) + .isThrownBy(() -> MergedAnnotation.from(clazz, config)) .withMessageStartingWith("Misconfigured aliases:") .withMessageContaining("attribute 'location1' in annotation [" + annotationType.getName() + "]") .withMessageContaining("attribute 'location2' in annotation [" + annotationType.getName() + "]") @@ -1796,8 +1794,8 @@ class MergedAnnotationsTests { ImplicitAliasesWithDifferentDefaultValuesTestConfiguration.class; ImplicitAliasesWithDifferentDefaultValuesTestConfiguration config = clazz.getAnnotation(annotationType); - assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy( - () -> MergedAnnotation.from(clazz, config)) + assertThatExceptionOfType(AnnotationConfigurationException.class) + .isThrownBy(() -> MergedAnnotation.from(clazz, config)) .withMessageStartingWith("Misconfigured aliases:") .withMessageContaining("attribute 'location1' in annotation [" + annotationType.getName() + "]") .withMessageContaining("attribute 'location2' in annotation [" + annotationType.getName() + "]") @@ -1893,8 +1891,8 @@ class MergedAnnotationsTests { @Test void synthesizeWhenAttributeAliasesWithDifferentValues() { - assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> - MergedAnnotation.from(TestConfigurationMismatch.class.getAnnotation(TestConfiguration.class)).synthesize()); + assertThatExceptionOfType(AnnotationConfigurationException.class) + .isThrownBy(() -> MergedAnnotation.from(TestConfigurationMismatch.class.getAnnotation(TestConfiguration.class))); } @Test @@ -1958,8 +1956,8 @@ class MergedAnnotationsTests { } private void testMissingTextAttribute(Map attributes) { - assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() -> - MergedAnnotation.of(AnnotationWithoutDefaults.class, attributes).synthesize().text()) + assertThatExceptionOfType(NoSuchElementException.class) + .isThrownBy(() -> MergedAnnotation.of(AnnotationWithoutDefaults.class, attributes).synthesize().text()) .withMessage("No value found for attribute named 'text' in merged annotation " + AnnotationWithoutDefaults.class.getCanonicalName()); } @@ -1968,7 +1966,8 @@ class MergedAnnotationsTests { void synthesizeFromMapWithAttributeOfIncorrectType() { Map map = Collections.singletonMap("value", 42L); MergedAnnotation annotation = MergedAnnotation.of(Component.class, map); - assertThatIllegalStateException().isThrownBy(() -> annotation.synthesize().value()) + assertThatIllegalStateException() + .isThrownBy(() -> annotation.synthesize().value()) .withMessage("Attribute 'value' in annotation " + "org.springframework.core.testfixture.stereotype.Component should be " + "compatible with java.lang.String but a java.lang.Long value was returned"); diff --git a/spring-core/src/test/java/org/springframework/core/annotation/RepeatableContainersTests.java b/spring-core/src/test/java/org/springframework/core/annotation/RepeatableContainersTests.java index ee1f88ee59..a6fa03f3c1 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/RepeatableContainersTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/RepeatableContainersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -161,9 +161,9 @@ class RepeatableContainersTests { RepeatableContainers repeatableContainers = RepeatableContainers.standardRepeatables() .and(ExplicitContainer.class, ExplicitRepeatable.class); assertThat(findRepeatedAnnotationValues(repeatableContainers, StandardRepeatablesTestCase.class, StandardContainer.class)) - .containsExactly("a", "b"); + .containsExactly("a", "b"); assertThat(findRepeatedAnnotationValues(repeatableContainers, ExplicitRepeatablesTestCase.class, ExplicitContainer.class)) - .containsExactly("a", "b"); + .containsExactly("a", "b"); } @Test