|
20 | 20 |
|
21 | 21 | import org.jspecify.annotations.Nullable;
|
22 | 22 |
|
| 23 | +import org.springframework.context.ConfigurableApplicationContext; |
23 | 24 | import org.springframework.context.support.AbstractApplicationContext;
|
24 | 25 | import org.springframework.test.context.ContextConfigurationAttributes;
|
25 | 26 | import org.springframework.test.context.ContextCustomizer;
|
26 | 27 | import org.springframework.test.context.ContextCustomizerFactory;
|
| 28 | +import org.springframework.test.context.MergedContextConfiguration; |
27 | 29 |
|
28 | 30 | /**
|
29 | 31 | * @author Sam Brannen
|
|
32 | 34 | class DisplayNameCustomizerFactory implements ContextCustomizerFactory {
|
33 | 35 |
|
34 | 36 | @Override
|
35 |
| - public @Nullable ContextCustomizer createContextCustomizer(Class<?> testClass, |
36 |
| - List<ContextConfigurationAttributes> __) { |
| 37 | + public ContextCustomizer createContextCustomizer(Class<?> testClass, |
| 38 | + List<ContextConfigurationAttributes> configAttributes) { |
37 | 39 |
|
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 | + } |
40 | 66 | }
|
41 | 67 |
|
42 | 68 | }
|
0 commit comments