Skip to content

Commit 2e0cc63

Browse files
committed
Implement DisplayNameCustomizer properly
1 parent 7d628b6 commit 2e0cc63

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

spring-test/src/test/java/org/springframework/test/context/cache/DisplayNameCustomizerFactory.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020

2121
import org.jspecify.annotations.Nullable;
2222

23+
import org.springframework.context.ConfigurableApplicationContext;
2324
import org.springframework.context.support.AbstractApplicationContext;
2425
import org.springframework.test.context.ContextConfigurationAttributes;
2526
import org.springframework.test.context.ContextCustomizer;
2627
import org.springframework.test.context.ContextCustomizerFactory;
28+
import org.springframework.test.context.MergedContextConfiguration;
2729

2830
/**
2931
* @author Sam Brannen
@@ -32,11 +34,35 @@
3234
class DisplayNameCustomizerFactory implements ContextCustomizerFactory {
3335

3436
@Override
35-
public @Nullable ContextCustomizer createContextCustomizer(Class<?> testClass,
36-
List<ContextConfigurationAttributes> __) {
37+
public ContextCustomizer createContextCustomizer(Class<?> testClass,
38+
List<ContextConfigurationAttributes> configAttributes) {
3739

38-
return (context, mergedConfig) ->
39-
((AbstractApplicationContext) context).setDisplayName(mergedConfig.getTestClass().getSimpleName());
40+
return new DisplayNameCustomizer(testClass.getSimpleName());
41+
}
42+
43+
44+
private static class DisplayNameCustomizer implements ContextCustomizer {
45+
46+
private final String displayName;
47+
48+
DisplayNameCustomizer(String displayName) {
49+
this.displayName = displayName;
50+
}
51+
52+
@Override
53+
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
54+
((AbstractApplicationContext) context).setDisplayName(this.displayName);
55+
}
56+
57+
@Override
58+
public boolean equals(@Nullable Object other) {
59+
return (this == other || (other != null && getClass() == other.getClass()));
60+
}
61+
62+
@Override
63+
public int hashCode() {
64+
return getClass().hashCode();
65+
}
4066
}
4167

4268
}

0 commit comments

Comments
 (0)