Make it easier to add auto-configuration to a test slice

Previously, an entry had to be added to spring.factories using the
name of one of the @AutoConfigure… meta-annotations on the @…Test
annotation as the key. This indirection was unnecessarily complicated.

This commit simplifies things by allowing the name of the @…Test
annotation itself to be used as the key.

Closes gh-6335
This commit is contained in:
Andy Wilkinson
2016-07-06 16:41:06 +01:00
parent 4fe28727ad
commit 3286760073
6 changed files with 26 additions and 3 deletions

View File

@@ -76,12 +76,21 @@ TestSlice createTestSlice(Properties springFactories, ClassMetadata classMetadat
}
Set<String> getImportedAutoConfiguration(Properties springFactories, ClassMetadata classMetadata, AnnotationMetadata annotationMetadata) {
Set<String> importers = findMetaImporters(annotationMetadata)
if (annotationMetadata.isAnnotated('org.springframework.boot.autoconfigure.ImportAutoConfiguration')) {
importers.add(annotationMetadata.className)
}
importers
.collect { autoConfigurationImporter ->
StringUtils.commaDelimitedListToSet(springFactories.get(autoConfigurationImporter))
}.flatten()
}
Set<String> findMetaImporters(AnnotationMetadata annotationMetadata) {
annotationMetadata.annotationTypes
.findAll { annotationType ->
isAutoConfigurationImporter(annotationType, annotationMetadata)
}.collect { autoConfigurationImporter ->
StringUtils.commaDelimitedListToSet(springFactories.get(autoConfigurationImporter))
}.flatten()
}
}
boolean isAutoConfigurationImporter(String annotationType, AnnotationMetadata metadata) {