I have a class with a primary key that is stored in a database. When creating a new instance of the class it can either be fetched from the HSQLDB database or for items not in the database it inserts everything but the primary key and this is autogenerated and returned to the class to set the id attribute. I then have a getID() method to retrieve this ID.
I am trying to write a JUnit test that checks to ensure the generated ID is what is returned by the getID() method but I have already used 'CALL IDENTITY' query to retrieve the ID inside the constructor and subsequent uses of this return 0. What is the best way of ensuring the generated ID is the same as the id returned by the getID() method?