27
27
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
28
28
import org .springframework .boot .autoconfigure .condition .ConditionEvaluationReport ;
29
29
import org .springframework .boot .autoconfigure .freemarker .FreeMarkerAutoConfiguration ;
30
+ import org .springframework .boot .autoconfigure .velocity .VelocityAutoConfiguration ;
30
31
import org .springframework .core .annotation .AnnotationAttributes ;
31
32
import org .springframework .core .io .DefaultResourceLoader ;
32
33
import org .springframework .core .io .support .SpringFactoriesLoader ;
33
34
import org .springframework .core .type .AnnotationMetadata ;
34
35
35
36
import static org .hamcrest .Matchers .contains ;
37
+ import static org .hamcrest .Matchers .containsInAnyOrder ;
36
38
import static org .hamcrest .Matchers .equalTo ;
37
39
import static org .hamcrest .Matchers .hasSize ;
38
40
import static org .hamcrest .Matchers .is ;
43
45
* Tests for {@link EnableAutoConfigurationImportSelector}
44
46
*
45
47
* @author Andy Wilkinson
48
+ * @author Stephane Nicoll
46
49
*/
47
50
@ RunWith (MockitoJUnitRunner .class )
48
51
public class EnableAutoConfigurationImportSelectorTests {
@@ -65,7 +68,7 @@ public void configureImportSelector() {
65
68
66
69
@ Test
67
70
public void importsAreSelected () {
68
- configureExclusions ();
71
+ configureExclusions (new String [ 0 ], new String [ 0 ] );
69
72
String [] imports = this .importSelector .selectImports (this .annotationMetadata );
70
73
assertThat (
71
74
imports .length ,
@@ -77,21 +80,44 @@ EnableAutoConfiguration.class, getClass().getClassLoader())
77
80
}
78
81
79
82
@ Test
80
- public void exclusionsAreApplied () {
81
- configureExclusions (FreeMarkerAutoConfiguration .class .getName ());
83
+ public void classExclusionsAreApplied () {
84
+ configureExclusions (new String []{ FreeMarkerAutoConfiguration .class .getName ()}, new String [ 0 ] );
82
85
String [] imports = this .importSelector .selectImports (this .annotationMetadata );
83
86
assertThat (imports .length ,
84
87
is (equalTo (getAutoConfigurationClassNames ().size () - 1 )));
85
88
assertThat (ConditionEvaluationReport .get (this .beanFactory ).getExclusions (),
86
89
contains (FreeMarkerAutoConfiguration .class .getName ()));
87
90
}
88
91
89
- private void configureExclusions (String ... exclusions ) {
92
+ @ Test
93
+ public void classNamesExclusionsAreApplied () {
94
+ configureExclusions (new String [0 ], new String []{VelocityAutoConfiguration .class .getName ()});
95
+ String [] imports = this .importSelector .selectImports (this .annotationMetadata );
96
+ assertThat (imports .length ,
97
+ is (equalTo (getAutoConfigurationClassNames ().size () - 1 )));
98
+ assertThat (ConditionEvaluationReport .get (this .beanFactory ).getExclusions (),
99
+ contains (VelocityAutoConfiguration .class .getName ()));
100
+ }
101
+
102
+ @ Test
103
+ public void bothExclusionsAreApplied () {
104
+ configureExclusions (new String []{VelocityAutoConfiguration .class .getName ()},
105
+ new String []{FreeMarkerAutoConfiguration .class .getName ()});
106
+ String [] imports = this .importSelector .selectImports (this .annotationMetadata );
107
+ assertThat (imports .length ,
108
+ is (equalTo (getAutoConfigurationClassNames ().size () - 2 )));
109
+ assertThat (ConditionEvaluationReport .get (this .beanFactory ).getExclusions (),
110
+ containsInAnyOrder (FreeMarkerAutoConfiguration .class .getName (),
111
+ VelocityAutoConfiguration .class .getName ()));
112
+ }
113
+
114
+ private void configureExclusions (String [] classExclusion , String [] nameExclusion ) {
90
115
given (
91
116
this .annotationMetadata .getAnnotationAttributes (
92
117
EnableAutoConfiguration .class .getName (), true )).willReturn (
93
118
this .annotationAttributes );
94
- given (this .annotationAttributes .getStringArray ("exclude" )).willReturn (exclusions );
119
+ given (this .annotationAttributes .getStringArray ("exclude" )).willReturn (classExclusion );
120
+ given (this .annotationAttributes .getStringArray ("excludeName" )).willReturn (nameExclusion );
95
121
}
96
122
97
123
private List <String > getAutoConfigurationClassNames () {
0 commit comments