1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
23
23
import java .util .HashMap ;
24
24
import java .util .Locale ;
25
25
import java .util .Map ;
26
-
27
26
import javax .servlet .http .HttpServletResponse ;
28
27
28
+ import freemarker .ext .servlet .AllHttpScopesHashModel ;
29
+ import freemarker .template .Configuration ;
30
+ import freemarker .template .Template ;
31
+ import freemarker .template .TemplateException ;
29
32
import org .junit .Test ;
33
+
30
34
import org .springframework .context .ApplicationContextException ;
31
35
import org .springframework .mock .web .test .MockHttpServletRequest ;
32
36
import org .springframework .mock .web .test .MockHttpServletResponse ;
40
44
import org .springframework .web .servlet .view .InternalResourceView ;
41
45
import org .springframework .web .servlet .view .RedirectView ;
42
46
43
- import freemarker .ext .servlet .AllHttpScopesHashModel ;
44
- import freemarker .template .Configuration ;
45
- import freemarker .template .Template ;
46
- import freemarker .template .TemplateException ;
47
-
48
47
import static org .junit .Assert .*;
49
48
import static org .mockito .BDDMockito .*;
50
49
@@ -70,7 +69,7 @@ public void testNoFreeMarkerConfig() throws Exception {
70
69
}
71
70
catch (ApplicationContextException ex ) {
72
71
// Check there's a helpful error message
73
- assertTrue (ex .getMessage ().indexOf ("FreeMarkerConfig" ) != - 1 );
72
+ assertTrue (ex .getMessage ().contains ("FreeMarkerConfig" ));
74
73
}
75
74
}
76
75
@@ -83,7 +82,7 @@ public void testNoTemplateName() throws Exception {
83
82
}
84
83
catch (IllegalArgumentException ex ) {
85
84
// Check there's a helpful error message
86
- assertTrue (ex .getMessage ().indexOf ("url" ) != - 1 );
85
+ assertTrue (ex .getMessage ().contains ("url" ));
87
86
}
88
87
}
89
88
@@ -94,7 +93,7 @@ public void testValidTemplateName() throws Exception {
94
93
WebApplicationContext wac = mock (WebApplicationContext .class );
95
94
MockServletContext sc = new MockServletContext ();
96
95
97
- Map configs = new HashMap ();
96
+ Map < String , FreeMarkerConfig > configs = new HashMap < String , FreeMarkerConfig > ();
98
97
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer ();
99
98
configurer .setConfiguration (new TestConfiguration ());
100
99
configs .put ("configurer" , configurer );
@@ -110,7 +109,7 @@ public void testValidTemplateName() throws Exception {
110
109
request .setAttribute (DispatcherServlet .LOCALE_RESOLVER_ATTRIBUTE , new AcceptHeaderLocaleResolver ());
111
110
HttpServletResponse response = new MockHttpServletResponse ();
112
111
113
- Map model = new HashMap ();
112
+ Map < String , Object > model = new HashMap < String , Object > ();
114
113
model .put ("myattr" , "myvalue" );
115
114
fv .render (model , request , response );
116
115
@@ -124,7 +123,7 @@ public void testKeepExistingContentType() throws Exception {
124
123
WebApplicationContext wac = mock (WebApplicationContext .class );
125
124
MockServletContext sc = new MockServletContext ();
126
125
127
- Map configs = new HashMap ();
126
+ Map < String , FreeMarkerConfig > configs = new HashMap < String , FreeMarkerConfig > ();
128
127
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer ();
129
128
configurer .setConfiguration (new TestConfiguration ());
130
129
configs .put ("configurer" , configurer );
@@ -141,7 +140,7 @@ public void testKeepExistingContentType() throws Exception {
141
140
HttpServletResponse response = new MockHttpServletResponse ();
142
141
response .setContentType ("myContentType" );
143
142
144
- Map model = new HashMap ();
143
+ Map < String , Object > model = new HashMap < String , Object > ();
145
144
model .put ("myattr" , "myvalue" );
146
145
fv .render (model , request , response );
147
146
@@ -185,7 +184,7 @@ private class TestConfiguration extends Configuration {
185
184
@ Override
186
185
public Template getTemplate (String name , final Locale locale ) throws IOException {
187
186
if (name .equals ("templateName" ) || name .equals ("prefix_test_suffix" )) {
188
- return new Template (name , new StringReader ("test" )) {
187
+ return new Template (name , new StringReader ("test" ), this ) {
189
188
@ Override
190
189
public void process (Object model , Writer writer ) throws TemplateException , IOException {
191
190
assertEquals (Locale .US , locale );
0 commit comments