Search in sources :

Example 6 with DataSize

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);
}
Also used : TypeDescriptor(org.springframework.core.convert.TypeDescriptor) DataSize(org.springframework.util.unit.DataSize)

Aggregations

DataSize (org.springframework.util.unit.DataSize)6 PropertyMapper (org.springframework.boot.context.properties.PropertyMapper)5 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)3 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Duration (java.time.Duration)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Lifecycle (org.apache.catalina.Lifecycle)1 AccessLogValve (org.apache.catalina.valves.AccessLogValve)1 ErrorReportValve (org.apache.catalina.valves.ErrorReportValve)1 RemoteIpValve (org.apache.catalina.valves.RemoteIpValve)1 AbstractProtocol (org.apache.coyote.AbstractProtocol)1 ProtocolHandler (org.apache.coyote.ProtocolHandler)1 AbstractHttp11Protocol (org.apache.coyote.http11.AbstractHttp11Protocol)1 AutoConfiguration (org.springframework.boot.autoconfigure.AutoConfiguration)1 EnableAutoConfiguration (org.springframework.boot.autoconfigure.EnableAutoConfiguration)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnWebApplication (org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication)1