Skip to content

Commit

Permalink
Add more test cases on JDBCQueryResultMetaData (apache#33217)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Oct 11, 2024
1 parent c47c100 commit 867b3da
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Types;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -80,6 +82,13 @@ void assertGetTableName() throws SQLException {
assertThat(queryResultMetaData.getTableName(1), is("order"));
}

@Test
void assertGetTableNameWithException() throws SQLException {
ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
when(resultSetMetaData.getTableName(1)).thenThrow(new SQLFeatureNotSupportedException());
assertThat(new JDBCQueryResultMetaData(resultSetMetaData).getTableName(1), is(""));
}

@Test
void assertGetColumnType() throws SQLException {
assertThat(queryResultMetaData.getColumnType(1), is(Types.INTEGER));
Expand All @@ -100,11 +109,25 @@ void assertIsSigned() throws SQLException {
assertTrue(queryResultMetaData.isSigned(1));
}

@Test
void assertIsSignedWithException() throws SQLException {
ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
when(resultSetMetaData.isSigned(1)).thenThrow(new SQLFeatureNotSupportedException());
assertFalse(new JDBCQueryResultMetaData(resultSetMetaData).isSigned(1));
}

@Test
void assertIsNotNull() throws SQLException {
assertTrue(queryResultMetaData.isNotNull(1));
}

@Test
void assertIsNull() throws SQLException {
ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
when(resultSetMetaData.isNullable(1)).thenReturn(ResultSetMetaData.columnNullableUnknown);
assertFalse(new JDBCQueryResultMetaData(resultSetMetaData).isNotNull(1));
}

@Test
void assertIsAutoIncrement() throws SQLException {
assertTrue(queryResultMetaData.isAutoIncrement(1));
Expand Down

0 comments on commit 867b3da

Please sign in to comment.