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

  1. The expression evaluates to "" when the original expression was null
  2. 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?

Was it helpful?

Solution

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.

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
scroll top