I have a controller class, inside of which i have a command object. I have a method find() which uses this command object as follows:
class itemController{
//command object
class SearchCommand{
String email
static constraints={
email blank:false,email:true
}
def find = {SearchCommand sc ->
if(!sc.hasErrors()){
----- do something---
}
}
Now, I am writing a test case to test the find method in the controller. But the test case fails at
if(!sc.hasErrors())
as sc is still 'null'. I am not sure how to handle this inner class command object in the test case. The test case that i have written so far is:
class itemControllerTests extends ControllerUnitTestCase {
void testFind(){
def model = controller.find()
assertNotNull(model)
}
}
How do I handle the inner class Command Object in the test case. Do I mock it? I have tried using mockCommandObject(?), but not sure how should i pass the inner class command object to this?