georgef wrote:
Since Criteria is an interface you could probably mock it out and test the values that are being set in it.
Sure I can. The problem is that the Criterion's (which Criteria is build on) knows only how to generate its part of sql statement, but knows nothing about model beans. In other words Criterion does not have such method as 'match(Object)'. Taking this into account it appears that it would be necessary to analyze the class of the specific criterion and perform matching depending on this class. This is not very hard but it's not trivial anyway. And I hoped someone already did it, so I would not reinvent the wheel.
georgef wrote:
Alternatively you could also test your DAOs against an in memory database like HSQLDB. See,
http://www.theserverside.com/tt/articles/article.tss?l=UnitTestingPersonally I prefer testing against my target DB as I trust my test more.
As for HSQLDB (or another in-memory database), I looked at this approach and saw several drawbacks in it. We have legacy database, we forced to create mapping that is bound to Oracle. HSQLDB and Oracle have rather different dialects and we cannot use the same mapping for Oracle and for HSQLDB as well. And maintenaning two separate mappings, one for Oracle and one for HSQLDB, looks like overhead.
Using Oracle database for testing requires extra setup and takes long time to run. That's why I looked up solution that does not require database at all.