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