Utility for Mocking ResultSets
//Create a Map that can be used as part of a result set
//maxCount is the number of rows to be returned
Map mockResultSet(int maxCount) {
int count = 0;
boolean closed = false;
return [
getCount : { -> count } ,
next : { -> count++ < maxCount }, //returns false after
close : { -> assertFalse(closed); closed = true; },
isClosed : { return closed; }
];
}
...
Map pfIDsResultSet = mockResultSet(2);
Closure pfIDsGetString = {
String name
-> assertEquals("value", name);
return "id"+pfIDsResultSet.getCount();
}
pfIDsResultSet.put('getString', pfIDsGetString);
Next