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