@@ -69,7 +69,7 @@ public void close() {
69
69
70
70
@ Test
71
71
public void defaultConfiguration () {
72
- registerAndRefreshContext ();
72
+ load ();
73
73
assertThat (this .context .getBean (FreeMarkerViewResolver .class )).isNotNull ();
74
74
assertThat (this .context .getBean (FreeMarkerConfigurer .class )).isNotNull ();
75
75
assertThat (this .context .getBean (FreeMarkerConfig .class )).isNotNull ();
@@ -79,7 +79,7 @@ public void defaultConfiguration() {
79
79
80
80
@ Test
81
81
public void defaultViewResolution () throws Exception {
82
- registerAndRefreshContext ();
82
+ load ();
83
83
MockHttpServletResponse response = render ("home" );
84
84
String result = response .getContentAsString ();
85
85
assertThat (result ).contains ("home" );
@@ -88,7 +88,7 @@ public void defaultViewResolution() throws Exception {
88
88
89
89
@ Test
90
90
public void customContentType () throws Exception {
91
- registerAndRefreshContext ("spring.freemarker.contentType:application/json" );
91
+ load ("spring.freemarker.contentType:application/json" );
92
92
MockHttpServletResponse response = render ("home" );
93
93
String result = response .getContentAsString ();
94
94
assertThat (result ).contains ("home" );
@@ -97,23 +97,23 @@ public void customContentType() throws Exception {
97
97
98
98
@ Test
99
99
public void customPrefix () throws Exception {
100
- registerAndRefreshContext ("spring.freemarker.prefix:prefix/" );
100
+ load ("spring.freemarker.prefix:prefix/" );
101
101
MockHttpServletResponse response = render ("prefixed" );
102
102
String result = response .getContentAsString ();
103
103
assertThat (result ).contains ("prefixed" );
104
104
}
105
105
106
106
@ Test
107
107
public void customSuffix () throws Exception {
108
- registerAndRefreshContext ("spring.freemarker.suffix:.freemarker" );
108
+ load ("spring.freemarker.suffix:.freemarker" );
109
109
MockHttpServletResponse response = render ("suffixed" );
110
110
String result = response .getContentAsString ();
111
111
assertThat (result ).contains ("suffixed" );
112
112
}
113
113
114
114
@ Test
115
115
public void customTemplateLoaderPath () throws Exception {
116
- registerAndRefreshContext (
116
+ load (
117
117
"spring.freemarker.templateLoaderPath:classpath:/custom-templates/" );
118
118
MockHttpServletResponse response = render ("custom" );
119
119
String result = response .getContentAsString ();
@@ -122,14 +122,14 @@ public void customTemplateLoaderPath() throws Exception {
122
122
123
123
@ Test
124
124
public void disableCache () {
125
- registerAndRefreshContext ("spring.freemarker.cache:false" );
125
+ load ("spring.freemarker.cache:false" );
126
126
assertThat (this .context .getBean (FreeMarkerViewResolver .class ).getCacheLimit ())
127
127
.isEqualTo (0 );
128
128
}
129
129
130
130
@ Test
131
131
public void allowSessionOverride () {
132
- registerAndRefreshContext ("spring.freemarker.allow-session-override:true" );
132
+ load ("spring.freemarker.allow-session-override:true" );
133
133
AbstractTemplateViewResolver viewResolver = this .context
134
134
.getBean (FreeMarkerViewResolver .class );
135
135
assertThat (ReflectionTestUtils .getField (viewResolver , "allowSessionOverride" ))
@@ -139,14 +139,14 @@ public void allowSessionOverride() {
139
139
@ SuppressWarnings ("deprecation" )
140
140
@ Test
141
141
public void customFreeMarkerSettings () {
142
- registerAndRefreshContext ("spring.freemarker.settings.boolean_format:yup,nope" );
142
+ load ("spring.freemarker.settings.boolean_format:yup,nope" );
143
143
assertThat (this .context .getBean (FreeMarkerConfigurer .class ).getConfiguration ()
144
144
.getSetting ("boolean_format" )).isEqualTo ("yup,nope" );
145
145
}
146
146
147
147
@ Test
148
148
public void renderTemplate () throws Exception {
149
- registerAndRefreshContext ();
149
+ load ();
150
150
FreeMarkerConfigurer freemarker = this .context
151
151
.getBean (FreeMarkerConfigurer .class );
152
152
StringWriter writer = new StringWriter ();
@@ -156,13 +156,13 @@ public void renderTemplate() throws Exception {
156
156
157
157
@ Test
158
158
public void registerResourceHandlingFilterDisabledByDefault () {
159
- registerAndRefreshContext ();
159
+ load ();
160
160
assertThat (this .context .getBeansOfType (FilterRegistrationBean .class )).isEmpty ();
161
161
}
162
162
163
163
@ Test
164
164
public void registerResourceHandlingFilterOnlyIfResourceChainIsEnabled () {
165
- registerAndRefreshContext ("spring.resources.chain.enabled:true" );
165
+ load ("spring.resources.chain.enabled:true" );
166
166
FilterRegistrationBean <?> registration = this .context
167
167
.getBean (FilterRegistrationBean .class );
168
168
assertThat (registration .getFilter ())
@@ -175,7 +175,7 @@ public void registerResourceHandlingFilterOnlyIfResourceChainIsEnabled() {
175
175
@ SuppressWarnings ("rawtypes" )
176
176
public void registerResourceHandlingFilterWithOtherRegistrationBean () {
177
177
// gh-14897
178
- registerAndRefreshContext (FilterRegistrationConfiguration .class ,
178
+ load (FilterRegistrationConfiguration .class ,
179
179
"spring.resources.chain.enabled:true" );
180
180
Map <String , FilterRegistrationBean > beans = this .context
181
181
.getBeansOfType (FilterRegistrationBean .class );
@@ -187,11 +187,11 @@ public void registerResourceHandlingFilterWithOtherRegistrationBean() {
187
187
EnumSet .of (DispatcherType .REQUEST , DispatcherType .ERROR ));
188
188
}
189
189
190
- private void registerAndRefreshContext (String ... env ) {
191
- registerAndRefreshContext (BaseConfiguration .class , env );
190
+ private void load (String ... env ) {
191
+ load (BaseConfiguration .class , env );
192
192
}
193
193
194
- private void registerAndRefreshContext (Class <?> config , String ... env ) {
194
+ private void load (Class <?> config , String ... env ) {
195
195
this .context = new AnnotationConfigWebApplicationContext ();
196
196
this .context .setServletContext (new MockServletContext ());
197
197
TestPropertyValues .of (env ).applyTo (this .context );
0 commit comments