Dear All,
I want to mock a ResultSet. Seriously. I'm refactoring one big complicated piece of code which is parsing data from ResultSet, and I want my code to behave identically. So, I need to write a unit test for the piece being refactored to be able to test this.
After googling I came up with 2 ideas:
- Use EasyMock, write looooong mocking sequence. VERY BAD solution: hard to add initial data, hard to change data, big test debugging promices.
- Use Apache Derby or HSQLDB to create in-memory DB, fill it from file or String array, query with some magical InMemoryDBUtils.query(sql). Then use that ResultSet. Unfortunately, I did not find any magical InMemoryDBUtils to write the test fast :-). IBM article "Isolated unit testing of persistence with Derby" seems just fine about what I need, though...
Second approach looks somewhat easier and much more supportable.
What would you advice for creating such a mock? (despite doctors, of course :-)? Am I missing an eyebrow some silver bullet? Possibly, DBUnit is the tool for this?
Thank you all for your time and answers.
WBR, DiaWorD