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{
You can use mockCommandObject
class RioController {
class UserCommand{
String email
static constraints = {
email blank: false, email: true
}
}
def load={UserCommand cmd ->
if(cmd.validate()){
flash.message = "Ok"
}
else{
flash.message = "Where is the email?"
}
}
}
import grails.test.mixin.*
import org.junit.*
@TestFor(RioController)
class RioControllerTests {
@Test
void testLoad(){
mockCommandObject RioController.UserCommand
controller.load()
assert flash.message == "Where is the email?"
params.email = "verynew@email.com"
controller.load()
assert flash.message == "Ok"
}
}