From c5566e275558efcfb364190059fbe53c986c760d Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 27 May 2015 15:13:44 +0200 Subject: [PATCH] Fix broken build Update EnableAutoConfigurationImportSelectorTests to match the new `excludeName` property. Closes gh-2660 --- ...EnableAutoConfigurationImportSelector.java | 12 +++---- ...eAutoConfigurationImportSelectorTests.java | 36 ++++++++++++++++--- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java index 633faa27b4..eddff6c0ae 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java @@ -74,8 +74,11 @@ class EnableAutoConfigurationImportSelector implements DeferredImportSelector, this.beanClassLoader))); // Remove those specifically disabled - exclude(Arrays.asList(attributes.getStringArray("exclude")), factories); - exclude(Arrays.asList(attributes.getStringArray("excludeName")), factories); + List excluded = new ArrayList(); + excluded.addAll(Arrays.asList(attributes.getStringArray("exclude"))); + excluded.addAll(Arrays.asList(attributes.getStringArray("excludeName"))); + factories.removeAll(excluded); + ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded); // Sort factories = new AutoConfigurationSorter(this.resourceLoader) @@ -88,11 +91,6 @@ class EnableAutoConfigurationImportSelector implements DeferredImportSelector, } } - private void exclude(List excluded, List factories) { - factories.removeAll(excluded); - ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded); - } - @Override public void setBeanClassLoader(ClassLoader classLoader) { this.beanClassLoader = classLoader; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java index d9017a9b5d..010a18145f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java @@ -27,12 +27,14 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; +import org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.core.type.AnnotationMetadata; import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; @@ -43,6 +45,7 @@ import static org.mockito.BDDMockito.given; * Tests for {@link EnableAutoConfigurationImportSelector} * * @author Andy Wilkinson + * @author Stephane Nicoll */ @RunWith(MockitoJUnitRunner.class) public class EnableAutoConfigurationImportSelectorTests { @@ -65,7 +68,7 @@ public class EnableAutoConfigurationImportSelectorTests { @Test public void importsAreSelected() { - configureExclusions(); + configureExclusions(new String[0], new String[0]); String[] imports = this.importSelector.selectImports(this.annotationMetadata); assertThat( imports.length, @@ -77,8 +80,8 @@ public class EnableAutoConfigurationImportSelectorTests { } @Test - public void exclusionsAreApplied() { - configureExclusions(FreeMarkerAutoConfiguration.class.getName()); + public void classExclusionsAreApplied() { + configureExclusions(new String[]{FreeMarkerAutoConfiguration.class.getName()}, new String[0]); String[] imports = this.importSelector.selectImports(this.annotationMetadata); assertThat(imports.length, is(equalTo(getAutoConfigurationClassNames().size() - 1))); @@ -86,12 +89,35 @@ public class EnableAutoConfigurationImportSelectorTests { contains(FreeMarkerAutoConfiguration.class.getName())); } - private void configureExclusions(String... exclusions) { + @Test + public void classNamesExclusionsAreApplied() { + configureExclusions(new String[0], new String[]{VelocityAutoConfiguration.class.getName()}); + String[] imports = this.importSelector.selectImports(this.annotationMetadata); + assertThat(imports.length, + is(equalTo(getAutoConfigurationClassNames().size() - 1))); + assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions(), + contains(VelocityAutoConfiguration.class.getName())); + } + + @Test + public void bothExclusionsAreApplied() { + configureExclusions(new String[]{VelocityAutoConfiguration.class.getName()}, + new String[]{FreeMarkerAutoConfiguration.class.getName()}); + String[] imports = this.importSelector.selectImports(this.annotationMetadata); + assertThat(imports.length, + is(equalTo(getAutoConfigurationClassNames().size() - 2))); + assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions(), + containsInAnyOrder(FreeMarkerAutoConfiguration.class.getName(), + VelocityAutoConfiguration.class.getName())); + } + + private void configureExclusions(String[] classExclusion, String[] nameExclusion) { given( this.annotationMetadata.getAnnotationAttributes( EnableAutoConfiguration.class.getName(), true)).willReturn( this.annotationAttributes); - given(this.annotationAttributes.getStringArray("exclude")).willReturn(exclusions); + given(this.annotationAttributes.getStringArray("exclude")).willReturn(classExclusion); + given(this.annotationAttributes.getStringArray("excludeName")).willReturn(nameExclusion); } private List getAutoConfigurationClassNames() {