SimpleAsyncTaskSchedulerBuilderTests Class — spring-boot Architecture
Architecture documentation for the SimpleAsyncTaskSchedulerBuilderTests class in SimpleAsyncTaskSchedulerBuilderTests.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/test/java/org/springframework/boot/task/SimpleAsyncTaskSchedulerBuilderTests.java lines 42–149
class SimpleAsyncTaskSchedulerBuilderTests {
private final SimpleAsyncTaskSchedulerBuilder builder = new SimpleAsyncTaskSchedulerBuilder();
@Test
void threadNamePrefixShouldApply() {
SimpleAsyncTaskScheduler scheduler = this.builder.threadNamePrefix("test-").build();
assertThat(scheduler.getThreadNamePrefix()).isEqualTo("test-");
}
@Test
void concurrencyLimitShouldApply() {
SimpleAsyncTaskScheduler scheduler = this.builder.concurrencyLimit(1).build();
assertThat(scheduler.getConcurrencyLimit()).isEqualTo(1);
}
@Test
@EnabledForJreRange(min = JRE.JAVA_21)
void virtualThreadsShouldApply() {
SimpleAsyncTaskScheduler scheduler = this.builder.virtualThreads(true).build();
assertThat(scheduler).extracting("virtualThreadDelegate").isNotNull();
}
@Test
void taskTerminationTimeoutShouldApply() {
SimpleAsyncTaskScheduler scheduler = this.builder.taskTerminationTimeout(Duration.ofSeconds(1)).build();
assertThat(scheduler).extracting("taskTerminationTimeout").isEqualTo(1000L);
}
@Test
void taskDecoratorShouldApply() {
TaskDecorator taskDecorator = mock(TaskDecorator.class);
SimpleAsyncTaskScheduler scheduler = this.builder.taskDecorator(taskDecorator).build();
assertThat(scheduler).extracting("taskDecorator").isSameAs(taskDecorator);
}
@Test
@SuppressWarnings("NullAway") // Test null check
void customizersWhenCustomizersAreNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> this.builder.customizers((SimpleAsyncTaskSchedulerCustomizer[]) null))
.withMessageContaining("'customizers' must not be null");
}
@Test
@SuppressWarnings("NullAway") // Test null check
void customizersCollectionWhenCustomizersAreNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> this.builder.customizers((Set<SimpleAsyncTaskSchedulerCustomizer>) null))
.withMessageContaining("'customizers' must not be null");
}
@Test
void customizersShouldApply() {
SimpleAsyncTaskSchedulerCustomizer customizer = mock(SimpleAsyncTaskSchedulerCustomizer.class);
SimpleAsyncTaskScheduler scheduler = this.builder.customizers(customizer).build();
then(customizer).should().customize(scheduler);
}
@Test
void customizersShouldBeAppliedLast() {
SimpleAsyncTaskScheduler scheduler = spy(new SimpleAsyncTaskScheduler());
this.builder.concurrencyLimit(1).threadNamePrefix("test-").additionalCustomizers((taskScheduler) -> {
then(taskScheduler).should().setConcurrencyLimit(1);
then(taskScheduler).should().setThreadNamePrefix("test-");
});
this.builder.configure(scheduler);
}
@Test
void customizersShouldReplaceExisting() {
SimpleAsyncTaskSchedulerCustomizer customizer1 = mock(SimpleAsyncTaskSchedulerCustomizer.class);
SimpleAsyncTaskSchedulerCustomizer customizer2 = mock(SimpleAsyncTaskSchedulerCustomizer.class);
SimpleAsyncTaskScheduler scheduler = this.builder.customizers(customizer1)
.customizers(Collections.singleton(customizer2))
.build();
then(customizer1).shouldHaveNoInteractions();
then(customizer2).should().customize(scheduler);
}
@Test
@SuppressWarnings("NullAway") // Test null check
void additionalCustomizersWhenCustomizersAreNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> this.builder.additionalCustomizers((SimpleAsyncTaskSchedulerCustomizer[]) null))
.withMessageContaining("'customizers' must not be null");
}
@Test
@SuppressWarnings("NullAway") // Test null check
void additionalCustomizersCollectionWhenCustomizersAreNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> this.builder.additionalCustomizers((Set<SimpleAsyncTaskSchedulerCustomizer>) null))
.withMessageContaining("'customizers' must not be null");
}
@Test
void additionalCustomizersShouldAddToExisting() {
SimpleAsyncTaskSchedulerCustomizer customizer1 = mock(SimpleAsyncTaskSchedulerCustomizer.class);
SimpleAsyncTaskSchedulerCustomizer customizer2 = mock(SimpleAsyncTaskSchedulerCustomizer.class);
SimpleAsyncTaskScheduler scheduler = this.builder.customizers(customizer1)
.additionalCustomizers(customizer2)
.build();
then(customizer1).should().customize(scheduler);
then(customizer2).should().customize(scheduler);
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free