I'd test them in action, if you test the serialization instead you'll be looking at prepared statement templates and your tests might break when Querydsl serialization logic is changed.
How to test QueryDsl predicates
-
27-06-2022 - |
Question
I have an utility class I use for my QueryDsl queries. I have, for example the following method:
public static StringExpression emptyIfNull(StringExpression expression) {
return expression.coalesce("").asString();
}
What I actually want to be sure of is that
- The expression evaluates to
""
when the original expression wasnull
- The expression evaluates to the original string otherwise
How should I test this? Should I setup a db test with my whole context or is there a simpler way to verify that the correct expressions are added, i.e., that using the utility method gives me a COALESCE(<original>, '')
SQL function?
Solution
OTHER TIPS
You can create an expected predicate in your test and check that the hash codes of the expected and actual predicate are the same.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow