From 9b61a8f037e2a18669606dd1ae2e8c3008eea39e Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Fri, 22 Nov 2024 14:40:21 +0100 Subject: [PATCH] Fix sonar findngs --- .../exasol/AbstractExasolSqlDialectIT.java | 33 ++++++++----------- .../ExasolSqlDialectExaConnectionIT.java | 5 ++- ...qlDialectExaConnectionWithDataTypesIT.java | 2 +- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/test/java/com/exasol/adapter/dialects/exasol/AbstractExasolSqlDialectIT.java b/src/test/java/com/exasol/adapter/dialects/exasol/AbstractExasolSqlDialectIT.java index 9ffafd9..44fff5c 100644 --- a/src/test/java/com/exasol/adapter/dialects/exasol/AbstractExasolSqlDialectIT.java +++ b/src/test/java/com/exasol/adapter/dialects/exasol/AbstractExasolSqlDialectIT.java @@ -24,7 +24,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; -import org.opentest4j.AssertionFailedError; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; @@ -47,6 +46,7 @@ abstract class AbstractExasolSqlDialectIT { private static final String COLUMN1_NAME = "C1"; @Container + @SuppressWarnings("resource") // Will be closed by @Testcontainers protected static final ExasolContainer> EXASOL = new ExasolContainer<>( IntegrationTestConfiguration.getDockerImageReference()).withReuse(true); private static ExasolSchema adapterSchema; @@ -166,8 +166,6 @@ protected void assertVirtualTableContents(final Table table, final Matcher getVirtualSchemaProperties() { return getConnectionSpecificVirtualSchemaProperties(); } - protected ResultSet selectAllFromCorrespondingVirtualTable(final VirtualSchema virtualSchema, final Table table) - throws SQLException { + protected ResultSet selectAllFromCorrespondingVirtualTable(final VirtualSchema virtualSchema, final Table table) { return selectAllFrom(getVirtualTableName(virtualSchema, table)); } - private ResultSet selectAllFrom(final String tableName) throws SQLException { + private ResultSet selectAllFrom(final String tableName) { return query("SELECT * FROM " + tableName); } @@ -206,15 +203,15 @@ protected String getVirtualTableName(final VirtualSchema virtualSchema, final Ta return virtualSchema.getFullyQualifiedName() + ".\"" + table.getName() + "\""; } - protected ResultSet query(final String sqlFormatString, final Object... args) throws SQLException { + protected ResultSet query(final String sqlFormatString, final Object... args) { return query(MessageFormat.format(sqlFormatString, args)); } - protected ResultSet query(final String sql) throws SQLException { + protected ResultSet query(final String sql) { try { return connection.createStatement().executeQuery(sql); } catch (final SQLException exception) { - throw new SQLException("Error executing '" + sql + "': " + exception.getMessage(), exception); + throw new IllegalStateException("Error executing '" + sql + "': " + exception.getMessage(), exception); } } @@ -374,11 +371,7 @@ void testIdentifierCaseSensitivityOnTable() { } protected void assertVsQuery(final String sql, final Matcher expected) { - try { - assertThat(query(sql), expected); - } catch (final SQLException exception) { - throw new AssertionFailedError("Unable to run assertion query: '" + sql + "'", exception); - } + assertThat(query(sql), expected); } @Test @@ -588,7 +581,7 @@ private void runQueryExpectedToFail(final String sql) throws SQLException { } @Test - void testCreateVirtualSchemaWithIgnoreErrorsProperty() throws SQLException { + void testCreateVirtualSchemaWithIgnoreErrorsProperty() { final Table table = createSingleColumnTable("BOOLEAN").insert(true); final Map properties = new HashMap<>(getConnectionSpecificVirtualSchemaProperties()); properties.put("IGNORE_ERRORS", EXASOL_TIMESTAMP_WITH_LOCAL_TIME_ZONE_SWITCH); @@ -850,7 +843,7 @@ void testNonDefaultIntervalDayToSecond() { } @Test - void testCurrentClusterFunction() throws SQLException { + void testCurrentClusterFunction() { final Table table = createSingleColumnTable("VARCHAR(20) UTF8").insert("_cluster"); final VirtualSchema virtualSchema = createVirtualSchema(this.sourceSchema); try { @@ -882,7 +875,7 @@ static boolean isExasol7OrLower() { } @Test - void testWildcards() throws SQLException { + void testWildcards() { assumeExasol7OrLower(); final String nameWithWildcard = "A_A"; this.sourceSchema.createTable(nameWithWildcard, "A", "VARCHAR(20)"); @@ -893,7 +886,7 @@ void testWildcards() throws SQLException { } @Test - void testWildcardsExasolV8() throws SQLException { + void testWildcardsExasolV8() { assumeExasol8OrHigher(); final String nameWithWildcard = "A_A"; this.sourceSchema.createTable(nameWithWildcard, "A", "VARCHAR(20)"); @@ -905,7 +898,7 @@ void testWildcardsExasolV8() throws SQLException { @Test @DisplayName("Verify DISTINCT with integer literal") - void testDistinctWithIntegerLiteral() throws SQLException { + void testDistinctWithIntegerLiteral() { final Table table = createSingleColumnTable("INT") // .insert(1).insert(1).insert(2).insert(3); final VirtualSchema virtualSchema = createVirtualSchema(this.sourceSchema); @@ -923,7 +916,7 @@ void testDistinctWithIntegerLiteral() throws SQLException { @Test @DisplayName("Verify GROUP BY with column number reference") - void testGroupByWithColumnNumber() throws SQLException { + void testGroupByWithColumnNumber() { final Table table = createSingleColumnTable("INT") // .insert(1).insert(1).insert(2).insert(3); final VirtualSchema virtualSchema = createVirtualSchema(this.sourceSchema); diff --git a/src/test/java/com/exasol/adapter/dialects/exasol/ExasolSqlDialectExaConnectionIT.java b/src/test/java/com/exasol/adapter/dialects/exasol/ExasolSqlDialectExaConnectionIT.java index c117d88..53c88d1 100644 --- a/src/test/java/com/exasol/adapter/dialects/exasol/ExasolSqlDialectExaConnectionIT.java +++ b/src/test/java/com/exasol/adapter/dialects/exasol/ExasolSqlDialectExaConnectionIT.java @@ -34,7 +34,6 @@ *
  • {@code GEOMETRY} types are reported with JDBC type name {@code VARCHAR} in ResultSets
  • *
      */ - class ExasolSqlDialectExaConnectionIT extends AbstractRemoteExasolVirtualSchemaConnectionIT { private static final String EXA_CONNECTION_NAME = "EXA_CONNECTION"; private ConnectionDefinition exaConnection; @@ -102,7 +101,7 @@ void testPasswordNotVisibleInImportFromExa() throws NoDriverFoundException, SQLE } @Test - void testAlterVirtualSchemaTriggersPropertyValidation() throws SQLException { + void testAlterVirtualSchemaTriggersPropertyValidation() { this.virtualSchema = createVirtualSchema(this.sourceSchema); final String name = this.virtualSchema.getFullyQualifiedName(); final SQLException exception = assertThrows(SQLException.class, @@ -111,7 +110,7 @@ void testAlterVirtualSchemaTriggersPropertyValidation() throws SQLException { assertThat(exception.getMessage(), containsString(expected)); } - private ResultSet explainVirtual(final String sql) throws SQLException { + private ResultSet explainVirtual(final String sql) { return query("EXPLAIN VIRTUAL " + sql); } diff --git a/src/test/java/com/exasol/adapter/dialects/exasol/ExasolSqlDialectExaConnectionWithDataTypesIT.java b/src/test/java/com/exasol/adapter/dialects/exasol/ExasolSqlDialectExaConnectionWithDataTypesIT.java index 019de28..645089d 100644 --- a/src/test/java/com/exasol/adapter/dialects/exasol/ExasolSqlDialectExaConnectionWithDataTypesIT.java +++ b/src/test/java/com/exasol/adapter/dialects/exasol/ExasolSqlDialectExaConnectionWithDataTypesIT.java @@ -83,7 +83,7 @@ void testPasswordNotVisibleInImportFromExa() throws NoDriverFoundException, SQLE } @Test - void testAlterVirtualSchemaTriggersPropertyValidation() throws SQLException { + void testAlterVirtualSchemaTriggersPropertyValidation() { this.virtualSchema = createVirtualSchema(this.sourceSchema); final String name = this.virtualSchema.getFullyQualifiedName(); final SQLException exception = assertThrows(SQLException.class,