Home / Class/ NumberToDurationConverterTests Class — spring-boot Architecture

NumberToDurationConverterTests Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/convert/NumberToDurationConverterTests.java lines 40–77

class NumberToDurationConverterTests {

	@ConversionServiceTest
	void convertWhenSimpleWithoutSuffixShouldReturnDuration(ConversionService conversionService) {
		assertThat(convert(conversionService, 10)).hasMillis(10);
		assertThat(convert(conversionService, +10)).hasMillis(10);
		assertThat(convert(conversionService, -10)).hasMillis(-10);
	}

	@ConversionServiceTest
	void convertWhenSimpleWithoutSuffixButWithAnnotationShouldReturnDuration(ConversionService conversionService) {
		assertThat(convert(conversionService, 10, ChronoUnit.SECONDS)).hasSeconds(10);
		assertThat(convert(conversionService, +10, ChronoUnit.SECONDS)).hasSeconds(10);
		assertThat(convert(conversionService, -10, ChronoUnit.SECONDS)).hasSeconds(-10);
	}

	private @Nullable Duration convert(ConversionService conversionService, Integer source) {
		return conversionService.convert(source, Duration.class);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private @Nullable Duration convert(ConversionService conversionService, Integer source,
			@Nullable ChronoUnit defaultUnit) {
		TypeDescriptor targetType = mock(TypeDescriptor.class);
		if (defaultUnit != null) {
			DurationUnit unitAnnotation = AnnotationUtils
				.synthesizeAnnotation(Collections.singletonMap("value", defaultUnit), DurationUnit.class, null);
			given(targetType.getAnnotation(DurationUnit.class)).willReturn(unitAnnotation);
		}
		given(targetType.getType()).willReturn((Class) Duration.class);
		return (Duration) conversionService.convert(source, TypeDescriptor.forObject(source), targetType);
	}

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

}

Analyze Your Own Codebase

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

Try Supermodel Free