| 1 | package fr.sii.ogham.email.sendgrid.v2.sender.impl.sendgrid.handler; | |
| 2 | ||
| 3 | import com.sendgrid.SendGrid; | |
| 4 | ||
| 5 | import fr.sii.ogham.core.message.content.Content; | |
| 6 | import fr.sii.ogham.core.message.content.MultiContent; | |
| 7 | import fr.sii.ogham.email.exception.handler.ContentHandlerException; | |
| 8 | import fr.sii.ogham.email.message.Email; | |
| 9 | ||
| 10 | /** | |
| 11 | * Content handler for {@link MultiContent} instances. All it does is, for each | |
| 12 | * content contained within the instance, it delegates processing to an injected | |
| 13 | * content handler. | |
| 14 | * | |
| 15 | */ | |
| 16 | public final class MultiContentHandler implements SendGridContentHandler { | |
| 17 | ||
| 18 | private final SendGridContentHandler delegate; | |
| 19 | ||
| 20 | /** | |
| 21 | * Constructor. | |
| 22 | * | |
| 23 | * @param delegate | |
| 24 | * the underlying content handler to delegate processing of each | |
| 25 | * of the contents contained within a {@link MultiContent} | |
| 26 | * instance | |
| 27 | */ | |
| 28 | public MultiContentHandler(final SendGridContentHandler delegate) { | |
| 29 |
3
1. <init> : negated conditional → NO_COVERAGE 2. <init> : negated conditional → KILLED 3. <init> : negated conditional → KILLED |
if (delegate == null) { |
| 30 | throw new IllegalArgumentException("[delegate] cannot be null"); | |
| 31 | } | |
| 32 | ||
| 33 | this.delegate = delegate; | |
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * Reads the content and adds it into the email. This method is expected to | |
| 38 | * update the content of the {@code email} parameter. | |
| 39 | * | |
| 40 | * While the method signature accepts any {@link Content} instance as | |
| 41 | * parameter, the method will fail if anything other than a | |
| 42 | * {@link MultiContent} is provided. | |
| 43 | * | |
| 44 | * @param email | |
| 45 | * the email to put the content in | |
| 46 | * @param content | |
| 47 | * the unprocessed content | |
| 48 | * @throws ContentHandlerException | |
| 49 | * the handler is unable to add the content to the email | |
| 50 | * @throws IllegalArgumentException | |
| 51 | * the content provided is not of the right type | |
| 52 | */ | |
| 53 | @Override | |
| 54 | public void setContent(final Email original, final SendGrid.Email email, final Content content) throws ContentHandlerException { | |
| 55 |
2
1. setContent : negated conditional → NO_COVERAGE 2. setContent : negated conditional → KILLED |
if (email == null) { |
| 56 | throw new IllegalArgumentException("[email] cannot be null"); | |
| 57 | } | |
| 58 |
2
1. setContent : negated conditional → NO_COVERAGE 2. setContent : negated conditional → KILLED |
if (content == null) { |
| 59 | throw new IllegalArgumentException("[content] cannot be null"); | |
| 60 | } | |
| 61 | ||
| 62 |
2
1. setContent : negated conditional → NO_COVERAGE 2. setContent : negated conditional → KILLED |
if (content instanceof MultiContent) { |
| 63 | for (Content subContent : ((MultiContent) content).getContents()) { | |
| 64 |
2
1. setContent : removed call to fr/sii/ogham/email/sendgrid/v2/sender/impl/sendgrid/handler/SendGridContentHandler::setContent → NO_COVERAGE 2. setContent : removed call to fr/sii/ogham/email/sendgrid/v2/sender/impl/sendgrid/handler/SendGridContentHandler::setContent → KILLED |
delegate.setContent(original, email, subContent); |
| 65 | } | |
| 66 | } else { | |
| 67 | throw new IllegalArgumentException("This instance can only work with MultiContent instances, but was passed " + content.getClass().getSimpleName()); | |
| 68 | } | |
| 69 | } | |
| 70 | ||
| 71 | } | |
Mutations | ||
| 29 |
1.1 2.2 3.3 |
|
| 55 |
1.1 2.2 |
|
| 58 |
1.1 2.2 |
|
| 62 |
1.1 2.2 |
|
| 64 |
1.1 2.2 |