| 1 | package fr.sii.ogham.testing.assertion.email; | |
| 2 | ||
| 3 | import static fr.sii.ogham.testing.assertion.util.EmailUtils.ATTACHMENT_DISPOSITION; | |
| 4 | ||
| 5 | import java.io.File; | |
| 6 | import java.io.IOException; | |
| 7 | import java.io.InputStream; | |
| 8 | import java.util.regex.Pattern; | |
| 9 | ||
| 10 | import org.apache.commons.io.IOUtils; | |
| 11 | ||
| 12 | /** | |
| 13 | * Class used in tests for ensuring that the attachment is respected. It | |
| 14 | * provides the following information: | |
| 15 | * <ul> | |
| 16 | * <li>The expected name of the attachment</li> | |
| 17 | * <li>The expected Mime type of the attachment</li> | |
| 18 | * <li>The expected content of the attachment</li> | |
| 19 | * <li>The expected description of the attachment</li> | |
| 20 | * <li>The expected disposition of the attachment</li> | |
| 21 | * </ul> | |
| 22 | * | |
| 23 | * @author Aurélien Baudet | |
| 24 | */ | |
| 25 | public class ExpectedAttachment { | |
| 26 | ||
| 27 | /** | |
| 28 | * The name of the attachment | |
| 29 | */ | |
| 30 | private String name; | |
| 31 | ||
| 32 | /** | |
| 33 | * The mimetype pattern for the attachment | |
| 34 | */ | |
| 35 | private Pattern mimetype; | |
| 36 | ||
| 37 | /** | |
| 38 | * The description of the attachment | |
| 39 | */ | |
| 40 | private String description; | |
| 41 | ||
| 42 | /** | |
| 43 | * The disposition of the attachment | |
| 44 | */ | |
| 45 | private String disposition; | |
| 46 | ||
| 47 | /** | |
| 48 | * The content of the attachment | |
| 49 | */ | |
| 50 | private byte[] content; | |
| 51 | ||
| 52 | public ExpectedAttachment(String name, Pattern mimetype, byte[] content, String description, String disposition) { | |
| 53 | super(); | |
| 54 | this.name = name; | |
| 55 | this.mimetype = mimetype; | |
| 56 | this.description = description; | |
| 57 | this.disposition = disposition; | |
| 58 | this.content = content; | |
| 59 | } | |
| 60 | ||
| 61 | public ExpectedAttachment(String name, Pattern mimetype, byte[] content, String description) { | |
| 62 | this(name, mimetype, content, description, ATTACHMENT_DISPOSITION); | |
| 63 | } | |
| 64 | ||
| 65 | public ExpectedAttachment(String name, Pattern mimetype, byte[] content) { | |
| 66 | this(name, mimetype, content, null); | |
| 67 | } | |
| 68 | ||
| 69 | public ExpectedAttachment(String name, Pattern mimetype, InputStream content, String description, String disposition) throws IOException { | |
| 70 | this(name, mimetype, IOUtils.toByteArray(content), description, disposition); | |
| 71 | } | |
| 72 | ||
| 73 | public ExpectedAttachment(String name, Pattern mimetype, InputStream content, String description) throws IOException { | |
| 74 | this(name, mimetype, content, description, ATTACHMENT_DISPOSITION); | |
| 75 | } | |
| 76 | ||
| 77 | public ExpectedAttachment(String name, Pattern mimetype, InputStream content) throws IOException { | |
| 78 | this(name, mimetype, content, null); | |
| 79 | } | |
| 80 | ||
| 81 | public ExpectedAttachment(String expectedContentPath, Pattern mimetype, String description, String disposition) throws IOException { | |
| 82 | this(new File(expectedContentPath).getName(), mimetype, ExpectedAttachment.class.getResourceAsStream(expectedContentPath), description, disposition); | |
| 83 | } | |
| 84 | ||
| 85 | public ExpectedAttachment(String expectedContentPath, Pattern mimetype, String description) throws IOException { | |
| 86 | this(expectedContentPath, mimetype, description, ATTACHMENT_DISPOSITION); | |
| 87 | } | |
| 88 | ||
| 89 | public ExpectedAttachment(String expectedContentPath, Pattern mimetype) throws IOException { | |
| 90 | this(expectedContentPath, mimetype, (String) null); | |
| 91 | } | |
| 92 | ||
| 93 | public ExpectedAttachment(String name, String mimetype, byte[] content, String description, String disposition) { | |
| 94 | this(name, Pattern.compile(mimetype), content, description, disposition); | |
| 95 | } | |
| 96 | ||
| 97 | public ExpectedAttachment(String name, String mimetype, byte[] content, String description) { | |
| 98 | this(name, mimetype, content, description, ATTACHMENT_DISPOSITION); | |
| 99 | } | |
| 100 | ||
| 101 | public ExpectedAttachment(String name, String mimetype, byte[] content) { | |
| 102 | this(name, mimetype, content, null); | |
| 103 | } | |
| 104 | ||
| 105 | public ExpectedAttachment(String name, String mimetype, InputStream content, String description, String disposition) throws IOException { | |
| 106 | this(name, mimetype, IOUtils.toByteArray(content), description, disposition); | |
| 107 | } | |
| 108 | ||
| 109 | public ExpectedAttachment(String name, String mimetype, InputStream content, String description) throws IOException { | |
| 110 | this(name, mimetype, content, description, ATTACHMENT_DISPOSITION); | |
| 111 | } | |
| 112 | ||
| 113 | public ExpectedAttachment(String name, String mimetype, InputStream content) throws IOException { | |
| 114 | this(name, mimetype, content, null); | |
| 115 | } | |
| 116 | ||
| 117 | public ExpectedAttachment(String expectedContentPath, String mimetype, String description, String disposition) throws IOException { | |
| 118 | this(new File(expectedContentPath).getName(), mimetype, ExpectedAttachment.class.getResourceAsStream(expectedContentPath), description, disposition); | |
| 119 | } | |
| 120 | ||
| 121 | public ExpectedAttachment(String expectedContentPath, String mimetype, String description) throws IOException { | |
| 122 | this(expectedContentPath, mimetype, description, ATTACHMENT_DISPOSITION); | |
| 123 | } | |
| 124 | ||
| 125 | public ExpectedAttachment(String expectedContentPath, String mimetype) throws IOException { | |
| 126 | this(expectedContentPath, mimetype, (String) null); | |
| 127 | } | |
| 128 | ||
| 129 | public String getName() { | |
| 130 |
2
1. getName : replaced return value with "" for fr/sii/ogham/testing/assertion/email/ExpectedAttachment::getName → NO_COVERAGE 2. getName : replaced return value with "" for fr/sii/ogham/testing/assertion/email/ExpectedAttachment::getName → KILLED |
return name; |
| 131 | } | |
| 132 | ||
| 133 | public Pattern getMimetype() { | |
| 134 |
2
1. getMimetype : replaced return value with null for fr/sii/ogham/testing/assertion/email/ExpectedAttachment::getMimetype → NO_COVERAGE 2. getMimetype : replaced return value with null for fr/sii/ogham/testing/assertion/email/ExpectedAttachment::getMimetype → KILLED |
return mimetype; |
| 135 | } | |
| 136 | ||
| 137 | public String getDescription() { | |
| 138 |
2
1. getDescription : replaced return value with "" for fr/sii/ogham/testing/assertion/email/ExpectedAttachment::getDescription → NO_COVERAGE 2. getDescription : replaced return value with "" for fr/sii/ogham/testing/assertion/email/ExpectedAttachment::getDescription → KILLED |
return description; |
| 139 | } | |
| 140 | ||
| 141 | public String getDisposition() { | |
| 142 |
2
1. getDisposition : replaced return value with "" for fr/sii/ogham/testing/assertion/email/ExpectedAttachment::getDisposition → NO_COVERAGE 2. getDisposition : replaced return value with "" for fr/sii/ogham/testing/assertion/email/ExpectedAttachment::getDisposition → KILLED |
return disposition; |
| 143 | } | |
| 144 | ||
| 145 | public byte[] getContent() { | |
| 146 |
2
1. getContent : replaced return value with null for fr/sii/ogham/testing/assertion/email/ExpectedAttachment::getContent → NO_COVERAGE 2. getContent : replaced return value with null for fr/sii/ogham/testing/assertion/email/ExpectedAttachment::getContent → KILLED |
return content; |
| 147 | } | |
| 148 | ||
| 149 | } | |
Mutations | ||
| 130 |
1.1 2.2 |
|
| 134 |
1.1 2.2 |
|
| 138 |
1.1 2.2 |
|
| 142 |
1.1 2.2 |
|
| 146 |
1.1 2.2 |