16
16
17
17
package org .springframework .test .context ;
18
18
19
+ import java .util .Arrays ;
20
+ import java .util .SortedSet ;
21
+ import java .util .TreeSet ;
22
+
19
23
import org .springframework .core .style .ToStringCreator ;
20
24
import org .springframework .util .ObjectUtils ;
25
+ import org .springframework .util .StringUtils ;
21
26
22
27
/**
23
28
* TODO [SPR-8386] Document MergedContextConfiguration.
@@ -40,6 +45,26 @@ public class MergedContextConfiguration {
40
45
private final ContextLoader contextLoader ;
41
46
42
47
48
+ private static String [] processLocations (String [] locations ) {
49
+ return locations == null ? new String [] {} : locations ;
50
+ }
51
+
52
+ private static Class <?>[] processClasses (Class <?>[] classes ) {
53
+ return classes == null ? new Class <?>[] {} : classes ;
54
+ }
55
+
56
+ private static String [] processActiveProfiles (String [] activeProfiles ) {
57
+ if (activeProfiles == null ) {
58
+ return new String [] {};
59
+ }
60
+
61
+ // Active profiles must be unique and sorted due to cache key generation
62
+ // in TestContext. Specifically, profile sets {foo,bar} and {bar,foo}
63
+ // must both result in the same array (e.g., [bar,foo]).
64
+ SortedSet <String > sortedProfilesSet = new TreeSet <String >(Arrays .asList (activeProfiles ));
65
+ return StringUtils .toStringArray (sortedProfilesSet );
66
+ }
67
+
43
68
/**
44
69
* TODO Document MergedContextConfiguration constructor.
45
70
*
@@ -52,9 +77,9 @@ public class MergedContextConfiguration {
52
77
public MergedContextConfiguration (Class <?> testClass , String [] locations , Class <?>[] classes ,
53
78
String [] activeProfiles , ContextLoader contextLoader ) {
54
79
this .testClass = testClass ;
55
- this .locations = locations ;
56
- this .classes = classes ;
57
- this .activeProfiles = activeProfiles ;
80
+ this .locations = processLocations ( locations ) ;
81
+ this .classes = processClasses ( classes ) ;
82
+ this .activeProfiles = processActiveProfiles ( activeProfiles ) ;
58
83
this .contextLoader = contextLoader ;
59
84
}
60
85
0 commit comments