forked from crawshaw/sqlitejdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionTest.java
More file actions
54 lines (45 loc) · 1.61 KB
/
ConnectionTest.java
File metadata and controls
54 lines (45 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package test;
import java.io.File;
import java.sql.*;
import org.junit.*;
import static org.junit.Assert.*;
/** These tests check whether access to files is woring correctly and
* some Connection.close() cases. */
public class ConnectionTest
{
@BeforeClass public static void forName() throws Exception {
Class.forName("org.sqlite.JDBC");
}
@Test public void openMemory() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:sqlite:");
conn.close();
}
@Test public void isClosed() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:sqlite:");
assertFalse(conn.isReadOnly());
conn.close();
assertTrue(conn.isClosed());
}
@Test public void openFile() throws SQLException {
File testdb = new File("test.db");
if (testdb.exists()) testdb.delete();
assertFalse(testdb.exists());
Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");
assertFalse(conn.isReadOnly());
conn.close();
assertTrue(testdb.exists());
conn = DriverManager.getConnection("jdbc:sqlite:test.db");
assertFalse(conn.isReadOnly());
conn.close();
assertTrue(testdb.exists());
testdb.delete();
}
@Test(expected= SQLException.class)
public void closeTest() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:sqlite:");
PreparedStatement prep = conn.prepareStatement("select null;");
ResultSet rs = prep.executeQuery();
conn.close();
prep.clearParameters();
}
}