Commit 15c44aa4 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '2.3.x'

Closes gh-24200
parents 57b053aa 988526be
/*
* 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.
......@@ -74,7 +74,7 @@ public final class DataSourceUnwrapper {
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);
}
}
......
/*
* 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.
......@@ -17,6 +17,7 @@
package org.springframework.boot.jdbc;
import java.sql.SQLException;
import java.util.function.Consumer;
import javax.sql.DataSource;
......@@ -87,12 +88,18 @@ class DataSourceUnwrapperTests {
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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment