[mail] Fix unstable MailBuilderTest (#12471)

When a URL attachment is used a check is done if an InputStream to the URL can be opened to see if it is valid.
Because the openHAB website was used the test would fail when the website has issues:

```
[ERROR]  org.openhab.binding.mail.MailBuilderTest.withURLAttachmentReturnsMultiPartEmail  Time elapsed: 10.391 s  <<< ERROR!
org.apache.commons.mail.EmailException: Invalid URL set:http://www.openhab.org
	at org.openhab.binding.mail.MailBuilderTest.withURLAttachmentReturnsMultiPartEmail(MailBuilderTest.java:77)
Caused by: java.io.IOException: Server returned HTTP response code: 520 for URL: http://www.openhab.org
	at org.openhab.binding.mail.MailBuilderTest.withURLAttachmentReturnsMultiPartEmail(MailBuilderTest.java:77)
```

It will now use a file URL instead so it is no longer depends on a website.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2022-03-13 20:26:32 +01:00 committed by GitHub
parent 43fe75ba2e
commit cb1c1e586e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.nio.file.Path;
import java.util.Map; import java.util.Map;
import javax.mail.MessagingException; import javax.mail.MessagingException;
@ -74,7 +75,8 @@ public class MailBuilderTest {
public void withURLAttachmentReturnsMultiPartEmail() public void withURLAttachmentReturnsMultiPartEmail()
throws AddressException, EmailException, MalformedURLException { throws AddressException, EmailException, MalformedURLException {
MailBuilder builder = new MailBuilder(TEST_EMAIL); MailBuilder builder = new MailBuilder(TEST_EMAIL);
Email mail = builder.withText("boo").withURLAttachment("http://www.openhab.org").build(); String url = Path.of("src/test/resources/attachment.txt").toUri().toURL().toString();
Email mail = builder.withText("boo").withURLAttachment(url).build();
assertThat(mail, instanceOf(MultiPartEmail.class)); assertThat(mail, instanceOf(MultiPartEmail.class));
} }

View File

@ -0,0 +1 @@
Lorem ipsum dolor sit amet, ut sed dolores repudiandae, no sit inani euripidis.