use of org.springframework.util.unit.DataSize in project spring-boot by spring-projects.
the class NumberToDataSizeConverterTests method convert.
@SuppressWarnings({ "rawtypes", "unchecked" })
private DataSize convert(ConversionService conversionService, Integer source, DataUnit defaultUnit) {
TypeDescriptor targetType = mock(TypeDescriptor.class);
if (defaultUnit != null) {
DataSizeUnit unitAnnotation = AnnotationUtils.synthesizeAnnotation(Collections.singletonMap("value", defaultUnit), DataSizeUnit.class, null);
given(targetType.getAnnotation(DataSizeUnit.class)).willReturn(unitAnnotation);
}
given(targetType.getType()).willReturn((Class) DataSize.class);
return (DataSize) conversionService.convert(source, TypeDescriptor.forObject(source), targetType);
}
Aggregations