public void testSqlStringExpression() {
log.debug("Testing SqlStringExpression");
// constructing
try {
new SqlStringExpression("");
} catch (Exception e) {
fail("Constructing of SqlStringExpression failed with empty string");
}
try {
new SqlStringExpression("a");
} catch (Exception e) {
fail("Constructing of SqlStringExpression failed with non-empty string");
}
try {
new SqlStringExpression("a", new Object[0]);
} catch (Exception e) {
fail("Constructing of SqlStringExpression failed with non-empty string and an empty array");
}
try {
new SqlStringExpression("a", new Object[] { "b", "c" });
} catch (Exception e) {
fail("Constructing of SqlStringExpression failed with non-empty string and two values");
}
try {
new SqlStringExpression(null);
fail("SqlStringExpression's string can not be null");
} catch (Exception e) {
// normal
}
try {
new SqlStringExpression("a", null);
fail("SqlStringExpression's values array can not be null");
} catch (Exception e) {
// normal
}
// SQL String
assertEquals("SqlStringExpression must return an empty string",
new SqlStringExpression("").toSqlString(), "");
assertEquals("SqlStringExpression must return \"a\"",
new SqlStringExpression("a").toSqlString(), "a");
// SQL arguments
assertTrue("SqlStringExpression must return an empty array",
Arrays.equals(new SqlStringExpression("a", new Object[0])
.getValues(), new Object[0]));
assertTrue("SqlStringExpression must return (\"b\", \"c\") as values",
Arrays.equals(new SqlStringExpression("a", new Object[] { "b",
"c" }).getValues(), new Object[] { "b", "c" }));
}