From 2b9636d0befc25510b9ac3743782925a74a36731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kubik?= Date: Tue, 26 Nov 2024 10:25:38 +0100 Subject: [PATCH] merge getString getBytes and getObject test into one method to reuse queried resultSet --- ...edTypesArrowJsonCompatibilityLatestIT.java | 22 ++++--------------- .../StructuredTypesGetStringBaseIT.java | 17 ++++++-------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesArrowJsonCompatibilityLatestIT.java b/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesArrowJsonCompatibilityLatestIT.java index cd8cb5ba1..c4c870e08 100644 --- a/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesArrowJsonCompatibilityLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesArrowJsonCompatibilityLatestIT.java @@ -1,6 +1,7 @@ package net.snowflake.client.jdbc.structuredtypes; import java.sql.Connection; +import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; @@ -23,6 +24,7 @@ public class StructuredTypesArrowJsonCompatibilityLatestIT extends StructuredTyp private final String expectedStructureTypeRepresentation; private final String selectSql; private static Map connections = new HashMap<>(); + private static Map> resultSets = new HashMap<>(); public StructuredTypesArrowJsonCompatibilityLatestIT( ResultSetFormatType queryResultFormat, @@ -51,27 +53,11 @@ public static void closeConnections() throws SQLException { } @Test - public void testRunAsGetString() throws SQLException { + public void testArrowJsonCompatibility() throws SQLException { withFirstRow( connections.get(queryResultFormat), selectSql, - (resultSet) -> assertGetStringIsCompatible(resultSet, expectedStructureTypeRepresentation)); - } - - @Test - public void testRunAsGetObject() throws SQLException { - withFirstRow( - connections.get(queryResultFormat), - selectSql, - (resultSet) -> assertGetObjectIsCompatible(resultSet, expectedStructureTypeRepresentation)); - } - - @Test - public void testRunAsGetBytes() throws SQLException { - withFirstRow( - connections.get(queryResultFormat), - selectSql, - (resultSet) -> assertGetBytesIsCompatible(resultSet, expectedStructureTypeRepresentation)); + (resultSet) -> assertResultSetIsCompatible(resultSet, expectedStructureTypeRepresentation)); } @Parameterized.Parameters(name = "format={0},sql={1}") diff --git a/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesGetStringBaseIT.java b/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesGetStringBaseIT.java index 392afd84b..5b56d2d96 100644 --- a/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesGetStringBaseIT.java +++ b/src/test/java/net/snowflake/client/jdbc/structuredtypes/StructuredTypesGetStringBaseIT.java @@ -51,24 +51,21 @@ protected static Connection initConnection(ResultSetFormatType queryResultFormat return conn; } - protected void assertGetStringIsCompatible(ResultSet resultSet, String expected) - throws SQLException { + protected void assertResultSetIsCompatible(ResultSet resultSet, String expected) + throws SQLException { + // Test getString String result = resultSet.getString(1); TestUtil.assertEqualsIgnoringWhitespace(expected, result); - } - protected void assertGetObjectIsCompatible(ResultSet resultSet, String expected) - throws SQLException { - String result = resultSet.getObject(1, String.class); + // Test getObject + result = resultSet.getObject(1, String.class); String resultCasted = (String) resultSet.getObject(1); TestUtil.assertEqualsIgnoringWhitespace(expected, result); TestUtil.assertEqualsIgnoringWhitespace(expected, resultCasted); - } - protected void assertGetBytesIsCompatible(ResultSet resultSet, String expected) - throws SQLException { + // Test getBytes TestUtil.assertEqualsIgnoringWhitespace( - expected, new String(resultSet.getBytes(1), StandardCharsets.UTF_8)); + expected, new String(resultSet.getBytes(1), StandardCharsets.UTF_8)); } protected void withFirstRow(