Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Syntactic sugar for readibility of unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Nov 17, 2023
1 parent b1dba1f commit 1d92b73
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 337 deletions.
40 changes: 20 additions & 20 deletions src/test/java/net/ucanaccess/jdbc/AccessLikeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected String getAccessPath() {
@MethodSource("net.ucanaccess.type.AccessVersion#getDefaultAccessVersion()")
void testLike(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT * FROM query1 ORDER BY campo2", "dd1");
checkQuery("SELECT * FROM query1 ORDER BY campo2", singleRec("dd1"));
}

@ParameterizedTest(name = "[{index}] {0}")
Expand All @@ -37,26 +37,25 @@ void testLikeExternal(AccessVersion _accessVersion) throws SQLException, IOExcep
"dsdsds", "aa", "aBa", "aBBBa", "PB123", "PZ123", "a*a", "A*a", "ss#sss", "*", "132B", "138", "138#")) {
st.execute("INSERT INTO T21 (descr) VALUES('" + val + "')");
}
Object[][] ver = {{"a*a"}, {"A*a"}};
checkQuery("SELECT descr FROM T21 WHERE descr LIKE 'a[*]a' ORDER BY ID", ver);

checkQuery("SELECT descr FROM T21 WHERE descr LIKE 'a[*]a' ORDER BY ID",
recs(rec("a*a"), rec("A*a")));

ver = new Object[][] {{"aa"}, {"aBa"}, {"aBBBa"}, {"a*a"}, {"A*a"}};
checkQuery("SELECT descr FROM T21 WHERE descr LIKE \"a*a\" AND '1'='1' AND (descr) like \"a*a\" ORDER BY ID", ver);
checkQuery("SELECT descr FROM T21 WHERE descr LIKE \"a*a\" AND '1'='1' AND (descr) like \"a*a\" ORDER BY ID",
recs(rec("aa"), rec("aBa"), rec("aBBBa"), rec("a*a"), rec("A*a")));

ver = new Object[][] {{2, "aa"}, {3, "aBa"}, {4, "aBBBa"}, {7, "a*a"}, {8, "A*a"}};
checkQuery("SELECT * FROM T21 WHERE descr LIKE 'a%a'", ver);

checkQuery("SELECT descr FROM T21 WHERE descr LIKE 'P[A-F]###'", "PB123");
checkQuery("SELECT descr FROM T21 WHERE (T21.descr\n) \nLIKE 'P[!A-F]###' AND '1'='1'", "PZ123");
checkQuery("SELECT * FROM T21 WHERE descr='aba'", 3, "aBa");
checkQuery("SELECT descr FROM T21 WHERE descr LIKE '13[1-4][A-F]'", "132B");
checkQuery("SELECT descr FROM T21 WHERE descr LIKE '13[!1-4]'", "138");
checkQuery("SELECT descr FROM T21 WHERE descr LIKE '%s[#]%'", "ss#sss");
checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###'", "138");
checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###[#]'", "138#");

checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###[#]'", "138#");
checkQuery("SELECT descr FROM T21 WHERE ((descr LIKE '###[#]'))", "138#");
checkQuery("SELECT * FROM T21 WHERE descr LIKE 'a%a'",
recs(rec(2, "aa"), rec(3, "aBa"), rec(4, "aBBBa"), rec(7, "a*a"), rec(8, "A*a")));
checkQuery("SELECT descr FROM T21 WHERE descr LIKE 'P[A-F]###'", singleRec("PB123"));
checkQuery("SELECT descr FROM T21 WHERE (T21.descr\n) \nLIKE 'P[!A-F]###' AND '1'='1'", singleRec("PZ123"));
checkQuery("SELECT * FROM T21 WHERE descr='aba'", singleRec(3, "aBa"));
checkQuery("SELECT descr FROM T21 WHERE descr LIKE '13[1-4][A-F]'", singleRec("132B"));
checkQuery("SELECT descr FROM T21 WHERE descr LIKE '13[!1-4]'", singleRec("138"));
checkQuery("SELECT descr FROM T21 WHERE descr LIKE '%s[#]%'", singleRec("ss#sss"));
checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###'", singleRec("138"));
checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###[#]'", singleRec("138#"));
checkQuery("SELECT descr FROM T21 WHERE descr LIKE '###[#]'", singleRec("138#"));
checkQuery("SELECT descr FROM T21 WHERE ((descr LIKE '###[#]'))", singleRec("138#"));
st.execute("DROP TABLE " + tableName);
}
}
Expand All @@ -73,7 +72,8 @@ void testNotLikeExternal(AccessVersion _accessVersion) throws SQLException {
st.execute("INSERT INTO Tx21(descr) VALUES('t11114')");
st.execute("INSERT INTO Tx21(descr) VALUES('t1111C')");
st.execute("INSERT INTO Tx21(descr) VALUES('t1111')");
checkQuery("SELECT DESCR FROM Tx21 WHERE descr NOT LIKE \"t#####\" ORDER BY id", new Object[][] {{"t1111C"}, {"t1111"}});
checkQuery("SELECT DESCR FROM Tx21 WHERE descr NOT LIKE \"t#####\" ORDER BY id",
recs(rec("t1111C"), rec("t1111")));
st.execute("DROP TABLE " + tableName);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/ucanaccess/jdbc/AddFunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void testAddFunction(AccessVersion _accessVersion) throws Exception {

ucanaccess.addFunctions(AddFunctions.class);
dumpQueryResult("SELECT pluto('hello', ' world ', NOW()) FROM t_add_function");
checkQuery("SELECT CONCAT('Hello World, ', 'Ucanaccess') FROM t_add_function", "Hello World, Ucanaccess");
checkQuery("SELECT CONCAT('Hello World, ', 'Ucanaccess') FROM t_add_function", singleRec("Hello World, Ucanaccess"));

executeStatements("DROP TABLE t_add_function");
}
Expand Down
28 changes: 14 additions & 14 deletions src/test/java/net/ucanaccess/jdbc/AggregateFunctionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,70 +35,70 @@ void afterEachTest() throws SQLException {
void testDCount(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);

checkQuery("SELECT id, DCount('*', 't235', '1=1') FROM [t235]", new Object[][] {{1234, 2}, {12344, 2}});
checkQuery("SELECT id as [WW \"SS], DCount('descr', 't235', '1=1')from t235",
new Object[][] {{1234, 2}, {12344, 2}});
checkQuery("SELECT DCount('*', 't235', '1=1') ", 2);
checkQuery("SELECT id, DCount('*', 't235', '1=1') FROM [t235]", recs(rec(1234, 2), rec(12344, 2)));
checkQuery("SELECT id AS [WW \"SS], DCount('descr', 't235', '1=1') FROM t235",
recs(rec(1234, 2), rec(12344, 2)));
checkQuery("SELECT DCount('*', 't235', '1=1') ", singleRec(2));
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testDSum(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT DSum('id', 't235', '1=1')", 13578);
checkQuery("SELECT DSum('id', 't235', '1=1')", singleRec(13578));
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testDMax(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT DMax('id', 't235')", 12344);
checkQuery("SELECT DMax('id', 't235')", singleRec(12344));
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testDMin(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT DMin('id', 't235')", 1234);
checkQuery("SELECT DMin('id', 't235')", singleRec(1234));
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testDAvg(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT DAvg('id', 't235')", 6789);
checkQuery("SELECT DAvg('id', 't235')", singleRec(6789));
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testLast(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT last(descr) FROM t235", "Show must go up and down");
checkQuery("SELECT last(NUM) FROM t235", -113.5540);
checkQuery("SELECT last(descr) FROM t235", singleRec("Show must go up and down"));
checkQuery("SELECT last(NUM) FROM t235", singleRec(-113.5540));
dumpQueryResult("SELECT last(date0) FROM t235");
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testFirst(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT first(descr) FROM t235", "Show must go off");
checkQuery("SELECT first(NUM) FROM t235", -1110.5540);
checkQuery("SELECT first(descr) FROM t235", singleRec("Show must go off"));
checkQuery("SELECT first(NUM) FROM t235", singleRec(-1110.5540));
dumpQueryResult("SELECT first(date0) FROM t235");
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testDLast(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT DLast('descr', 't235')", "Show must go up and down");
checkQuery("SELECT DLast('descr', 't235')", singleRec("Show must go up and down"));
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testDFirst(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
checkQuery("SELECT DFirst('descr', 't235') ", "Show must go off");
checkQuery("SELECT DFirst('descr', 't235') ", singleRec("Show must go off"));
}

}
10 changes: 5 additions & 5 deletions src/test/java/net/ucanaccess/jdbc/AlterTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ void testMiscellaneous(AccessVersion _accessVersion) throws SQLException, IOExce
st.execute("ALTER TABLE tx ADD FOREIGN KEY ([my best friend], [Is Pippo]) REFERENCES tx1(n1, [n 2]) ON DELETE CASCADE");
st.execute("INSERT INTO tx1 values(1,\"ciao\")");
st.execute("INSERT INTO tx ([my best friend], [my worst friend], [Is Pippo]) values(1, 2, \"ciao\")");
checkQuery("SELECT COUNT(*) FROM tx", 1);
checkQuery("SELECT COUNT(*) FROM tx", singleRec(1));
st.execute("DELETE FROM tx1");
checkQuery("SELECT COUNT(*) FROM tx");
checkQuery("SELECT COUNT(*) FROM tx", 0);
checkQuery("SELECT COUNT(*) FROM tx", singleRec(0));
st.execute("DROP TABLE tx ");
st.execute("DROP TABLE tx1 ");

Expand All @@ -258,10 +258,10 @@ void testMiscellaneous(AccessVersion _accessVersion) throws SQLException, IOExce
st.execute("ALTER TABLE tx ADD FOREIGN KEY ([my best friend], [Is Pippo]) REFERENCES tx1(n1, [n 2]) ON DELETE SET NULL");
st.execute("INSERT INTO tx1 VALUES(1, \"ciao\")");
st.execute("INSERT INTO tx ([my best friend], [my worst friend], [Is Pippo]) VALUES(1, 2, \"ciao\")");
checkQuery("SELECT COUNT(*) FROM tx", 1);
checkQuery("SELECT COUNT(*) FROM tx", singleRec(1));
st.execute("DELETE FROM tx1");
checkQuery("SELECT COUNT(*) FROM tx", 1);
checkQuery("SELECT * FROM tx", 1, null, 2.0, null, "what's this?");
checkQuery("SELECT COUNT(*) FROM tx", singleRec(1));
checkQuery("SELECT * FROM tx", singleRec(1, null, 2.0, null, "what's this?"));
st.execute("CREATE UNIQUE INDEX IDX111 ON tx ([my best friend])");

assertThatThrownBy(() -> st.execute("INSERT INTO tx ([my best friend], [my worst friend], [Is Pippo]) values(1, 2, \"ciao\")"))
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/net/ucanaccess/jdbc/BlobOleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ void testBlobOle(AccessVersion _accessVersion) throws SQLException, IOException

byte[] fileBytes = Files.readAllBytes(imgFileTemp.toPath());

checkQuery("SELECT * FROM t_ole_test", new Object[][] {{1, descr, fileBytes}});
checkQuery("SELECT * FROM t_ole_test", singleRec(1, descr, fileBytes));

PreparedStatement ps = ucanaccess.prepareStatement("UPDATE t_ole_test SET c_descr=? WHERE c_descr=?");
ps.setString(1, descr + "_OK");
ps.setString(2, descr);
ps.executeUpdate();
checkQuery("SELECT * FROM t_ole_test");
checkQuery("SELECT * FROM t_ole_test", 1, descr + "_OK", fileBytes);
checkQuery("SELECT * FROM t_ole_test", singleRec(1, descr + "_OK", fileBytes));
}

try (PreparedStatement ps = ucanaccess.prepareStatement("UPDATE t_ole_test SET c_ole=? WHERE c_descr=?")) {
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/net/ucanaccess/jdbc/CalculatedFieldTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ void testFunctionBuiltInCall(AccessVersion _accessVersion) throws Exception {
dumpQueryResult("SELECT * FROM clcdFlds");

checkQuery("SELECT input, clcd1, clcd2, clcd3, clcd4 FROM clcdFlds ORDER BY id",
new String[][] {{"my", "my", "my", "my", "my"},
{"myc", "myc", "myc", "myc", "myc"},
{"mycat", "myc", "myc", "cat", "cat"},
{"mycattom", "myc", "myc", "tom", "tom"},
{"", "", "", "", ""}});
recs(rec("my", "my", "my", "my", "my"),
rec("myc", "myc", "myc", "myc", "myc"),
rec("mycat", "myc", "myc", "cat", "cat"),
rec("mycattom", "myc", "myc", "tom", "tom"),
rec("", "", "", "", "")));

// inserting NULL into a calculated column containing a STRING formula is not permitted
assertThatThrownBy(() -> st.execute("INSERT INTO clcdFlds (input) VALUES (null)"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected UcanaccessConnectionBuilder buildConnection() {
@MethodSource("net.ucanaccess.type.AccessVersion#getDefaultAccessVersion()")
void testConcat(AccessVersion _accessVersion) throws Exception {
init(_accessVersion);
checkQuery("SELECT 'aa2'& null FROM dual", new Object[][] {{"aa2"}});
checkQuery("SELECT 'aa2'& null FROM dual", singleRec("aa2"));
}

}
2 changes: 1 addition & 1 deletion src/test/java/net/ucanaccess/jdbc/ConcatNullsTrueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected UcanaccessConnectionBuilder buildConnection() {
@MethodSource("net.ucanaccess.type.AccessVersion#getDefaultAccessVersion()")
void testConcat(AccessVersion _accessVersion) throws Exception {
init(_accessVersion);
checkQuery("SELECT 'aa2'& null FROM dual", new Object[][] {{null}});
checkQuery("SELECT 'aa2'& null FROM dual", recs(rec((Object) null)));
}

}
21 changes: 10 additions & 11 deletions src/test/java/net/ucanaccess/jdbc/CounterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,16 @@ void testCreateTypes(AccessVersion _accessVersion) throws SQLException {
}

dumpQueryResult("SELECT * FROM t_counter");
Object[][] ver = {
{-1, "A", null, null},
{3, "C", null, null},
{4, "D", null, null},
{5, "E", null, null},
{6, "F", null, null},
{7, "G", null, null},
{8, "H", null, null},
{9, "I", null, null}
};
checkQuery("SELECT * FROM t_counter ORDER BY cntr", ver);
checkQuery("SELECT * FROM t_counter ORDER BY cntr", recs(
rec(-1, "A", null, null),
rec(3, "C", null, null),
rec(4, "D", null, null),
rec(5, "E", null, null),
rec(6, "F", null, null),
rec(7, "G", null, null),
rec(8, "H", null, null),
rec(9, "I", null, null)
));

}

Expand Down
12 changes: 6 additions & 6 deletions src/test/java/net/ucanaccess/jdbc/CreateTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected String getAccessPath() {
private void createAsSelect() throws SQLException {
try (Statement st = ucanaccess.createStatement()) {
st.executeUpdate("CREATE TABLE AAA_BIS as (SELECT baaaa,a,c FROM AAA) WITH DATA");
Object[][] ver = {{"33A", 3, "G"}, {"33B", 111, "G"}};
checkQuery("SELECT * FROM AAA_bis ORDER BY baaaa", ver);
checkQuery("SELECT * FROM AAA_bis ORDER BY baaaa",
recs(rec("33A", 3, "G"), rec("33B", 111, "G")));
st.executeUpdate("CREATE TABLE AAA_quadris as (SELECT AAA.baaaa,AAA_BIS.baaaa as xxx FROM AAA,AAA_BIS) WITH DATA");
dumpQueryResult("SELECT * FROM AAA_quadris ORDER BY baaaa");
}
Expand All @@ -42,8 +42,8 @@ private void createAsSelect2() throws SQLException {
try (Statement st = ucanaccess.createStatement()) {
st.executeUpdate("CREATE TABLE AAA_TRIS as (SELECT baaaa,a,c FROM AAA) WITH NO DATA");
st.execute("INSERT INTO AAA_TRIS SELECT * FROM AAA_bis");
Object[][] ver = {{"33A", 3, "G"}, {"33B", 111, "G"}};
checkQuery("SELECT * FROM AAA_tris ORDER BY baaaa", ver);
checkQuery("SELECT * FROM AAA_tris ORDER BY baaaa",
recs(rec("33A", 3, "G"), rec("33B", 111, "G")));
}
}

Expand All @@ -61,8 +61,8 @@ private void createSimple() throws SQLException {
executeStatements(st,
"INSERT INTO AAA(baaaa, c) VALUES ('33A', 'G')",
"INSERT INTO AAA(baaaa, a, c) VALUES ('33B', 111, 'G')");
Object[][] ver = {{"33A", 3, "G"}, {"33B", 111, "G"}};
checkQuery("SELECT baaaa, a, c FROM AAA ORDER BY baaaa", ver);
checkQuery("SELECT baaaa, a, c FROM AAA ORDER BY baaaa",
recs(rec("33A", 3, "G"), rec("33B", 111, "G")));
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/test/java/net/ucanaccess/jdbc/CrudTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void testCrudPSBatch(AccessVersion _accessVersion) throws SQLException {
ps.executeBatch();
ps.clearBatch();
}
checkQuery("SELECT * FROM t1", new Object[][] {{id1, "Prep1"}, {id2, "Prep2"}});
checkQuery("SELECT * FROM t1", recs(rec(id1, "Prep1"), rec(id2, "Prep2")));
assertEquals(2, getCount("SELECT COUNT(*) FROM t1 where id in (" + id1 + ", " + id2 + ")"), "Insert failed");

try (PreparedStatement ps = ucanaccess.prepareStatement("DELETE FROM t1")) {
Expand All @@ -110,7 +110,7 @@ void testUpdatableRS(AccessVersion _accessVersion) throws SQLException {
rs.next();
rs.updateString(2, "show must go off");
rs.updateRow();
checkQuery("SELECT * FROM t1", new Object[][] {{6666554, "show must go off"}});
checkQuery("SELECT * FROM t1", singleRec(6666554, "show must go off"));
st.execute("DELETE FROM t1");
}
}
Expand All @@ -133,8 +133,7 @@ void testDeleteRS(AccessVersion _accessVersion) throws SQLException, IOException

rs.deleteRow();
ps.getConnection().commit();

checkQuery("SELECT COUNT(*) FROM t1", 0);
checkQuery("SELECT COUNT(*) FROM t1", singleRec(0));
}

@ParameterizedTest(name = "[{index}] {0}")
Expand All @@ -155,8 +154,8 @@ void testInsertRS(AccessVersion _accessVersion) throws SQLException {

rs.insertRow();
ps.getConnection().commit();
Object[][] ver = {{4, "Growing old in rural pleaces"}, {6666554, "tre canarini volano su e cadono"}};
checkQuery("SELECT * FROM t1 ORDER BY id", ver);
checkQuery("SELECT * FROM t1 ORDER BY id",
recs(rec(4, "Growing old in rural pleaces"), rec(6666554, "tre canarini volano su e cadono")));
st.execute("DELETE FROM t1");
}
}
Expand All @@ -182,7 +181,7 @@ void testInsertRSNoAllSet(AccessVersion _accessVersion) throws SQLException, IOE
rs.next();
ps.getConnection().commit();

checkQuery("SELECT * FROM T2 ORDER BY id", 1, "Growing old in rural places");
checkQuery("SELECT * FROM T2 ORDER BY id", singleRec(1, "Growing old in rural places"));
Statement stat = ucanaccess.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs1 = stat.executeQuery("SELECT * FROM T2 ORDER BY id");
rs1.last();
Expand All @@ -208,8 +207,7 @@ void testPartialInsertRS(AccessVersion _accessVersion) throws SQLException {

rs.insertRow();
ps.getConnection().commit();
Object[][] ver = {{1, "Growing old without emotions"}};
checkQuery("SELECT * FROM T21 ORDER BY id", ver);
checkQuery("SELECT * FROM T21 ORDER BY id", singleRec(1, "Growing old without emotions"));
st.execute("DELETE FROM t21");
}
}
Expand Down
Loading

0 comments on commit 1d92b73

Please sign in to comment.