use of org.springframework.format.number.NumberStyleFormatter in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method parseEmptyString.
@Test
public void parseEmptyString() {
formattingService.addFormatterForFieldType(Number.class, new NumberStyleFormatter());
assertThat(formattingService.convert("", TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class))).isNull();
}
use of org.springframework.format.number.NumberStyleFormatter in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method introspectedPrinter.
@Test
public void introspectedPrinter() {
formattingService.addPrinter(new NumberStyleFormatter("#,#00.0#"));
assertThat(formattingService.convert(123, String.class)).isEqualTo("123.0");
assertThatExceptionOfType(ConversionFailedException.class).isThrownBy(() -> formattingService.convert("123.0", Integer.class)).withCauseInstanceOf(NumberFormatException.class);
}
use of org.springframework.format.number.NumberStyleFormatter in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method introspectedParser.
@Test
public void introspectedParser() {
formattingService.addParser(new NumberStyleFormatter("#,#00.0#"));
assertThat(formattingService.convert("123.0", Integer.class)).isEqualTo(123);
assertThat(formattingService.convert(123, String.class)).isEqualTo("123");
}
use of org.springframework.format.number.NumberStyleFormatter in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method proxiedFormatter.
@Test
public void proxiedFormatter() {
Formatter<?> formatter = new NumberStyleFormatter();
formattingService.addFormatter((Formatter<?>) new ProxyFactory(formatter).getProxy());
assertThat(formattingService.convert(null, TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class))).isNull();
}
use of org.springframework.format.number.NumberStyleFormatter in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method formatFieldForTypeWithFormatter.
@Test
public void formatFieldForTypeWithFormatter() {
formattingService.addFormatterForFieldType(Number.class, new NumberStyleFormatter());
String formatted = formattingService.convert(3, String.class);
assertThat(formatted).isEqualTo("3");
Integer i = formattingService.convert("3", Integer.class);
assertThat(i).isEqualTo(3);
}
Aggregations