32
32
import org .junit .Test ;
33
33
34
34
import org .springframework .beans .factory .config .PropertyPlaceholderConfigurer ;
35
+ import org .springframework .beans .factory .support .RootBeanDefinition ;
35
36
import org .springframework .context .i18n .LocaleContextHolder ;
36
37
import org .springframework .context .support .GenericApplicationContext ;
37
38
import org .springframework .core .convert .TypeDescriptor ;
@@ -88,6 +89,7 @@ public LocalDate convert(DateTime source) {
88
89
89
90
@ Test
90
91
public void testFormatFieldForAnnotation () throws Exception {
92
+ formattingService .addFormatterForFieldAnnotation (new JodaDateTimeFormatAnnotationFormatterFactory ());
91
93
doTestFormatFieldForAnnotation (Model .class );
92
94
}
93
95
@@ -102,6 +104,22 @@ public void testFormatFieldForAnnotationWithPlaceholders() throws Exception {
102
104
context .getBeanFactory ().registerSingleton ("ppc" , ppc );
103
105
context .refresh ();
104
106
context .getBeanFactory ().initializeBean (formattingService , "formattingService" );
107
+ formattingService .addFormatterForFieldAnnotation (new JodaDateTimeFormatAnnotationFormatterFactory ());
108
+ doTestFormatFieldForAnnotation (ModelWithPlaceholders .class );
109
+ }
110
+
111
+ @ Test
112
+ public void testFormatFieldForAnnotationWithPlaceholdersAndFactoryBean () throws Exception {
113
+ GenericApplicationContext context = new GenericApplicationContext ();
114
+ PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer ();
115
+ Properties props = new Properties ();
116
+ props .setProperty ("dateStyle" , "S-" );
117
+ props .setProperty ("datePattern" , "M/d/yy" );
118
+ ppc .setProperties (props );
119
+ context .registerBeanDefinition ("formattingService" , new RootBeanDefinition (FormattingConversionServiceFactoryBean .class ));
120
+ context .getBeanFactory ().registerSingleton ("ppc" , ppc );
121
+ context .refresh ();
122
+ formattingService = context .getBean ("formattingService" , FormattingConversionService .class );
105
123
doTestFormatFieldForAnnotation (ModelWithPlaceholders .class );
106
124
}
107
125
@@ -116,7 +134,6 @@ public Date convert(DateTime source) {
116
134
return source .toDate ();
117
135
}
118
136
});
119
- formattingService .addFormatterForFieldAnnotation (new JodaDateTimeFormatAnnotationFormatterFactory ());
120
137
121
138
String formatted = (String ) formattingService .convert (new LocalDate (2009 , 10 , 31 ).toDateTimeAtCurrentTime ()
122
139
.toDate (), new TypeDescriptor (modelClass .getField ("date" )), TypeDescriptor .valueOf (String .class ));
0 commit comments