Fix broken build

Update EnableAutoConfigurationImportSelectorTests to match the new
`excludeName` property.

Closes gh-2660
pull/3050/head
Stephane Nicoll 10 years ago
parent a6f671be3e
commit c5566e2755

@ -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<String> excluded = new ArrayList<String>();
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<String> excluded, List<String> factories) {
factories.removeAll(excluded);
ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded);
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;

@ -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<String> getAutoConfigurationClassNames() {

Loading…
Cancel
Save