Implement close on LimboStatement and JDBC4Statement independently

This commit is contained in:
김선우
2025-01-28 09:20:07 +09:00
parent eeed305b07
commit a82c459ed0
5 changed files with 85 additions and 16 deletions

View File

@@ -0,0 +1,31 @@
package org.github.tursodatabase.core;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Properties;
import org.github.tursodatabase.TestUtils;
import org.github.tursodatabase.jdbc4.JDBC4Connection;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class LimboStatementTest {
private JDBC4Connection connection;
@BeforeEach
void setUp() throws Exception {
String filePath = TestUtils.createTempFile();
String url = "jdbc:sqlite:" + filePath;
connection = new JDBC4Connection(url, filePath, new Properties());
}
@Test
void closing_statement_closes_related_resources() throws Exception {
LimboStatement stmt = connection.prepare("SELECT 1");
stmt.execute();
stmt.close();
assertTrue(stmt.isClosed());
assertFalse(stmt.getResultSet().isOpen());
}
}

View File

@@ -3,6 +3,7 @@ package org.github.tursodatabase.jdbc4;
import static org.junit.jupiter.api.Assertions.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import org.github.tursodatabase.TestUtils;
@@ -51,4 +52,22 @@ class JDBC4StatementTest {
stmt.execute("INSERT INTO users VALUES (1, 'limbo');");
assertTrue(stmt.execute("SELECT * FROM users;"));
}
@Test
void close_statement_test() throws Exception {
stmt.close();
assertTrue(stmt.isClosed());
}
@Test
void double_close_is_no_op() throws SQLException {
stmt.close();
assertDoesNotThrow(() -> stmt.close());
}
@Test
void operations_on_closed_statement_should_throw_exception() throws Exception {
stmt.close();
assertThrows(SQLException.class, () -> stmt.execute("SELECT 1"));
}
}