I'm creating a unit test for my program. I have a void method which is taking five arguments, then converting those arguments into a closure and passing it to another service to be turned into an Email and sent. The only thing I care about is the body of this email, which is stored in one of the arguments passed into this function. Is it possible to verify this argument without changing the design of my program?
I've considered using Spock style mocks, but I can't determine if I can actually mock/stub out methods in my spec-tested class or if I can only mock out dependencies.
A simplified example
Class myTestService
{
def outsideService
private void sendEmail (User source, String subj, String body, List to, List attachments){
outsideService.sendMail{
//blah blah
subject subj
html wrapWithDefault(body) //wrapWithDefault is a big styling document also in this function
//blah blah
}
}
int send(GrailsParameterMap params, HttpServletRequest request) {
//Parse out attachments from request and body/subject/addressee from params
//little bit of business logic to ensure that we can send emails in our system
sendEmail(source,
subject,
"$body <br /><br /> important extra information",
sendTo,
attachments)
//Send another email to the source as a receipt
sendEmail(source,
subject,
"$body extra junk $receiptBody",
source,
attachments)
}
}
I need to find out if the receipt is properly adding receiptBody. Given that I'm sending a closure out to outsideService, it's hard to just rip variables out of that, so I'm at a bit of a loss.
Aucun commentaire:
Enregistrer un commentaire