Skip to content

Commit

Permalink
Updated test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ananya2 committed Mar 5, 2025
1 parent 99f6e72 commit 7e36f54
Showing 1 changed file with 10 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,24 +311,15 @@ public void testGetAsciiStreamOnXml() {
stmt.executeUpdate("INSERT INTO " + tableName + " (col1) VALUES (NULL)");

try (ResultSet rs = stmt.executeQuery("SELECT col1 FROM " + tableName)) {
int rowIndex = 0;
while (rs.next()) {
rowIndex++;
try {
InputStream asciiStream = rs.getAsciiStream(1);
if (rowIndex == 1) {
fail("Expected SQLException was not thrown for non-null value"); // Non-null value: Should throw an exception
} else {
assertNull(asciiStream, "Expected null for NULL value, but got a non-null InputStream"); // Null value: Should return null without throwing an exception
}
// If no exception is thrown, assert the value is null
assertNull(asciiStream, "Expected null for NULL value, but got a non-null InputStream");
} catch (SQLException e) {
if (rowIndex == 1) {
assertTrue(e.getMessage().contains("The conversion from xml to AsciiStream is unsupported."),
"Unexpected SQLException message: " + e.getMessage());
} else {
// In strict mode, NULL values may also throw an exception
assertNotNull(e, "The conversion from xml to AsciiStream is unsupported in strict mode.");
}
// Ensure that only expected exceptions occur
assertTrue(e.getMessage().contains("The conversion from xml to AsciiStream is unsupported."),
"Unexpected SQLException message: " + e.getMessage());
}
}
}
Expand All @@ -347,23 +338,15 @@ public void testGetBinaryStreamOnVarchar() {
stmt.executeUpdate("INSERT INTO " + tableName + " (col1) VALUES (NULL)");

try (ResultSet rs = stmt.executeQuery("SELECT col1 FROM " + tableName)) {
int rowIndex = 0;
while (rs.next()) {
rowIndex++;
try {
InputStream binaryStream = rs.getBinaryStream(1);
if (rowIndex == 1)
fail("Expected SQLException was not thrown for non-null value"); // Non-null value
else
assertNull(binaryStream, "Expected null for NULL value, but got a non-null InputStream"); // Null value
// If no exception is thrown, assert the value is null
assertNull(binaryStream, "Expected null for NULL value, but got a non-null InputStream");
} catch (SQLException e) {
if (rowIndex == 1) {
assertTrue(e.getMessage().contains("The conversion from varchar to BinaryStream is unsupported."),
"Unexpected SQLException message: " + e.getMessage());
} else {
// In strict mode, NULL values may also throw an exception
assertNotNull(e, "The conversion from varchar to BinaryStream is unsupported in strict mode.");
}
// Ensure that only expected exceptions occur
assertTrue(e.getMessage().contains("The conversion from varchar to BinaryStream is unsupported."),
"Unexpected SQLException message: " + e.getMessage());
}
}
}
Expand Down

0 comments on commit 7e36f54

Please sign in to comment.