score:0

Assuming you're writing your tests in Scala with MockitoSugar and ScalaTest you want to be using an ArgumentCaptor from the Mockito library. This allows you to capture the value of the client object passed as the parameter to the fundtion sendEmailClientSuspended(client).

See this stackoverflow post for a worked example you can follow. You'll need to specify the package your Client class is in, so something like this...

val capturedClient = ArgumentCaptor.forClass(classOf[com.acme.app.Client])

If your Mailer object doesn't extent a Trait currently, add one so you can mock the Trait and call verify() on it.

If you don't own the code to Mailer, you can move the call out into it's own helper class that you write, and you can then mock the new Trait. Something like this...

trait MailerTrait {
  def sendEmailClientSuspended(client: Client): Unit
}

object MyMailer extends MailerTrait () {
    def sendEmailClientSuspended(client: Client): Unit = {
        Mailer.sendEmailClientSuspended(client)
    }
}

Related Query