@@ -128,7 +128,7 @@ void threadPoolTaskExecutorBuilderWhenHasCustomBuilderShouldUseCustomBuilder() {
128128
129129 @ Test
130130 void threadPoolTaskExecutorBuilderShouldUseTaskDecorator () {
131- this .contextRunner .withBean (TaskDecorator .class , this :: createTaskDecorator ).run ((context ) -> {
131+ this .contextRunner .withBean (TaskDecorator .class , OrderedTaskDecorator :: new ).run ((context ) -> {
132132 assertThat (context ).hasSingleBean (ThreadPoolTaskExecutorBuilder .class );
133133 ThreadPoolTaskExecutor executor = context .getBean (ThreadPoolTaskExecutorBuilder .class ).build ();
134134 assertThat (executor ).extracting ("taskDecorator" ).isSameAs (context .getBean (TaskDecorator .class ));
@@ -137,8 +137,9 @@ void threadPoolTaskExecutorBuilderShouldUseTaskDecorator() {
137137
138138 @ Test
139139 void threadPoolTaskExecutorBuilderShouldUseCompositeTaskDecorator () {
140- this .contextRunner .withBean ("taskDecorator1" , TaskDecorator .class , this ::createTaskDecorator )
141- .withBean ("taskDecorator2" , TaskDecorator .class , this ::createTaskDecorator )
140+ this .contextRunner .withBean ("taskDecorator1" , TaskDecorator .class , () -> new OrderedTaskDecorator (1 ))
141+ .withBean ("taskDecorator2" , TaskDecorator .class , () -> new OrderedTaskDecorator (3 ))
142+ .withBean ("taskDecorator3" , TaskDecorator .class , () -> new OrderedTaskDecorator (2 ))
142143 .run ((context ) -> {
143144 assertThat (context ).hasSingleBean (ThreadPoolTaskExecutorBuilder .class );
144145 ThreadPoolTaskExecutor executor = context .getBean (ThreadPoolTaskExecutorBuilder .class ).build ();
@@ -147,6 +148,7 @@ void threadPoolTaskExecutorBuilderShouldUseCompositeTaskDecorator() {
147148 .extracting ("taskDecorators" )
148149 .asInstanceOf (InstanceOfAssertFactories .list (TaskDecorator .class ))
149150 .containsExactly (context .getBean ("taskDecorator1" , TaskDecorator .class ),
151+ context .getBean ("taskDecorator3" , TaskDecorator .class ),
150152 context .getBean ("taskDecorator2" , TaskDecorator .class ));
151153 });
152154 }
@@ -201,7 +203,7 @@ void whenVirtualThreadsAreAvailableButNotEnabledThenThreadPoolTaskExecutorIsAuto
201203 @ EnabledForJreRange (min = JRE .JAVA_21 )
202204 void whenTaskDecoratorIsDefinedThenSimpleAsyncTaskExecutorWithVirtualThreadsUsesIt () {
203205 this .contextRunner .withPropertyValues ("spring.threads.virtual.enabled=true" )
204- .withBean (TaskDecorator .class , this :: createTaskDecorator )
206+ .withBean (TaskDecorator .class , OrderedTaskDecorator :: new )
205207 .run ((context ) -> {
206208 SimpleAsyncTaskExecutor executor = context .getBean (SimpleAsyncTaskExecutor .class );
207209 assertThat (executor ).extracting ("taskDecorator" ).isSameAs (context .getBean (TaskDecorator .class ));
@@ -212,15 +214,17 @@ void whenTaskDecoratorIsDefinedThenSimpleAsyncTaskExecutorWithVirtualThreadsUses
212214 @ EnabledForJreRange (min = JRE .JAVA_21 )
213215 void whenTaskDecoratorsAreDefinedThenSimpleAsyncTaskExecutorWithVirtualThreadsUsesThem () {
214216 this .contextRunner .withPropertyValues ("spring.threads.virtual.enabled=true" )
215- .withBean ("taskDecorator1" , TaskDecorator .class , this ::createTaskDecorator )
216- .withBean ("taskDecorator2" , TaskDecorator .class , this ::createTaskDecorator )
217+ .withBean ("taskDecorator1" , TaskDecorator .class , () -> new OrderedTaskDecorator (1 ))
218+ .withBean ("taskDecorator2" , TaskDecorator .class , () -> new OrderedTaskDecorator (3 ))
219+ .withBean ("taskDecorator3" , TaskDecorator .class , () -> new OrderedTaskDecorator (2 ))
217220 .run ((context ) -> {
218221 SimpleAsyncTaskExecutor executor = context .getBean (SimpleAsyncTaskExecutor .class );
219222 assertThat (executor ).extracting ("taskDecorator" )
220223 .isInstanceOf (CompositeTaskDecorator .class )
221224 .extracting ("taskDecorators" )
222225 .asInstanceOf (InstanceOfAssertFactories .list (TaskDecorator .class ))
223226 .containsExactly (context .getBean ("taskDecorator1" , TaskDecorator .class ),
227+ context .getBean ("taskDecorator3" , TaskDecorator .class ),
224228 context .getBean ("taskDecorator2" , TaskDecorator .class ));
225229 });
226230 }
@@ -485,10 +489,6 @@ void shouldNotAliasApplicationTaskExecutorWhenBootstrapExecutorAliasIsDefined()
485489 });
486490 }
487491
488- private TaskDecorator createTaskDecorator () {
489- return (runnable ) -> runnable ;
490- }
491-
492492 private Executor createCustomAsyncExecutor (String threadNamePrefix ) {
493493 SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor ();
494494 executor .setThreadNamePrefix (threadNamePrefix );
0 commit comments