11package digital .pragmatech .testing ;
22
3+ import org .springframework .test .context .MergedContextConfiguration ;
4+
35import java .time .Instant ;
4- import java .util .Arrays ;
5- import java .util .Collections ;
6- import java .util .LinkedHashMap ;
7- import java .util .List ;
8- import java .util .Map ;
9- import java .util .Optional ;
10- import java .util .Set ;
6+ import java .util .*;
117import java .util .concurrent .ConcurrentHashMap ;
128import java .util .concurrent .CopyOnWriteArrayList ;
139import java .util .concurrent .atomic .AtomicInteger ;
1410import java .util .stream .Collectors ;
1511
16- import org .springframework .test .context .MergedContextConfiguration ;
17-
1812/**
1913 * Entry representing a cached context configuration.
2014 */
@@ -181,8 +175,10 @@ public Map<String, Object> getConfigurationSummary() {
181175
182176 summary .put ("properties" , configuration .getPropertySourceProperties ().length + " properties" );
183177 summary .put ("parentContext" , configuration .getParent ());
184- summary .put ("contextCustomizers" , configuration .getContextCustomizers ());
185- summary .put ("locations" , String .join ("," , configuration .getLocations ()));
178+ // contextCustomizers equality is based on Set. Convert to ordered String representation to simplify comparison
179+ summary .put ("contextCustomizers" , prettyPrintCollection (toStringSortedSet (configuration .getContextCustomizers ())));
180+ // locations equality is based on String[], no ordering
181+ summary .put ("locations" , String .join ("," , prettyPrintCollection (Arrays .asList (configuration .getLocations ()))));
186182
187183 summary .put ("contextInitializers" , configuration .getContextInitializerClasses ().stream ()
188184 .map (Class ::getSimpleName )
@@ -193,4 +189,36 @@ public Map<String, Object> getConfigurationSummary() {
193189
194190 return summary ;
195191 }
192+
193+ /**
194+ * Convert collection of objects to SortedSet of String. This can be helpful for visually comparable representations.
195+ *
196+ * TODO move to string utility class
197+ *
198+ * @param elements
199+ * @return
200+ */
201+ private static SortedSet <String > toStringSortedSet (Collection <?> elements ) {
202+ var set = new TreeSet <String >();
203+ elements .forEach (e -> set .add (Objects .toString (e )));
204+ return set ;
205+ }
206+
207+ /**
208+ * Pretty format collection elements (new line for each element).
209+ *
210+ * TODO move to string utility class
211+ *
212+ * @param elements
213+ * @return
214+ */
215+ private static String prettyPrintCollection (Collection <String > elements ) {
216+ if (elements == null ) {
217+ return "" ;
218+ }
219+ if (elements .isEmpty ()) {
220+ return "[]" ;
221+ }
222+ return "[\n " + String .join (",\n " , elements ) + "\n ]" ;
223+ }
196224}
0 commit comments