@@ -331,6 +331,34 @@ void buildWhenDerivedFromExistingDatabaseWithTypeChange() {
331
331
assertThat (built .getUrl ()).isEqualTo ("jdbc:postgresql://localhost:5432/postgres" );
332
332
}
333
333
334
+ @ Test // gh-27295
335
+ void buildWhenDerivedFromCustomType () {
336
+ CustomDataSource dataSource = new CustomDataSource ();
337
+ dataSource .setUsername ("test" );
338
+ dataSource .setPassword ("secret" );
339
+ dataSource .setUrl ("jdbc:postgresql://localhost:5432/postgres" );
340
+ DataSourceBuilder <?> builder = DataSourceBuilder .derivedFrom (dataSource ).username ("alice" )
341
+ .password ("confidential" );
342
+ CustomDataSource testSource = (CustomDataSource ) builder .build ();
343
+ assertThat (testSource ).isNotSameAs (dataSource );
344
+ assertThat (testSource .getUsername ()).isEqualTo ("alice" );
345
+ assertThat (testSource .getUrl ()).isEqualTo ("jdbc:postgresql://localhost:5432/postgres" );
346
+ assertThat (testSource .getPassword ()).isEqualTo ("confidential" );
347
+ }
348
+
349
+ @ Test // gh-27295
350
+ void buildWhenDerivedFromCustomTypeWithTypeChange () {
351
+ CustomDataSource dataSource = new CustomDataSource ();
352
+ dataSource .setUsername ("test" );
353
+ dataSource .setPassword ("secret" );
354
+ dataSource .setUrl ("jdbc:postgresql://localhost:5432/postgres" );
355
+ DataSourceBuilder <?> builder = DataSourceBuilder .derivedFrom (dataSource ).type (SimpleDriverDataSource .class );
356
+ SimpleDriverDataSource testSource = (SimpleDriverDataSource ) builder .build ();
357
+ assertThat (testSource .getUsername ()).isEqualTo ("test" );
358
+ assertThat (testSource .getUrl ()).isEqualTo ("jdbc:postgresql://localhost:5432/postgres" );
359
+ assertThat (testSource .getPassword ()).isEqualTo ("secret" );
360
+ }
361
+
334
362
final class HidePackagesClassLoader extends URLClassLoader {
335
363
336
364
private final String [] hiddenPackages ;
0 commit comments