Add test to verify behavior on null columns

This commit is contained in:
김선우
2025-01-29 11:56:49 +09:00
parent 041c8fbddc
commit 3649e8f67c

View File

@@ -100,7 +100,7 @@ class JDBC4ResultSetTest {
}
@Test
void test_getString_returnsNull() throws Exception {
void test_getString_returns_null_on_null() throws Exception {
stmt.executeUpdate("CREATE TABLE test_null (string_col TEXT);");
stmt.executeUpdate("INSERT INTO test_null (string_col) VALUES (NULL);");
@@ -134,6 +134,16 @@ class JDBC4ResultSetTest {
assertFalse(resultSet.getBoolean(1));
}
@Test
void test_getBoolean_returns_false_on_null() throws Exception {
stmt.executeUpdate("CREATE TABLE test_null (boolean_col INTEGER);");
stmt.executeUpdate("INSERT INTO test_null (boolean_col) VALUES (NULL);");
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_null");
assertTrue(resultSet.next());
assertFalse(resultSet.getBoolean(1));
}
@Test
void test_getByte() throws Exception {
stmt.executeUpdate("CREATE TABLE test_byte (byte_col INTEGER);");
@@ -156,6 +166,16 @@ class JDBC4ResultSetTest {
assertEquals(127, resultSet.getByte(1)); // -129 overflows to 127
}
@Test
void test_getByte_returns_zero_on_null() throws Exception {
stmt.executeUpdate("CREATE TABLE test_null (byte_col INTEGER);");
stmt.executeUpdate("INSERT INTO test_null (byte_col) VALUES (NULL);");
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_null");
assertTrue(resultSet.next());
assertEquals(0, resultSet.getByte(1));
}
@Test
void test_getShort() throws Exception {
stmt.executeUpdate("CREATE TABLE test_short (short_col SMALLINT);");
@@ -178,6 +198,16 @@ class JDBC4ResultSetTest {
assertEquals(-32768, resultSet.getShort(1));
}
@Test
void test_getShort_returns_zero_on_null() throws Exception {
stmt.executeUpdate("CREATE TABLE test_null (short_col INTEGER);");
stmt.executeUpdate("INSERT INTO test_null (short_col) VALUES (NULL);");
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_null");
assertTrue(resultSet.next());
assertEquals(0, resultSet.getShort(1));
}
@Test
void test_getInt() throws Exception {
stmt.executeUpdate("CREATE TABLE test_int (int_col INT);");
@@ -200,6 +230,16 @@ class JDBC4ResultSetTest {
assertEquals(-2147483648, resultSet.getInt(1));
}
@Test
void test_getInt_returns_zero_on_null() throws Exception {
stmt.executeUpdate("CREATE TABLE test_null (int_col INTEGER);");
stmt.executeUpdate("INSERT INTO test_null (int_col) VALUES (NULL);");
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_null");
assertTrue(resultSet.next());
assertEquals(0, resultSet.getInt(1));
}
@Test
@Disabled("limbo has a bug which sees -9223372036854775808 as double")
void test_getLong() throws Exception {
@@ -226,6 +266,16 @@ class JDBC4ResultSetTest {
assertEquals(-9223372036854775808L, resultSet.getLong(1));
}
@Test
void test_getLong_returns_zero_no_null() throws Exception {
stmt.executeUpdate("CREATE TABLE test_null (long_col INTEGER);");
stmt.executeUpdate("INSERT INTO test_null (long_col) VALUES (NULL);");
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_null");
assertTrue(resultSet.next());
assertEquals(0L, resultSet.getLong(1));
}
@Test
void test_getFloat() throws Exception {
stmt.executeUpdate("CREATE TABLE test_float (float_col REAL);");
@@ -256,6 +306,16 @@ class JDBC4ResultSetTest {
assertEquals(-3.4028235E38f, resultSet.getFloat(1), 0.0001);
}
@Test
void test_getFloat_returns_zero_on_null() throws Exception {
stmt.executeUpdate("CREATE TABLE test_null (float_col REAL);");
stmt.executeUpdate("INSERT INTO test_null (float_col) VALUES (NULL);");
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_null");
assertTrue(resultSet.next());
assertEquals(0.0f, resultSet.getFloat(1), 0.0001);
}
@Test
void test_getDouble() throws Exception {
stmt.executeUpdate("CREATE TABLE test_double (double_col DOUBLE);");
@@ -288,6 +348,16 @@ class JDBC4ResultSetTest {
assertEquals(-1.7976931348623157E308, resultSet.getDouble(1), 0.0001);
}
@Test
void test_getDouble_returns_zero_on_null() throws Exception {
stmt.executeUpdate("CREATE TABLE test_null (double_col REAL);");
stmt.executeUpdate("INSERT INTO test_null (double_col) VALUES (NULL);");
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_null");
assertTrue(resultSet.next());
assertEquals(0.0, resultSet.getDouble(1), 0.0001);
}
@Test
void test_getBigDecimal() throws Exception {
stmt.executeUpdate("CREATE TABLE test_bigdecimal (bigdecimal_col REAL);");
@@ -329,6 +399,16 @@ class JDBC4ResultSetTest {
resultSet.getBigDecimal(1, 2));
}
@Test
void test_getBigDecimal_returns_null_on_null() throws Exception {
stmt.executeUpdate("CREATE TABLE test_null (bigdecimal_col REAL);");
stmt.executeUpdate("INSERT INTO test_null (bigdecimal_col) VALUES (NULL);");
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_null");
assertTrue(resultSet.next());
assertNull(resultSet.getBigDecimal(1, 2));
}
@ParameterizedTest
@MethodSource("byteArrayProvider")
void test_getBytes(byte[] data) throws Exception {
@@ -355,4 +435,14 @@ class JDBC4ResultSetTest {
assertTrue(resultSet.next());
assertArrayEquals(data, resultSet.getBytes(1));
}
@Test
void test_getBytes_returns_null_on_null() throws Exception {
stmt.executeUpdate("CREATE TABLE test_null (bytes_col BLOB);");
stmt.executeUpdate("INSERT INTO test_null (bytes_col) VALUES (NULL);");
ResultSet resultSet = stmt.executeQuery("SELECT * FROM test_null");
assertTrue(resultSet.next());
assertNull(resultSet.getBytes(1));
}
}