Home / Class/ PeriodToStringConverterTests Class — spring-boot Architecture

PeriodToStringConverterTests Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/convert/PeriodToStringConverterTests.java lines 36–85

class PeriodToStringConverterTests {

	@ConversionServiceTest
	void convertWithoutStyleShouldReturnIso8601(ConversionService conversionService) {
		String converted = conversionService.convert(Period.ofDays(1), String.class);
		assertThat(converted).isEqualTo(Period.ofDays(1).toString());
	}

	@ConversionServiceTest
	void convertWithFormatWhenZeroShouldUseFormatAndDays(ConversionService conversionService) {
		String converted = (String) conversionService.convert(Period.ofMonths(0),
				MockPeriodTypeDescriptor.get(null, PeriodStyle.SIMPLE), TypeDescriptor.valueOf(String.class));
		assertThat(converted).isEqualTo("0d");
	}

	@ConversionServiceTest
	void convertWithFormatShouldUseFormat(ConversionService conversionService) {
		String converted = (String) conversionService.convert(Period.of(1, 2, 3),
				MockPeriodTypeDescriptor.get(null, PeriodStyle.SIMPLE), TypeDescriptor.valueOf(String.class));
		assertThat(converted).isEqualTo("1y2m3d");
	}

	@ConversionServiceTest
	void convertWithFormatAndUnitWhenZeroShouldUseFormatAndUnit(ConversionService conversionService) {
		String converted = (String) conversionService.convert(Period.ofYears(0),
				MockPeriodTypeDescriptor.get(ChronoUnit.YEARS, PeriodStyle.SIMPLE),
				TypeDescriptor.valueOf(String.class));
		assertThat(converted).isEqualTo("0y");
	}

	@ConversionServiceTest
	void convertWithFormatAndUnitWhenNonZeroShouldUseFormatAndIgnoreUnit(ConversionService conversionService) {
		String converted = (String) conversionService.convert(Period.of(1, 0, 3),
				MockPeriodTypeDescriptor.get(ChronoUnit.YEARS, PeriodStyle.SIMPLE),
				TypeDescriptor.valueOf(String.class));
		assertThat(converted).isEqualTo("1y3d");
	}

	@ConversionServiceTest
	void convertWithWeekUnitShouldConvertToStringInDays(ConversionService conversionService) {
		String converted = (String) conversionService.convert(Period.ofWeeks(53),
				MockPeriodTypeDescriptor.get(null, PeriodStyle.SIMPLE), TypeDescriptor.valueOf(String.class));
		assertThat(converted).isEqualTo("371d");
	}

	static Stream<? extends Arguments> conversionServices() {
		return ConversionServiceArguments.with(new PeriodToStringConverter());
	}

}

Analyze Your Own Codebase

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

Try Supermodel Free