This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new c0eae747f3b Add test cases on DatabaseTypeEngineTest (#36938)
c0eae747f3b is described below
commit c0eae747f3bf5ca93f0a824211d80897c5f8415a
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Oct 25 00:55:50 2025 +0800
Add test cases on DatabaseTypeEngineTest (#36938)
* Add test cases on DatabaseTypeEngineTest
* Add test cases on DatabaseTypeEngineTest
---
.../infra/database/DatabaseTypeEngineTest.java | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java
index c80f455ccd0..c3dc371f2df 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngineTest.java
@@ -33,6 +33,7 @@ import org.junit.jupiter.api.Test;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import java.util.Collections;
import java.util.Properties;
@@ -40,6 +41,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -84,6 +86,21 @@ class DatabaseTypeEngineTest {
assertThrows(SQLWrapperException.class, () ->
DatabaseTypeEngine.getStorageType(dataSource));
}
+ @Test
+ void assertGetStorageTypeWithSQLFeatureNotSupportedExceptionReturnsEmpty()
throws SQLException {
+ Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
+
when(connection.getMetaData().getURL()).thenThrow(SQLFeatureNotSupportedException.class);
+ assertThrows(SQLWrapperException.class, () ->
DatabaseTypeEngine.getStorageType(new MockedDataSource(connection)));
+ }
+
+ @Test
+ void assertGetStorageTypeWithSQLFeatureNotSupportedExceptionAndSQLError()
throws SQLException {
+ Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
+
when(connection.getMetaData().getURL()).thenThrow(SQLFeatureNotSupportedException.class);
+
when(connection.isWrapperFor(any(Class.class))).thenThrow(SQLException.class);
+ assertThrows(SQLWrapperException.class, () ->
DatabaseTypeEngine.getStorageType(new MockedDataSource(connection)));
+ }
+
@Test
void assertGetDefaultStorageTypeWithEmptyDataSources() {
DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "MySQL");