XComp commented on code in PR #19807: URL: https://github.com/apache/flink/pull/19807#discussion_r891137397
########## flink-connectors/flink-connector-jdbc/src/test/java/org/apache/flink/connector/jdbc/JdbcRowOutputFormatTest.java: ########## @@ -76,27 +75,23 @@ public void testInvalidDriver() { .finish(); jdbcOutputFormat.open(0, 1); } catch (Exception e) { - assertTrue(findThrowable(e, IOException.class).isPresent()); - assertTrue(findThrowableWithMessage(e, expectedMsg).isPresent()); + assertThat(findThrowable(e, IOException.class)).isPresent(); + assertThat(findThrowableWithMessage(e, expectedMsg)).isPresent(); } } @Test public void testInvalidURL() { String expectedMsg = "No suitable driver found for jdbc:der:iamanerror:mory:ebookshop"; - try { - jdbcOutputFormat = - JdbcRowOutputFormat.buildJdbcOutputFormat() - .setDrivername(DERBY_EBOOKSHOP_DB.getDriverClass()) - .setDBUrl("jdbc:der:iamanerror:mory:ebookshop") - .setQuery(String.format(INSERT_TEMPLATE, INPUT_TABLE)) - .finish(); - jdbcOutputFormat.open(0, 1); - fail("expect exception"); - } catch (Exception e) { - assertTrue(findThrowable(e, IOException.class).isPresent()); - assertTrue(findThrowableWithMessage(e, expectedMsg).isPresent()); - } + + jdbcOutputFormat = + JdbcRowOutputFormat.buildJdbcOutputFormat() + .setDrivername(DERBY_EBOOKSHOP_DB.getDriverClass()) + .setDBUrl("jdbc:der:iamanerror:mory:ebookshop") + .setQuery(String.format(INSERT_TEMPLATE, INPUT_TABLE)) + .finish(); + assertThatThrownBy(() -> jdbcOutputFormat.open(0, 1)) + .satisfies(anyCauseMatches(SQLException.class, expectedMsg)); Review Comment: Why do we change from `IOException` to `SQLException` here? 🤔 ########## flink-connectors/flink-connector-jdbc/src/test/java/org/apache/flink/connector/jdbc/table/JdbcOutputFormatTest.java: ########## @@ -91,181 +87,190 @@ public void tearDown() throws Exception { @Test public void testInvalidDriver() { String expectedMsg = "unable to open JDBC writer"; - try { - JdbcConnectorOptions jdbcOptions = - JdbcConnectorOptions.builder() - .setDriverName("org.apache.derby.jdbc.idontexist") - .setDBUrl(DERBY_EBOOKSHOP_DB.getUrl()) - .setTableName(INPUT_TABLE) - .build(); - JdbcDmlOptions dmlOptions = - JdbcDmlOptions.builder() - .withTableName(jdbcOptions.getTableName()) - .withDialect(jdbcOptions.getDialect()) - .withFieldNames(fieldNames) - .build(); - - outputFormat = - new JdbcOutputFormatBuilder() - .setJdbcOptions(jdbcOptions) - .setFieldDataTypes(fieldDataTypes) - .setJdbcDmlOptions(dmlOptions) - .setJdbcExecutionOptions(JdbcExecutionOptions.builder().build()) - .build(); - outputFormat.open(0, 1); - fail("Expected exception is not thrown."); - } catch (Exception e) { - assertTrue(findThrowable(e, IOException.class).isPresent()); - assertTrue(findThrowableWithMessage(e, expectedMsg).isPresent()); - } + assertThatThrownBy( + () -> { + JdbcConnectorOptions jdbcOptions = + JdbcConnectorOptions.builder() + .setDriverName("org.apache.derby.jdbc.idontexist") + .setDBUrl(DERBY_EBOOKSHOP_DB.getUrl()) + .setTableName(INPUT_TABLE) + .build(); + JdbcDmlOptions dmlOptions = + JdbcDmlOptions.builder() + .withTableName(jdbcOptions.getTableName()) + .withDialect(jdbcOptions.getDialect()) + .withFieldNames(fieldNames) + .build(); + + outputFormat = + new JdbcOutputFormatBuilder() + .setJdbcOptions(jdbcOptions) + .setFieldDataTypes(fieldDataTypes) + .setJdbcDmlOptions(dmlOptions) + .setJdbcExecutionOptions( + JdbcExecutionOptions.builder().build()) + .build(); + outputFormat.open(0, 1); + }) + .hasMessage(expectedMsg); Review Comment: We're not checking for the `IOException` here 🤔 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org