I am trying to do a unit test on the list action of a controller. Here is the code for testing it :
void testListAction()
{
ac = new AddressesController();
def org = new Organizations(viewAllPost: true);
mockForConstraintsTests(Addresses);
def a = new Addresses(firstLine:'A', secondLine:'B', thirdLine:'C', luCountry:UnitedStates, zipCode:'12345', luState:Florida, city:'jag');
assertTrue(a.validate());
mockSession['currentUserOrganizationId'] = org;
mockDomain(Addresses, [
new Addresses(firstLine:'A1', secondLine:'B', thirdLine:'C', luCountry:UnitedStates, zipCode:'12345', luState:Florida, city:'jag'),
new Addresses(firstLine:'A2', secondLine:'B2', thirdLine:'C2', luCountry:UnitedStates, zipCode:'12344', luState:Florida, city:'jag2')
]);
def model = ac.list();
assertEquals(2, model.postInstanceList.size());
}
But No matter how I tried I am always getting back the same result that the model.postInstanceList is null and I can not invoke the size method on it. What am I doing wrong here ?
void testListAction()
{
ac = new AddressesController();
def org = new Organizations(viewAllPost: true);
mockForConstraintsTests(Addresses);
def a = new Addresses(firstLine:'A', secondLine:'B', thirdLine:'C', luCountry:UnitedStates, zipCode:'12345', luState:Florida, city:'jag');
assertTrue(a.validate());
mockSession['currentUserOrganizationId'] = org;
mockDomain(Addresses, [
new Addresses(firstLine:'A1', secondLine:'B', thirdLine:'C', luCountry:UnitedStates, zipCode:'12345', luState:Florida, city:'jag'),
new Addresses(firstLine:'A2', secondLine:'B2', thirdLine:'C2', luCountry:UnitedStates, zipCode:'12344', luState:Florida, city:'jag2')
]);
def model = ac.list();
assertEquals(2, model.postInstanceList.size());
}
But No matter how I tried I am always getting back the same result that the model.postInstanceList is null and I can not invoke the size method on it. What am I doing wrong here ?