Home / Class/ ArrayToDelimitedStringConverterTests Class — spring-boot Architecture

ArrayToDelimitedStringConverterTests Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/convert/ArrayToDelimitedStringConverterTests.java lines 37–104

class ArrayToDelimitedStringConverterTests {

	@ConversionServiceTest
	void convertListToStringShouldConvert(ConversionService conversionService) {
		String[] list = { "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 = new String[] { "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 = new String[] { "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) {
		String[] list = null;
		String converted = conversionService.convert(list, String.class);
		assertThat(converted).isNull();
	}

	@Test
	void convertShouldConvertElements() {
		Data data = new Data();
		data.type = new int[] { 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 ArrayToDelimitedStringConverter(service)));
	}

	static class Data {

		@Delimiter(Delimiter.NONE)
		String @Nullable [] none;

		@Delimiter("-")
		String @Nullable [] dash;

		@Delimiter(".")
		int @Nullable [] type;

	}

}

Analyze Your Own Codebase

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

Try Supermodel Free