@@ -128,7 +128,7 @@ void threadPoolTaskExecutorBuilderWhenHasCustomBuilderShouldUseCustomBuilder() {
128
128
129
129
@ Test
130
130
void threadPoolTaskExecutorBuilderShouldUseTaskDecorator () {
131
- this .contextRunner .withBean (TaskDecorator .class , this :: createTaskDecorator ).run ((context ) -> {
131
+ this .contextRunner .withBean (TaskDecorator .class , OrderedTaskDecorator :: new ).run ((context ) -> {
132
132
assertThat (context ).hasSingleBean (ThreadPoolTaskExecutorBuilder .class );
133
133
ThreadPoolTaskExecutor executor = context .getBean (ThreadPoolTaskExecutorBuilder .class ).build ();
134
134
assertThat (executor ).extracting ("taskDecorator" ).isSameAs (context .getBean (TaskDecorator .class ));
@@ -137,8 +137,9 @@ void threadPoolTaskExecutorBuilderShouldUseTaskDecorator() {
137
137
138
138
@ Test
139
139
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 ))
142
143
.run ((context ) -> {
143
144
assertThat (context ).hasSingleBean (ThreadPoolTaskExecutorBuilder .class );
144
145
ThreadPoolTaskExecutor executor = context .getBean (ThreadPoolTaskExecutorBuilder .class ).build ();
@@ -147,6 +148,7 @@ void threadPoolTaskExecutorBuilderShouldUseCompositeTaskDecorator() {
147
148
.extracting ("taskDecorators" )
148
149
.asInstanceOf (InstanceOfAssertFactories .list (TaskDecorator .class ))
149
150
.containsExactly (context .getBean ("taskDecorator1" , TaskDecorator .class ),
151
+ context .getBean ("taskDecorator3" , TaskDecorator .class ),
150
152
context .getBean ("taskDecorator2" , TaskDecorator .class ));
151
153
});
152
154
}
@@ -201,7 +203,7 @@ void whenVirtualThreadsAreAvailableButNotEnabledThenThreadPoolTaskExecutorIsAuto
201
203
@ EnabledForJreRange (min = JRE .JAVA_21 )
202
204
void whenTaskDecoratorIsDefinedThenSimpleAsyncTaskExecutorWithVirtualThreadsUsesIt () {
203
205
this .contextRunner .withPropertyValues ("spring.threads.virtual.enabled=true" )
204
- .withBean (TaskDecorator .class , this :: createTaskDecorator )
206
+ .withBean (TaskDecorator .class , OrderedTaskDecorator :: new )
205
207
.run ((context ) -> {
206
208
SimpleAsyncTaskExecutor executor = context .getBean (SimpleAsyncTaskExecutor .class );
207
209
assertThat (executor ).extracting ("taskDecorator" ).isSameAs (context .getBean (TaskDecorator .class ));
@@ -212,15 +214,17 @@ void whenTaskDecoratorIsDefinedThenSimpleAsyncTaskExecutorWithVirtualThreadsUses
212
214
@ EnabledForJreRange (min = JRE .JAVA_21 )
213
215
void whenTaskDecoratorsAreDefinedThenSimpleAsyncTaskExecutorWithVirtualThreadsUsesThem () {
214
216
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 ))
217
220
.run ((context ) -> {
218
221
SimpleAsyncTaskExecutor executor = context .getBean (SimpleAsyncTaskExecutor .class );
219
222
assertThat (executor ).extracting ("taskDecorator" )
220
223
.isInstanceOf (CompositeTaskDecorator .class )
221
224
.extracting ("taskDecorators" )
222
225
.asInstanceOf (InstanceOfAssertFactories .list (TaskDecorator .class ))
223
226
.containsExactly (context .getBean ("taskDecorator1" , TaskDecorator .class ),
227
+ context .getBean ("taskDecorator3" , TaskDecorator .class ),
224
228
context .getBean ("taskDecorator2" , TaskDecorator .class ));
225
229
});
226
230
}
@@ -485,10 +489,6 @@ void shouldNotAliasApplicationTaskExecutorWhenBootstrapExecutorAliasIsDefined()
485
489
});
486
490
}
487
491
488
- private TaskDecorator createTaskDecorator () {
489
- return (runnable ) -> runnable ;
490
- }
491
-
492
492
private Executor createCustomAsyncExecutor (String threadNamePrefix ) {
493
493
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor ();
494
494
executor .setThreadNamePrefix (threadNamePrefix );
0 commit comments