Skip to content

Commit 69a2982

Browse files
committed
Polish "Configure FluentConfiguration to use ResourceLoader's ClassLoader"
See gh-16947
1 parent cc5bd51 commit 69a2982

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public Flyway flyway(FlywayProperties properties,
113113
ObjectProvider<FlywayConfigurationCustomizer> fluentConfigurationCustomizers,
114114
ObjectProvider<Callback> callbacks,
115115
ObjectProvider<FlywayCallback> flywayCallbacks) {
116-
FluentConfiguration configuration = new FluentConfiguration(resourceLoader.getClassLoader());
116+
FluentConfiguration configuration = new FluentConfiguration(
117+
resourceLoader.getClassLoader());
117118
DataSource dataSourceToMigrate = configureDataSource(configuration,
118119
properties, dataSourceProperties, flywayDataSource.getIfAvailable(),
119120
dataSource.getIfAvailable());

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.junit.jupiter.api.Test;
3737
import org.mockito.InOrder;
3838

39-
import org.mockito.internal.util.MockUtil;
4039
import org.springframework.beans.factory.BeanCreationException;
4140
import org.springframework.boot.autoconfigure.AutoConfigurations;
4241
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
@@ -56,7 +55,6 @@
5655
import org.springframework.stereotype.Component;
5756

5857
import static org.assertj.core.api.Assertions.assertThat;
59-
import static org.junit.jupiter.api.Assertions.assertTrue;
6058
import static org.mockito.ArgumentMatchers.any;
6159
import static org.mockito.BDDMockito.given;
6260
import static org.mockito.Mockito.inOrder;
@@ -478,10 +476,11 @@ public void undoSqlMigrationPrefix() {
478476
public void customFlywayClassLoader() {
479477
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class,
480478
ResourceLoaderConfiguration.class).run((context) -> {
481-
assertThat(context).hasSingleBean(Flyway.class);
482-
Flyway flyway = context.getBean(Flyway.class);
483-
assertTrue(MockUtil.isMock(flyway.getConfiguration().getClassLoader()));
484-
});
479+
assertThat(context).hasSingleBean(Flyway.class);
480+
Flyway flyway = context.getBean(Flyway.class);
481+
assertThat(flyway.getConfiguration().getClassLoader())
482+
.isInstanceOf(CustomClassLoader.class);
483+
});
485484
}
486485

487486
@Configuration(proxyBeanMethods = false)
@@ -509,7 +508,8 @@ protected static class ResourceLoaderConfiguration {
509508
@Bean
510509
@Primary
511510
public ResourceLoader customClassLoader() {
512-
return new DefaultResourceLoader(mock(ClassLoader.class));
511+
return new DefaultResourceLoader(
512+
new CustomClassLoader(getClass().getClassLoader()));
513513
}
514514

515515
}
@@ -629,4 +629,12 @@ public FlywayConfigurationCustomizer customizerTwo() {
629629

630630
}
631631

632+
private static final class CustomClassLoader extends ClassLoader {
633+
634+
private CustomClassLoader(ClassLoader parent) {
635+
super(parent);
636+
}
637+
638+
}
639+
632640
}

0 commit comments

Comments
 (0)