diff --git a/src/main/java/org/kiwiproject/test/h2/H2DatabaseTestHelper.java b/src/main/java/org/kiwiproject/test/h2/H2DatabaseTestHelper.java index 67a275da..df6c9ffe 100644 --- a/src/main/java/org/kiwiproject/test/h2/H2DatabaseTestHelper.java +++ b/src/main/java/org/kiwiproject/test/h2/H2DatabaseTestHelper.java @@ -4,14 +4,15 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.SystemUtils; import org.h2.jdbcx.JdbcDataSource; -import org.kiwiproject.test.jdbc.RuntimeSQLException; +import org.kiwiproject.jdbc.UncheckedSQLException; -import javax.sql.DataSource; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.sql.SQLException; +import javax.sql.DataSource; + /** * Utilities for H2 databases. *

@@ -33,7 +34,7 @@ public class H2DatabaseTestHelper { * * @return a {@link H2FileBasedDatabase} that represents the new database * @throws IllegalStateException if the database directory could not be created - * @throws RuntimeSQLException if any other error occurs + * @throws UncheckedSQLException if any other error occurs * @see System#getProperty(String) */ public static H2FileBasedDatabase buildH2FileBasedDatabase() { @@ -55,7 +56,7 @@ private static File newH2DatabaseDirectory() { * @param h2DatabaseDirectory the directory where the database resides * @return a {@link DataSource} that can be used to connect to the H2 database * @throws IllegalStateException if the database directory could not be created - * @throws RuntimeSQLException if any other error occurs + * @throws UncheckedSQLException if any other error occurs */ public static DataSource buildH2DataSource(File h2DatabaseDirectory) { try { @@ -84,7 +85,7 @@ private static DataSource buildH2DatabaseWithTestTable(File h2DatabaseDirectory) LOG.trace("Successfully created test_table"); return dataSource; } catch (SQLException e) { - throw new RuntimeSQLException(e); + throw new UncheckedSQLException(e); } } diff --git a/src/main/java/org/kiwiproject/test/jdbc/RuntimeSQLException.java b/src/main/java/org/kiwiproject/test/jdbc/RuntimeSQLException.java index e7045af9..9234e656 100644 --- a/src/main/java/org/kiwiproject/test/jdbc/RuntimeSQLException.java +++ b/src/main/java/org/kiwiproject/test/jdbc/RuntimeSQLException.java @@ -1,8 +1,8 @@ package org.kiwiproject.test.jdbc; import org.kiwiproject.base.KiwiDeprecated; -import org.kiwiproject.base.KiwiPreconditions; import org.kiwiproject.base.KiwiDeprecated.Severity; +import org.kiwiproject.base.KiwiPreconditions; import java.sql.SQLException; @@ -11,6 +11,7 @@ * * @deprecated replaced by UncheckedSQLException in kiwi 4.2.0 */ +@SuppressWarnings("DeprecatedIsStillUsed") @Deprecated(since = "3.6.0", forRemoval = true) @KiwiDeprecated( removeAt = "4.0.0", diff --git a/src/main/java/org/kiwiproject/test/jdbc/SimpleSingleConnectionDataSource.java b/src/main/java/org/kiwiproject/test/jdbc/SimpleSingleConnectionDataSource.java index 3f9fda3d..ab8c7ac1 100644 --- a/src/main/java/org/kiwiproject/test/jdbc/SimpleSingleConnectionDataSource.java +++ b/src/main/java/org/kiwiproject/test/jdbc/SimpleSingleConnectionDataSource.java @@ -6,8 +6,8 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.kiwiproject.jdbc.UncheckedSQLException; -import javax.sql.DataSource; import java.io.Closeable; import java.io.PrintWriter; import java.lang.reflect.InvocationHandler; @@ -21,6 +21,8 @@ import java.util.Objects; import java.util.logging.Logger; +import javax.sql.DataSource; + /** * A very simple implementation of {@link DataSource} intended to be used only during tests. As its name * suggests, this implementation stores a single {@link Connection} which is always returned by the @@ -120,7 +122,7 @@ private static Connection getConnectionFromDriverManager(String url, String user try { return DriverManager.getConnection(url, username, password); } catch (SQLException e) { - throw new RuntimeSQLException(f("Error getting Connection for URL {} and username {}", url, username), e); + throw new UncheckedSQLException(f("Error getting Connection for URL {} and username {}", url, username), e); } } diff --git a/src/test/java/org/kiwiproject/test/jdbc/RuntimeSQLExceptionTest.java b/src/test/java/org/kiwiproject/test/jdbc/RuntimeSQLExceptionTest.java index f51ad069..a4da0b09 100644 --- a/src/test/java/org/kiwiproject/test/jdbc/RuntimeSQLExceptionTest.java +++ b/src/test/java/org/kiwiproject/test/jdbc/RuntimeSQLExceptionTest.java @@ -7,6 +7,7 @@ import java.sql.SQLException; +@SuppressWarnings("removal") @DisplayName("RuntimeSQLException") class RuntimeSQLExceptionTest { @@ -29,4 +30,4 @@ void shouldConstructWithSQLException() { .hasMessage("Statement error") .hasCauseReference(sqlEx); } -} \ No newline at end of file +} diff --git a/src/test/java/org/kiwiproject/test/jdbc/SimpleSingleConnectionDataSourceTest.java b/src/test/java/org/kiwiproject/test/jdbc/SimpleSingleConnectionDataSourceTest.java index 83fc9915..d24d68fd 100644 --- a/src/test/java/org/kiwiproject/test/jdbc/SimpleSingleConnectionDataSourceTest.java +++ b/src/test/java/org/kiwiproject/test/jdbc/SimpleSingleConnectionDataSourceTest.java @@ -12,9 +12,9 @@ import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import org.kiwiproject.jdbc.UncheckedSQLException; import org.kiwiproject.test.junit.jupiter.H2FileBasedDatabaseExtension; -import javax.sql.DataSource; import java.io.PrintWriter; import java.io.StringWriter; import java.sql.Connection; @@ -23,6 +23,8 @@ import java.util.logging.Logger; import java.util.stream.IntStream; +import javax.sql.DataSource; + @DisplayName("SimpleSingleConnectionDataSource") class SimpleSingleConnectionDataSourceTest { @@ -47,7 +49,7 @@ void shouldThrow_GivenInvalidCredentials() { var thrown = catchThrowable(() -> new SimpleSingleConnectionDataSource(url, "bad_user")); - assertThat(thrown).isExactlyInstanceOf(RuntimeSQLException.class); + assertThat(thrown).isExactlyInstanceOf(UncheckedSQLException.class); // The actual cause (as of the time I write this) is a org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException. // Since I do not want to be so specific to a vendor implementation, just check that there is a non-null cause. @@ -75,7 +77,7 @@ private Connection tryGetConnection() { try { return dataSource.getConnection(); } catch (SQLException e) { - throw new RuntimeSQLException(e); + throw new UncheckedSQLException(e); } } @@ -126,7 +128,7 @@ private Connection tryGetConnection(String username, String password) { try { return dataSource.getConnection(username, password); } catch (SQLException e) { - throw new RuntimeSQLException(e); + throw new UncheckedSQLException(e); } } }