From 73170224c97a63dd75ad1c9d4d1158c7f693f6b9 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 22 May 2015 17:46:34 +0200 Subject: [PATCH] Polish annotation utility tests --- .../annotation/AnnotatedElementUtilsTests.java | 12 ++++++------ .../core/annotation/AnnotationUtilsTests.java | 17 ++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java index c9bfe2876e..77ba824b5a 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java @@ -573,7 +573,7 @@ public class AnnotatedElementUtilsTests { * Mock of {@link org.springframework.test.context.ContextConfiguration}. */ @Retention(RetentionPolicy.RUNTIME) - static @interface ContextConfig { + @interface ContextConfig { @AliasFor(attribute = "locations") String[] value() default {}; @@ -584,21 +584,21 @@ public class AnnotatedElementUtilsTests { @ContextConfig @Retention(RetentionPolicy.RUNTIME) - static @interface ConventionBasedComposedContextConfig { + @interface ConventionBasedComposedContextConfig { String[] locations() default {}; } @ContextConfig(value = "duplicateDeclaration") @Retention(RetentionPolicy.RUNTIME) - static @interface InvalidConventionBasedComposedContextConfig { + @interface InvalidConventionBasedComposedContextConfig { String[] locations(); } @ContextConfig @Retention(RetentionPolicy.RUNTIME) - static @interface AliasedComposedContextConfig { + @interface AliasedComposedContextConfig { @AliasFor(annotation = ContextConfig.class, attribute = "locations") String[] xmlConfigFiles(); @@ -606,7 +606,7 @@ public class AnnotatedElementUtilsTests { @ContextConfig @Retention(RetentionPolicy.RUNTIME) - static @interface AliasedValueComposedContextConfig { + @interface AliasedValueComposedContextConfig { @AliasFor(annotation = ContextConfig.class, attribute = "value") String[] locations(); @@ -620,7 +620,7 @@ public class AnnotatedElementUtilsTests { */ @ContextConfig(value = "duplicateDeclaration") @Retention(RetentionPolicy.RUNTIME) - static @interface InvalidAliasedComposedContextConfig { + @interface InvalidAliasedComposedContextConfig { @AliasFor(annotation = ContextConfig.class, attribute = "locations") String[] xmlConfigFiles(); diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java index 24ea05a04b..4fe618a728 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java @@ -25,7 +25,6 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import org.junit.Rule; import org.junit.Test; @@ -36,6 +35,7 @@ import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass; import org.springframework.stereotype.Component; import org.springframework.util.ClassUtils; +import static java.util.stream.Collectors.*; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import static org.springframework.core.annotation.AnnotationUtils.*; @@ -480,7 +480,7 @@ public class AnnotationUtilsTests { Method method = InterfaceWithRepeated.class.getMethod("foo"); Set annotations = getRepeatableAnnotation(method, MyRepeatableContainer.class, MyRepeatable.class); assertNotNull(annotations); - List values = annotations.stream().map(MyRepeatable::value).collect(Collectors.toList()); + List values = annotations.stream().map(MyRepeatable::value).collect(toList()); assertThat(values, equalTo(Arrays.asList("a", "b", "c", "meta"))); } @@ -489,10 +489,10 @@ public class AnnotationUtilsTests { Set annotations = getRepeatableAnnotation(TestCase.class, Hierarchy.class, ContextConfig.class); assertNotNull(annotations); - List locations = annotations.stream().map(ContextConfig::locations).collect(Collectors.toList()); + List locations = annotations.stream().map(ContextConfig::locations).collect(toList()); assertThat(locations, equalTo(Arrays.asList("A", "B"))); - List values = annotations.stream().map(ContextConfig::value).collect(Collectors.toList()); + List values = annotations.stream().map(ContextConfig::value).collect(toList()); assertThat(values, equalTo(Arrays.asList("A", "B"))); } @@ -646,14 +646,13 @@ public class AnnotationUtilsTests { ContextConfig[] configs = synthesizedHierarchy.value(); assertNotNull(configs); - for (ContextConfig contextConfig : configs) { - assertThat(contextConfig, instanceOf(SynthesizedAnnotation.class)); - } + assertTrue("nested annotations must be synthesized", + Arrays.stream(configs).allMatch(c -> c instanceof SynthesizedAnnotation)); - List locations = Arrays.stream(configs).map(ContextConfig::locations).collect(Collectors.toList()); + List locations = Arrays.stream(configs).map(ContextConfig::locations).collect(toList()); assertThat(locations, equalTo(Arrays.asList("A", "B"))); - List values = Arrays.stream(configs).map(ContextConfig::value).collect(Collectors.toList()); + List values = Arrays.stream(configs).map(ContextConfig::value).collect(toList()); assertThat(values, equalTo(Arrays.asList("A", "B"))); }