ConfigurationPropertiesCharSequenceToObjectConverterTests Class — spring-boot Architecture
Architecture documentation for the ConfigurationPropertiesCharSequenceToObjectConverterTests class in ConfigurationPropertiesCharSequenceToObjectConverterTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesCharSequenceToObjectConverterTests.java lines 42–116
class ConfigurationPropertiesCharSequenceToObjectConverterTests {
@ConversionServiceTest
void convertWhenCanConvertViaToString(ConversionService conversionService) {
assertThat(conversionService.convert(new StringBuilder("1"), Integer.class)).isOne();
}
@ConversionServiceTest
void convertWhenCanConvertDirectlySkipsStringConversion(ConversionService conversionService) {
assertThat(conversionService.convert(new String("1"), Long.class)).isOne();
if (!ConversionServiceArguments.isApplicationConversionService(conversionService)) {
assertThat(conversionService.convert(new StringBuilder("1"), Long.class)).isEqualTo(2);
}
}
@Test
@SuppressWarnings("unchecked")
void convertWhenTargetIsList() {
ConversionService conversionService = new ApplicationConversionService();
StringBuilder source = new StringBuilder("1,2,3");
TypeDescriptor sourceType = TypeDescriptor.valueOf(StringBuilder.class);
TypeDescriptor targetType = TypeDescriptor.collection(List.class, TypeDescriptor.valueOf(String.class));
List<String> converted = (List<String>) conversionService.convert(source, sourceType, targetType);
assertThat(converted).containsExactly("1", "2", "3");
}
@Test
@SuppressWarnings("unchecked")
void convertWhenTargetIsListAndNotUsingApplicationConversionService() {
FormattingConversionService conversionService = new DefaultFormattingConversionService();
conversionService.addConverter(new ConfigurationPropertiesCharSequenceToObjectConverter(conversionService));
StringBuilder source = new StringBuilder("1,2,3");
TypeDescriptor sourceType = TypeDescriptor.valueOf(StringBuilder.class);
TypeDescriptor targetType = TypeDescriptor.collection(List.class, TypeDescriptor.valueOf(String.class));
List<String> converted = (List<String>) conversionService.convert(source, sourceType, targetType);
assertThat(converted).containsExactly("1", "2", "3");
}
static Stream<? extends Arguments> conversionServices() {
return ConversionServiceArguments.with((conversionService) -> {
conversionService.addConverter(new StringToIntegerConverter());
conversionService.addConverter(new StringToLongConverter());
conversionService.addConverter(new CharSequenceToLongConverter());
conversionService.addConverter(new ConfigurationPropertiesCharSequenceToObjectConverter(conversionService));
});
}
static class StringToIntegerConverter implements Converter<String, Integer> {
@Override
public Integer convert(String source) {
return Integer.valueOf(source);
}
}
static class StringToLongConverter implements Converter<String, Long> {
@Override
public Long convert(String source) {
return Long.valueOf(source);
}
}
static class CharSequenceToLongConverter implements Converter<CharSequence, Long> {
@Override
public Long convert(CharSequence source) {
return Long.parseLong(source.toString()) + 1;
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free