From 26bbb6e767e9a4a7132e6ca88a873d2feb9f686f Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 28 Mar 2016 16:17:47 +0200 Subject: [PATCH] Polishing --- .../support/AbstractTestContextBootstrapper.java | 4 ++-- .../test/context/support/ContextLoaderUtils.java | 7 +++---- .../ContextLoaderUtilsContextHierarchyTests.java | 12 +++++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java index 8fa0040e1a..51bbee68da 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java @@ -31,8 +31,8 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; -import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationAwareOrderComparator; +import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.test.context.BootstrapContext; import org.springframework.test.context.CacheAwareContextLoaderDelegate; @@ -278,7 +278,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot return buildDefaultMergedContextConfiguration(testClass, cacheAwareContextLoaderDelegate); } - if (AnnotatedElementUtils.findMergedAnnotation(testClass, ContextHierarchy.class) != null) { + if (AnnotationUtils.findAnnotation(testClass, ContextHierarchy.class) != null) { Map> hierarchyMap = ContextLoaderUtils.buildContextHierarchyMap(testClass); MergedContextConfiguration parentConfig = null; MergedContextConfiguration mergedConfig = null; diff --git a/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java index fb3aab8502..49819fd546 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java @@ -81,13 +81,12 @@ abstract class ContextLoaderUtils { * (must not be {@code null}) * @return the list of lists of configuration attributes for the specified class; * never {@code null} - * @throws IllegalArgumentException if the supplied class is {@code null}; if + * @throws IllegalArgumentException if the supplied class is {@code null}; or if * neither {@code @ContextConfiguration} nor {@code @ContextHierarchy} is - * present on the supplied class; or if a test class or composed annotation + * present on the supplied class + * @throws IllegalStateException if a test class or composed annotation * in the class hierarchy declares both {@code @ContextConfiguration} and * {@code @ContextHierarchy} as top-level annotations. - * @throws IllegalStateException if no class in the class hierarchy declares - * {@code @ContextHierarchy}. * @since 3.2.2 * @see #buildContextHierarchyMap(Class) * @see #resolveContextConfigurationAttributes(Class) diff --git a/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java b/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java index 810910c993..37025fdf0f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsContextHierarchyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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. @@ -22,7 +22,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.junit.Ignore; import org.junit.Test; import org.springframework.context.ApplicationContextInitializer; @@ -60,10 +59,13 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf resolveContextHierarchyAttributes(SingleTestClassWithContextConfigurationAndContextHierarchyOnSingleMetaAnnotation.class); } - @Test(expected = IllegalStateException.class) - @Ignore // an upfront findAnnotation check just for an assertion seems too expensive + @Test public void resolveContextHierarchyAttributesForSingleTestClassWithImplicitSingleLevelContextHierarchy() { - resolveContextHierarchyAttributes(BareAnnotations.class); + List> hierarchyAttributes = resolveContextHierarchyAttributes(BareAnnotations.class); + assertEquals(1, hierarchyAttributes.size()); + List configAttributesList = hierarchyAttributes.get(0); + assertEquals(1, configAttributesList.size()); + debugConfigAttributes(configAttributesList); } @Test