Skip to content

Commit

Permalink
Merge branch '2.3.x'
Browse files Browse the repository at this point in the history
Closes gh-24200
  • Loading branch information
wilkinsona committed Nov 18, 2020
2 parents 57b053a + 988526b commit 15c44aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,7 +74,7 @@ public static <T> T unwrap(DataSource dataSource, Class<T> target) {

private static <S> S safeUnwrap(Wrapper wrapper, Class<S> target) {
try {
if (wrapper.isWrapperFor(target)) {
if (target.isInterface() && wrapper.isWrapperFor(target)) {
return wrapper.unwrap(target);
}
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
package org.springframework.boot.jdbc;

import java.sql.SQLException;
import java.util.function.Consumer;

import javax.sql.DataSource;

Expand Down Expand Up @@ -87,12 +88,18 @@ void unwrapDataSourceProxy() {
assertThat(DataSourceUnwrapper.unwrap(actual, DataSourceProxy.class)).isSameAs(dataSource);
}

@Test
void unwrappingIsNotAttemptedWhenTargetIsNotAnInterface() throws SQLException {
DataSource dataSource = mock(DataSource.class);
assertThat(DataSourceUnwrapper.unwrap(dataSource, HikariDataSource.class)).isNull();
verifyNoMoreInteractions(dataSource);
}

@Test
void unwrappingIsNotAttemptedWhenDataSourceIsNotWrapperForTarget() throws SQLException {
DataSource dataSource = mock(DataSource.class);
DataSource actual = DataSourceUnwrapper.unwrap(dataSource, HikariDataSource.class);
assertThat(actual).isNull();
verify(dataSource).isWrapperFor(HikariDataSource.class);
assertThat(DataSourceUnwrapper.unwrap(dataSource, Consumer.class)).isNull();
verify(dataSource).isWrapperFor(Consumer.class);
verifyNoMoreInteractions(dataSource);
}

Expand Down

0 comments on commit 15c44aa

Please sign in to comment.