testing the mailer

The function under test

Possible inputs

  • The data in the SendgridRequest can be correct or incorrect

  • if the contents are not valid - returns a Response object with the appropriate Http status code

  • If the contents are valid

    • creates a SendGrid API Request object from our SendgridRequest request, and

    • calls the SendGrid API which returns a Response object

Possible outputs

  • The SendGrid API normally returns a SendGrid Response object

  • The Response will contain an http status code

  • We need to handle any http status so that later we can handle failure, retry, and circuit breaker cases

  • We need to handle any Runtime exception

For testing we need to cover three boundaries

  1. Verification of the input SendgridRequest object

  2. Creation of a correct SendGrid API request based on the SendgridRequest

  3. Calling the API and handling any response

Example - Verification of the input SendgridRequest object

Since we want to test many scenarios, we'll use a parameterized test and pass several scenarios into the same test.

We don't want to call the real SendGrid API, so we'll mock the api() method that calls it. But we do want to verify what we sent to the API, so we'll use a Captor to see the Request that was passed into our mocked api()

We then call our test example, which:

Last updated

Was this helpful?