use of org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method formatFieldForAnnotationWithDirectFieldAccess.
@Test
public void formatFieldForAnnotationWithDirectFieldAccess() throws Exception {
formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
doTestFormatFieldForAnnotation(Model.class, true);
}
use of org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method formatFieldForAnnotationWithSubclassAsFieldType.
@Test
public void formatFieldForAnnotationWithSubclassAsFieldType() throws Exception {
formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory() {
@Override
public Printer<?> getPrinter(org.springframework.format.annotation.DateTimeFormat annotation, Class<?> fieldType) {
assertEquals(MyDate.class, fieldType);
return super.getPrinter(annotation, fieldType);
}
});
formattingService.addConverter(new Converter<MyDate, Long>() {
@Override
public Long convert(MyDate source) {
return source.getTime();
}
});
formattingService.addConverter(new Converter<MyDate, Date>() {
@Override
public Date convert(MyDate source) {
return source;
}
});
formattingService.convert(new MyDate(), new TypeDescriptor(ModelWithSubclassField.class.getField("date")), TypeDescriptor.valueOf(String.class));
}
use of org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method formatFieldForAnnotationWithPlaceholders.
@Test
@SuppressWarnings("resource")
public void formatFieldForAnnotationWithPlaceholders() throws Exception {
GenericApplicationContext context = new GenericApplicationContext();
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
Properties props = new Properties();
props.setProperty("dateStyle", "S-");
props.setProperty("datePattern", "M-d-yy");
ppc.setProperties(props);
context.getBeanFactory().registerSingleton("ppc", ppc);
context.refresh();
context.getBeanFactory().initializeBean(formattingService, "formattingService");
formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
doTestFormatFieldForAnnotation(ModelWithPlaceholders.class, false);
}
use of org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method formatFieldForAnnotation.
@Test
public void formatFieldForAnnotation() throws Exception {
formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
doTestFormatFieldForAnnotation(Model.class, false);
}
Aggregations