| 1 | package fr.sii.ogham.email.sendgrid.v2.sender.impl.sendgrid.client; | |
| 2 | ||
| 3 | import java.io.IOException; | |
| 4 | ||
| 5 | import org.slf4j.Logger; | |
| 6 | import org.slf4j.LoggerFactory; | |
| 7 | ||
| 8 | import com.sendgrid.SendGrid; | |
| 9 | import com.sendgrid.SendGrid.Email; | |
| 10 | import com.sendgrid.SendGridException; | |
| 11 | ||
| 12 | /** | |
| 13 | * Facade wrapping the {@link SendGrid} object. | |
| 14 | */ | |
| 15 | public final class DelegateSendGridClient implements SendGridClient { | |
| 16 | ||
| 17 | private static final Logger LOG = LoggerFactory.getLogger(DelegateSendGridClient.class); | |
| 18 | ||
| 19 | private SendGrid delegate; | |
| 20 | ||
| 21 | /** | |
| 22 | * Constructor. | |
| 23 | * | |
| 24 | * @param delegate | |
| 25 | * the entry point to the SendGrid library | |
| 26 | * @throws IllegalArgumentException | |
| 27 | * if provided delegate is null | |
| 28 | */ | |
| 29 | public DelegateSendGridClient(final SendGrid delegate) { | |
| 30 |
3
1. <init> : negated conditional → NO_COVERAGE 2. <init> : negated conditional → KILLED 3. <init> : negated conditional → KILLED |
if (delegate == null) { |
| 31 | throw new IllegalArgumentException("[delegate] cannot be null"); | |
| 32 | } | |
| 33 | ||
| 34 | this.delegate = delegate; | |
| 35 | } | |
| 36 | ||
| 37 | @Override | |
| 38 | public void send(final Email email) throws SendGridException { | |
| 39 |
2
1. send : negated conditional → NO_COVERAGE 2. send : negated conditional → KILLED |
if (email == null) { |
| 40 | throw new IllegalArgumentException("[email] cannot be null"); | |
| 41 | } | |
| 42 | ||
| 43 | LOG.debug("Sending to SendGrid client: FROM {}<{}>", email.getFromName(), email.getFrom()); | |
| 44 | LOG.debug("Sending to SendGrid client: TO {} (as {})", email.getTos(), email.getToNames()); | |
| 45 | LOG.debug("Sending to SendGrid client: SUBJECT {}", email.getSubject()); | |
| 46 | LOG.debug("Sending to SendGrid client: TEXT CONTENT {}", email.getText()); | |
| 47 | LOG.debug("Sending to SendGrid client: HTML CONTENT {}", email.getHtml()); | |
| 48 | ||
| 49 | final SendGrid.Response response = delegate.send(email); | |
| 50 | ||
| 51 |
2
1. send : negated conditional → NO_COVERAGE 2. send : negated conditional → KILLED |
if (response.getStatus()) { |
| 52 | LOG.debug("Response from SendGrid client: ({}) {}", response.getCode(), response.getMessage()); | |
| 53 | } else { | |
| 54 | throw new SendGridException(new IOException("Sending to SendGrid failed: (" + response.getCode() + ") " + response.getMessage())); | |
| 55 | } | |
| 56 | } | |
| 57 | } | |
Mutations | ||
| 30 |
1.1 2.2 3.3 |
|
| 39 |
1.1 2.2 |
|
| 51 |
1.1 2.2 |