@@ -457,6 +457,20 @@ void buildWhenDerivedFromCustomTypeWithTypeChange() {
457
457
assertThat (testSource .getPassword ()).isEqualTo ("secret" );
458
458
}
459
459
460
+ @ Test
461
+ void buildWhenDerivedFromCustomTypeDeriveDriverClassNameFromDerivedUrl () {
462
+ UrlCapableLimitedCustomDataSource dataSource = new UrlCapableLimitedCustomDataSource ();
463
+ dataSource .setUsername ("test" );
464
+ dataSource .setPassword ("secret" );
465
+ dataSource .setUrl ("jdbc:postgresql://localhost:5432/postgres" );
466
+ DataSourceBuilder <?> builder = DataSourceBuilder .derivedFrom (dataSource ).type (SimpleDriverDataSource .class );
467
+ SimpleDriverDataSource testSource = (SimpleDriverDataSource ) builder .build ();
468
+ assertThat (testSource .getUsername ()).isEqualTo ("test" );
469
+ assertThat (testSource .getUrl ()).isEqualTo ("jdbc:postgresql://localhost:5432/postgres" );
470
+ assertThat (testSource .getPassword ()).isEqualTo ("secret" );
471
+ assertThat (testSource .getDriver ()).isInstanceOf (org .postgresql .Driver .class );
472
+ }
473
+
460
474
@ Test // gh-31920
461
475
void buildWhenC3P0TypeSpecifiedReturnsExpectedDataSource () {
462
476
this .dataSource = DataSourceBuilder .create ()
@@ -620,12 +634,10 @@ void setPassword(String password) {
620
634
621
635
}
622
636
623
- static class CustomDataSource extends LimitedCustomDataSource {
637
+ static class UrlCapableLimitedCustomDataSource extends LimitedCustomDataSource {
624
638
625
639
private String url ;
626
640
627
- private String driverClassName ;
628
-
629
641
String getUrl () {
630
642
return this .url ;
631
643
}
@@ -634,6 +646,13 @@ void setUrl(String url) {
634
646
this .url = url ;
635
647
}
636
648
649
+ }
650
+
651
+ static class CustomDataSource extends UrlCapableLimitedCustomDataSource {
652
+
653
+ private String driverClassName ;
654
+
655
+
637
656
String getDriverClassName () {
638
657
return this .driverClassName ;
639
658
}
0 commit comments