File tree Expand file tree Collapse file tree 2 files changed +22
-12
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/jdbc
test/java/org/springframework/boot/jdbc Expand file tree Collapse file tree 2 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -281,22 +281,17 @@ public String toString() {
281
281
}
282
282
283
283
Method findSetter (Class <?> type ) {
284
- return extracted ("set" , type , true );
284
+ return extracted ("set" , type , String . class );
285
285
}
286
286
287
287
Method findGetter (Class <?> type ) {
288
- return extracted ("get" , type , false );
288
+ return extracted ("get" , type );
289
289
}
290
290
291
- private Method extracted (String prefix , Class <?> type , boolean hasParameter ) {
291
+ private Method extracted (String prefix , Class <?> type , Class <?>... paramTypes ) {
292
292
for (String candidate : this .names ) {
293
- Method method ;
294
- if (hasParameter ) {
295
- method = ReflectionUtils .findMethod (type , prefix + StringUtils .capitalize (candidate ), String .class );
296
- }
297
- else {
298
- method = ReflectionUtils .findMethod (type , prefix + StringUtils .capitalize (candidate ));
299
- }
293
+ Method method = ReflectionUtils .findMethod (type , prefix + StringUtils .capitalize (candidate ),
294
+ paramTypes );
300
295
if (method != null ) {
301
296
return method ;
302
297
}
Original file line number Diff line number Diff line change @@ -331,8 +331,23 @@ void buildWhenDerivedFromExistingDatabaseWithTypeChange() {
331
331
assertThat (built .getUrl ()).isEqualTo ("jdbc:postgresql://localhost:5432/postgres" );
332
332
}
333
333
334
- @ Test // gh -27295
335
- void buildWhenDerivedFromCustomTypeSpecifiedReturnsDataSource () {
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 () {
336
351
CustomDataSource dataSource = new CustomDataSource ();
337
352
dataSource .setUsername ("test" );
338
353
dataSource .setPassword ("secret" );
You can’t perform that action at this time.
0 commit comments