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() {
281281 }
282282
283283 Method findSetter (Class <?> type ) {
284- return extracted ("set" , type , true );
284+ return extracted ("set" , type , String . class );
285285 }
286286
287287 Method findGetter (Class <?> type ) {
288- return extracted ("get" , type , false );
288+ return extracted ("get" , type );
289289 }
290290
291- private Method extracted (String prefix , Class <?> type , boolean hasParameter ) {
291+ private Method extracted (String prefix , Class <?> type , Class <?>... paramTypes ) {
292292 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 );
300295 if (method != null ) {
301296 return method ;
302297 }
Original file line number Diff line number Diff line change @@ -331,8 +331,23 @@ void buildWhenDerivedFromExistingDatabaseWithTypeChange() {
331331 assertThat (built .getUrl ()).isEqualTo ("jdbc:postgresql://localhost:5432/postgres" );
332332 }
333333
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 () {
336351 CustomDataSource dataSource = new CustomDataSource ();
337352 dataSource .setUsername ("test" );
338353 dataSource .setPassword ("secret" );
You can’t perform that action at this time.
0 commit comments