-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#202: fixed concurrent modification exception when moving invalid emb…
…edded images to regular attachments list (big thanks to @nedashley!)
- Loading branch information
Showing
2 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/java/org/simplejavamail/converter/internal/mimemessage/MimeMessageParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.simplejavamail.converter.internal.mimemessage; | ||
|
||
import org.junit.Test; | ||
import org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.ParsedMimeMessageComponents; | ||
|
||
import javax.mail.util.ByteArrayDataSource; | ||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.moveInvalidEmbeddedResourcesToAttachments; | ||
|
||
public class MimeMessageParserTest { | ||
@Test | ||
public void testMoveInvalidEmbeddedResourcesToAttachments_NoHtmlNoInvalid() throws IOException { | ||
ParsedMimeMessageComponents parsedComponents = new ParsedMimeMessageComponents(); | ||
parsedComponents.cidMap.put("moo1", new ByteArrayDataSource("moomoo", "text/plain")); | ||
parsedComponents.cidMap.put("moo2", new ByteArrayDataSource("moomoo", "text/plain")); | ||
moveInvalidEmbeddedResourcesToAttachments(parsedComponents); | ||
|
||
assertThat(parsedComponents.cidMap).isEmpty(); | ||
assertThat(parsedComponents.attachmentList).containsOnlyKeys("moo1","moo2"); | ||
} | ||
@Test | ||
public void testMoveInvalidEmbeddedResourcesToAttachments_HtmlButNoInvalid() throws IOException { | ||
ParsedMimeMessageComponents parsedComponents = new ParsedMimeMessageComponents(); | ||
parsedComponents.htmlContent = "blah moo1 blah html"; | ||
parsedComponents.cidMap.put("moo1", new ByteArrayDataSource("moomoo", "text/plain")); | ||
parsedComponents.cidMap.put("moo2", new ByteArrayDataSource("moomoo", "text/plain")); | ||
moveInvalidEmbeddedResourcesToAttachments(parsedComponents); | ||
|
||
assertThat(parsedComponents.cidMap).isEmpty(); | ||
assertThat(parsedComponents.attachmentList).containsOnlyKeys("moo1","moo2"); | ||
} | ||
|
||
@Test | ||
public void testMoveInvalidEmbeddedResourcesToAttachments_Invalid() throws IOException { | ||
ParsedMimeMessageComponents parsedComponents = new ParsedMimeMessageComponents(); | ||
parsedComponents.htmlContent = "blah cid:moo1 blah html"; | ||
parsedComponents.cidMap.put("moo1", new ByteArrayDataSource("moomoo", "text/plain")); | ||
parsedComponents.cidMap.put("moo2", new ByteArrayDataSource("moomoo", "text/plain")); | ||
moveInvalidEmbeddedResourcesToAttachments(parsedComponents); | ||
|
||
assertThat(parsedComponents.cidMap).containsOnlyKeys("moo1"); | ||
assertThat(parsedComponents.attachmentList).containsOnlyKeys("moo2"); | ||
} | ||
} |