I'm trying to unit test my DAO which uses the Criteria API. The Criteria object I have has a number of expressions and returns a unique result.
The problem I have is that when I use Jmock to create an expectation I have to create one for the criteria.uniqueResult()
command and I have to set a return type. The return type is a custom type which has been created by Hibernate as a mapping file to my database table. When I run the test however I get a ClassCastException
because in the working method the return type is an Object
which I cast to my custom Hibernate type object. For some reason I cant get Jmock to understand this
eg.
Inside the method I want to test I have the following;
MyCustomObject customObject = (MyCustomObject)criteria.uniqueResult();
and then in my expectation I have;
oneOf(criteria).uniqueResult();will(returnValue(new MyCustomObject()))
any ideas how I can test this?