Home / Class/ CollectionToDelimitedStringConverterTests Class — spring-boot Architecture

CollectionToDelimitedStringConverterTests Class — spring-boot Architecture

Architecture documentation for the CollectionToDelimitedStringConverterTests class in CollectionToDelimitedStringConverterTests.java from the spring-boot codebase.

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/convert/CollectionToDelimitedStringConverterTests.java lines 39–106

class CollectionToDelimitedStringConverterTests {

	@ConversionServiceTest
	void convertListToStringShouldConvert(ConversionService conversionService) {
		List<String> list = Arrays.asList("a", "b", "c");
		String converted = conversionService.convert(list, String.class);
		assertThat(converted).isEqualTo("a,b,c");
	}

	@ConversionServiceTest
	void convertWhenHasDelimiterNoneShouldConvert(ConversionService conversionService) {
		Data data = new Data();
		data.none = Arrays.asList("1", "2", "3");
		Field field = ReflectionUtils.findField(Data.class, "none");
		assertThat(field).isNotNull();
		String converted = (String) conversionService.convert(data.none, TypeDescriptor.nested(field, 0),
				TypeDescriptor.valueOf(String.class));
		assertThat(converted).isEqualTo("123");
	}

	@ConversionServiceTest
	void convertWhenHasDelimiterDashShouldConvert(ConversionService conversionService) {
		Data data = new Data();
		data.dash = Arrays.asList("1", "2", "3");
		Field field = ReflectionUtils.findField(Data.class, "dash");
		assertThat(field).isNotNull();
		String converted = (String) conversionService.convert(data.dash, TypeDescriptor.nested(field, 0),
				TypeDescriptor.valueOf(String.class));
		assertThat(converted).isEqualTo("1-2-3");
	}

	@ConversionServiceTest
	void convertShouldConvertNull(ConversionService conversionService) {
		List<String> list = null;
		String converted = conversionService.convert(list, String.class);
		assertThat(converted).isNull();
	}

	@Test
	void convertShouldConvertElements() {
		Data data = new Data();
		data.type = Arrays.asList(1, 2, 3);
		Field field = ReflectionUtils.findField(Data.class, "type");
		assertThat(field).isNotNull();
		String converted = (String) new ApplicationConversionService().convert(data.type,
				TypeDescriptor.nested(field, 0), TypeDescriptor.valueOf(String.class));
		assertThat(converted).isEqualTo("1.2.3");
	}

	static Stream<? extends Arguments> conversionServices() {
		return ConversionServiceArguments
			.with((service) -> service.addConverter(new CollectionToDelimitedStringConverter(service)));
	}

	static class Data {

		@Delimiter(Delimiter.NONE)
		@Nullable List<String> none;

		@Delimiter("-")
		@Nullable List<String> dash;

		@Delimiter(".")
		@Nullable List<Integer> type;

	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free