60
60
*/
61
61
class ImportsContextCustomizer implements ContextCustomizer {
62
62
63
- static final String TEST_CLASS_ATTRIBUTE = "testClass " ;
63
+ private static final String TEST_CLASS_NAME_ATTRIBUTE = "testClassName " ;
64
64
65
- private final Class <?> testClass ;
65
+ private final String testClassName ;
66
66
67
67
private final ContextCustomizerKey key ;
68
68
69
69
ImportsContextCustomizer (Class <?> testClass ) {
70
- this .testClass = testClass ;
70
+ this .testClassName = testClass . getName () ;
71
71
this .key = new ContextCustomizerKey (testClass );
72
72
}
73
73
@@ -84,13 +84,13 @@ private void registerCleanupPostProcessor(BeanDefinitionRegistry registry, Annot
84
84
BeanDefinition definition = registerBean (registry , reader , ImportsCleanupPostProcessor .BEAN_NAME ,
85
85
ImportsCleanupPostProcessor .class );
86
86
definition .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
87
- definition .getConstructorArgumentValues ().addIndexedArgumentValue (0 , this .testClass );
87
+ definition .getConstructorArgumentValues ().addIndexedArgumentValue (0 , this .testClassName );
88
88
}
89
89
90
90
private void registerImportsConfiguration (BeanDefinitionRegistry registry , AnnotatedBeanDefinitionReader reader ) {
91
91
BeanDefinition definition = registerBean (registry , reader , ImportsConfiguration .BEAN_NAME ,
92
92
ImportsConfiguration .class );
93
- definition .setAttribute (TEST_CLASS_ATTRIBUTE , this .testClass );
93
+ definition .setAttribute (TEST_CLASS_NAME_ATTRIBUTE , this .testClassName );
94
94
}
95
95
96
96
private BeanDefinitionRegistry getBeanDefinitionRegistry (ApplicationContext context ) {
@@ -162,8 +162,8 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
162
162
@ Override
163
163
public String [] selectImports (AnnotationMetadata importingClassMetadata ) {
164
164
BeanDefinition definition = this .beanFactory .getBeanDefinition (ImportsConfiguration .BEAN_NAME );
165
- Object testClass = ( definition != null ) ? definition .getAttribute (TEST_CLASS_ATTRIBUTE ) : null ;
166
- return (testClass != null ) ? new String [] { (( Class <?>) testClass ). getName () } : NO_IMPORTS ;
165
+ Object testClassName = definition .getAttribute (TEST_CLASS_NAME_ATTRIBUTE ) ;
166
+ return (testClassName != null ) ? new String [] { (String ) testClassName } : NO_IMPORTS ;
167
167
}
168
168
169
169
}
@@ -177,10 +177,10 @@ static class ImportsCleanupPostProcessor implements BeanDefinitionRegistryPostPr
177
177
178
178
static final String BEAN_NAME = ImportsCleanupPostProcessor .class .getName ();
179
179
180
- private final Class <?> testClass ;
180
+ private final String testClassName ;
181
181
182
- ImportsCleanupPostProcessor (Class <?> testClass ) {
183
- this .testClass = testClass ;
182
+ ImportsCleanupPostProcessor (String testClassName ) {
183
+ this .testClassName = testClassName ;
184
184
}
185
185
186
186
@ Override
@@ -193,7 +193,7 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) t
193
193
String [] names = registry .getBeanDefinitionNames ();
194
194
for (String name : names ) {
195
195
BeanDefinition definition = registry .getBeanDefinition (name );
196
- if (this .testClass . getName () .equals (definition .getBeanClassName ())) {
196
+ if (this .testClassName .equals (definition .getBeanClassName ())) {
197
197
registry .removeBeanDefinition (name );
198
198
}
199
199
}
0 commit comments