Home / Class/ SimpleAsyncTaskExecutorBuilderTests Class — spring-boot Architecture

SimpleAsyncTaskExecutorBuilderTests Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/task/SimpleAsyncTaskExecutorBuilderTests.java lines 45–171

class SimpleAsyncTaskExecutorBuilderTests {

	private final SimpleAsyncTaskExecutorBuilder builder = new SimpleAsyncTaskExecutorBuilder();

	@Test
	void threadNamePrefixShouldApply() {
		SimpleAsyncTaskExecutor executor = this.builder.threadNamePrefix("test-").build();
		assertThat(executor.getThreadNamePrefix()).isEqualTo("test-");
	}

	@Test
	@EnabledForJreRange(min = JRE.JAVA_21)
	void virtualThreadsShouldApply() {
		SimpleAsyncTaskExecutor executor = this.builder.virtualThreads(true).build();
		SimpleAsyncTaskExecutorAssert.assertThat(executor).usesVirtualThreads();
	}

	@Test
	void cancelRemainingTasksOnCloseShouldApply() {
		SimpleAsyncTaskExecutor executor = this.builder.cancelRemainingTasksOnClose(true).build();
		assertThat(executor).extracting("cancelRemainingTasksOnClose").isEqualTo(true);
	}

	@Test
	void rejectTasksWhenLimitReachedShouldApply() {
		SimpleAsyncTaskExecutor executor = this.builder.rejectTasksWhenLimitReached(true).build();
		assertThat(executor).extracting("rejectTasksWhenLimitReached").isEqualTo(true);
	}

	@Test
	void concurrencyLimitShouldApply() {
		SimpleAsyncTaskExecutor executor = this.builder.concurrencyLimit(1).build();
		assertThat(executor.getConcurrencyLimit()).isEqualTo(1);
	}

	@Test
	void taskDecoratorShouldApply() {
		TaskDecorator taskDecorator = mock(TaskDecorator.class);
		SimpleAsyncTaskExecutor executor = this.builder.taskDecorator(taskDecorator).build();
		assertThat(executor).extracting("taskDecorator").isSameAs(taskDecorator);
	}

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void customizersWhenCustomizersAreNullShouldThrowException() {
		assertThatIllegalArgumentException()
			.isThrownBy(() -> this.builder.customizers((SimpleAsyncTaskExecutorCustomizer[]) null))
			.withMessageContaining("'customizers' must not be null");
	}

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void customizersCollectionWhenCustomizersAreNullShouldThrowException() {
		assertThatIllegalArgumentException()
			.isThrownBy(() -> this.builder.customizers((Set<SimpleAsyncTaskExecutorCustomizer>) null))
			.withMessageContaining("'customizers' must not be null");
	}

	@Test
	void customizersShouldApply() {
		SimpleAsyncTaskExecutorCustomizer customizer = mock(SimpleAsyncTaskExecutorCustomizer.class);
		SimpleAsyncTaskExecutor executor = this.builder.customizers(customizer).build();
		then(customizer).should().customize(executor);
	}

	@Test
	void customizersShouldBeAppliedLast() {
		TaskDecorator taskDecorator = mock(TaskDecorator.class);
		SimpleAsyncTaskExecutor executor = spy(new SimpleAsyncTaskExecutor());
		this.builder.threadNamePrefix("test-")
			.virtualThreads(true)
			.concurrencyLimit(1)
			.taskDecorator(taskDecorator)
			.additionalCustomizers((taskExecutor) -> {
				then(taskExecutor).should().setConcurrencyLimit(1);
				then(taskExecutor).should().setVirtualThreads(true);
				then(taskExecutor).should().setThreadNamePrefix("test-");
				then(taskExecutor).should().setTaskDecorator(taskDecorator);
			});
		this.builder.configure(executor);
	}

	@Test
	void customizersShouldReplaceExisting() {
		SimpleAsyncTaskExecutorCustomizer customizer1 = mock(SimpleAsyncTaskExecutorCustomizer.class);
		SimpleAsyncTaskExecutorCustomizer customizer2 = mock(SimpleAsyncTaskExecutorCustomizer.class);
		SimpleAsyncTaskExecutor executor = this.builder.customizers(customizer1)
			.customizers(Collections.singleton(customizer2))
			.build();
		then(customizer1).shouldHaveNoInteractions();
		then(customizer2).should().customize(executor);
	}

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void additionalCustomizersWhenCustomizersAreNullShouldThrowException() {
		assertThatIllegalArgumentException()
			.isThrownBy(() -> this.builder.additionalCustomizers((SimpleAsyncTaskExecutorCustomizer[]) null))
			.withMessageContaining("'customizers' must not be null");
	}

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void additionalCustomizersCollectionWhenCustomizersAreNullShouldThrowException() {
		assertThatIllegalArgumentException()
			.isThrownBy(() -> this.builder.additionalCustomizers((Set<SimpleAsyncTaskExecutorCustomizer>) null))
			.withMessageContaining("'customizers' must not be null");
	}

	@Test
	void additionalCustomizersShouldAddToExisting() {
		SimpleAsyncTaskExecutorCustomizer customizer1 = mock(SimpleAsyncTaskExecutorCustomizer.class);
		SimpleAsyncTaskExecutorCustomizer customizer2 = mock(SimpleAsyncTaskExecutorCustomizer.class);
		SimpleAsyncTaskExecutor executor = this.builder.customizers(customizer1)
			.additionalCustomizers(customizer2)
			.build();
		then(customizer1).should().customize(executor);
		then(customizer2).should().customize(executor);
	}

	@Test
	void taskTerminationTimeoutShouldApply() {
		SimpleAsyncTaskExecutor executor = this.builder.taskTerminationTimeout(Duration.ofSeconds(1)).build();
		assertThat(executor).extracting("taskTerminationTimeout").isEqualTo(1000L);
	}

}

Analyze Your Own Codebase

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

Try Supermodel Free