Reduce code duplication in ContextLoaderUtils

Prior to this commit, the following two methods in ContextLoaderUtils
contained almost identical loops for traversing the test class
hierarchy:

 - resolveContextLoaderClass(Class<?>, String)
 - resolveContextConfigurationAttributes(Class<?>)

With this commit, resolveContextLoaderClass() no longer traverses the
class hierarchy. Instead, it now works directly with the resolved list
of ContextConfigurationAttributes, thereby removing code duplication.

Issue: SPR-9918
This commit is contained in:
Sam Brannen
2012-10-27 22:29:55 +02:00
parent 397d20b55a
commit 33d5b011d3
2 changed files with 90 additions and 103 deletions

View File

@@ -16,8 +16,8 @@
package org.springframework.test.context;
import static org.springframework.test.context.ContextLoaderUtils.*;
import static org.junit.Assert.*;
import static org.springframework.test.context.ContextLoaderUtils.*;
import java.util.Arrays;
import java.util.Collections;
@@ -140,8 +140,8 @@ public class ContextLoaderUtilsTests {
List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(LocationsBar.class);
assertNotNull(attributesList);
assertEquals(2, attributesList.size());
assertLocationsFooAttributes(attributesList.get(0));
assertLocationsBarAttributes(attributesList.get(1));
assertLocationsBarAttributes(attributesList.get(0));
assertLocationsFooAttributes(attributesList.get(1));
}
@Test
@@ -149,8 +149,8 @@ public class ContextLoaderUtilsTests {
List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(ClassesBar.class);
assertNotNull(attributesList);
assertEquals(2, attributesList.size());
assertClassesFooAttributes(attributesList.get(0));
assertClassesBarAttributes(attributesList.get(1));
assertClassesBarAttributes(attributesList.get(0));
assertClassesFooAttributes(attributesList.get(1));
}
@Test(expected = IllegalArgumentException.class)