From f042dcf0e09092e6e95592c5948470db437d49d1 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 11 May 2021 17:17:28 +0200 Subject: [PATCH] Properly assert that auto-configured TaskExecutor is lazy This commit fixes a flawed assertion that was relying on a log message to validate the TaskExecutor is lazy. The level of the log message has changed in framework and broke the test. We now rather check the bean definition. --- .../task/TaskExecutionAutoConfigurationTests.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfigurationTests.java index a0bb9642a2a..da16bf270ee 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,13 +23,13 @@ import java.util.function.Consumer; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.task.TaskExecutorBuilder; import org.springframework.boot.task.TaskExecutorCustomizer; import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; -import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -96,13 +96,13 @@ class TaskExecutionAutoConfigurationTests { } @Test - void taskExecutorAutoConfigured(CapturedOutput output) { + void taskExecutorAutoConfiguredIsLazy() { this.contextRunner.run((context) -> { - assertThat(output).doesNotContain("Initializing ExecutorService"); - assertThat(context).hasSingleBean(Executor.class); - assertThat(context).hasBean("applicationTaskExecutor"); + assertThat(context).hasSingleBean(Executor.class).hasBean("applicationTaskExecutor"); + BeanDefinition beanDefinition = context.getSourceApplicationContext().getBeanFactory() + .getBeanDefinition("applicationTaskExecutor"); + assertThat(beanDefinition.isLazyInit()).isTrue(); assertThat(context).getBean("applicationTaskExecutor").isInstanceOf(ThreadPoolTaskExecutor.class); - assertThat(output).contains("Initializing ExecutorService"); }); }