|
24 | 24 | import jakarta.persistence.EntityManagerFactory;
|
25 | 25 | import org.junit.jupiter.api.Test;
|
26 | 26 | import org.junit.jupiter.api.extension.ExtendWith;
|
| 27 | +import org.mockito.InOrder; |
| 28 | +import org.mockito.Mockito; |
27 | 29 |
|
28 | 30 | import org.springframework.batch.core.BatchStatus;
|
29 | 31 | import org.springframework.batch.core.Job;
|
|
71 | 73 | import org.springframework.context.annotation.Bean;
|
72 | 74 | import org.springframework.context.annotation.Configuration;
|
73 | 75 | import org.springframework.context.annotation.Primary;
|
74 |
| -import org.springframework.core.convert.converter.Converter; |
| 76 | +import org.springframework.core.annotation.Order; |
75 | 77 | import org.springframework.core.convert.support.ConfigurableConversionService;
|
76 | 78 | import org.springframework.jdbc.BadSqlGrammarException;
|
77 | 79 | import org.springframework.jdbc.core.JdbcTemplate;
|
@@ -403,17 +405,20 @@ void whenTheUserDefinesTheirOwnDatabaseInitializerThenTheAutoConfiguredBatchInit
|
403 | 405 | }
|
404 | 406 |
|
405 | 407 | @Test
|
406 |
| - void userProvidedCustomConverter() { |
| 408 | + void conversionServiceCustomizersAreCalled() { |
407 | 409 | this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class)
|
408 |
| - .withUserConfiguration(RegisterCustomConverter.class) |
| 410 | + .withUserConfiguration(ConversionServiceCustomizersConfiguration.class) |
409 | 411 | .run((context) -> {
|
410 |
| - assertThat(context).hasSingleBean(SpringBootBatchConfiguration.class); |
| 412 | + BatchConversionServiceCustomizer customizer = context.getBean("batchConversionServiceCustomizer", |
| 413 | + BatchConversionServiceCustomizer.class); |
| 414 | + BatchConversionServiceCustomizer anotherCustomizer = context |
| 415 | + .getBean("anotherBatchConversionServiceCustomizer", BatchConversionServiceCustomizer.class); |
| 416 | + InOrder inOrder = Mockito.inOrder(customizer, anotherCustomizer); |
411 | 417 | ConfigurableConversionService configurableConversionService = context
|
412 | 418 | .getBean(SpringBootBatchConfiguration.class)
|
413 | 419 | .getConversionService();
|
414 |
| - assertThat(configurableConversionService.canConvert(RegisterCustomConverter.Foo.class, |
415 |
| - RegisterCustomConverter.Bar.class)) |
416 |
| - .isTrue(); |
| 420 | + inOrder.verify(customizer).customize(configurableConversionService); |
| 421 | + inOrder.verify(anotherCustomizer).customize(configurableConversionService); |
417 | 422 | });
|
418 | 423 | }
|
419 | 424 |
|
@@ -698,29 +703,18 @@ static class EnableBatchProcessingConfiguration {
|
698 | 703 | }
|
699 | 704 |
|
700 | 705 | @Configuration(proxyBeanMethods = false)
|
701 |
| - static class RegisterCustomConverter { |
| 706 | + static class ConversionServiceCustomizersConfiguration { |
702 | 707 |
|
703 | 708 | @Bean
|
| 709 | + @Order(1) |
704 | 710 | BatchConversionServiceCustomizer batchConversionServiceCustomizer() {
|
705 |
| - return (configurableConversionService) -> configurableConversionService |
706 |
| - .addConverter(new FooToBarConverter()); |
707 |
| - } |
708 |
| - |
709 |
| - static class Foo { |
710 |
| - |
| 711 | + return mock(BatchConversionServiceCustomizer.class); |
711 | 712 | }
|
712 | 713 |
|
713 |
| - static class Bar { |
714 |
| - |
715 |
| - } |
716 |
| - |
717 |
| - static class FooToBarConverter implements Converter<Foo, Bar> { |
718 |
| - |
719 |
| - @Override |
720 |
| - public Bar convert(Foo source) { |
721 |
| - return null; |
722 |
| - } |
723 |
| - |
| 714 | + @Bean |
| 715 | + @Order(2) |
| 716 | + BatchConversionServiceCustomizer anotherBatchConversionServiceCustomizer() { |
| 717 | + return mock(BatchConversionServiceCustomizer.class); |
724 | 718 | }
|
725 | 719 |
|
726 | 720 | }
|
|
0 commit comments