grails - Testing a command object in a service class method that has the command object as part of the method signature -


i have grails service class i'm trying write spock test for. signature of method follows:

def builderrorjsonarray(addressinfocommand addressinfocmd, paymentinfocommand paymentinfocmd, boolean trsrequest = false)  

when populate addressinfocommand , paymentinfocommand command object invalid data in test , call validate on it, it's not returning errors , i'm not sure why. guess it's way i'm mocking command objects in test (via mockforconstraintstests). here part of test populates paymentinfocommand:

setup:     service.messagesource = [getmessage: { errors, locale -> return "message" }]     mockforconstraintstests(addressinfocommand)     mockforconstraintstests(paymentinfocommand)      paymentinfocommand paymentinfocommand = new paymentinfocommand()     def payment = new payment()     payment.paymenttype = ""     payment.cardaccountnumber = ""     payment.cardexpirationdate = ""     payment.cardsecuritycode = ""     paymentinfocommand.setpaymentinfocommand(payment)     paymentinfocommand.validate()  

and here part of paymentinfocommand:

class paymentinfocommand {     string cardtype = ""     string cardaccountnumber = ""     string cardexpirationdateyear = ""     string cardexpirationdatemonth = ""     string cardsecuritycode = ""     def messagesource      static constraints = {         cardaccountnumber(nullable: false, blank: false, maxsize: 19, creditcard: true)          cardsecuritycode(nullable: false, blank: false, minsize: 3, maxsize: 4, validator: {val, obj ->             if (!stringutils.isnumeric(obj.cardsecuritycode)) {                 return "paymentinfocommand.cardsecuritycode.notanumber.error"             }         })     } } 

can see i'm doing wrong?


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -