Skip to content

Commit

Permalink
minimized diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Loki-Afro committed Dec 13, 2023
1 parent 67c0446 commit 2d6182b
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 88 deletions.
39 changes: 8 additions & 31 deletions src/test/java/org/apache/commons/mail/AbstractEmailTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
*/
package org.apache.commons.mail;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -96,20 +99,17 @@ public abstract class AbstractEmailTest {
private static int fileNameCounter;

@BeforeEach
public void setUpAbstractEmailTest()
{
public void setUpAbstractEmailTest() {
emailOutputDir = new File("target/test-emails");
if (!emailOutputDir.exists()) {
emailOutputDir.mkdirs();
}
}

@AfterEach
public void tearDownEmailTest()
{
//stop the fake email server (if started)
if (this.fakeMailServer != null && !isMailServerStopped(fakeMailServer))
{
public void tearDownEmailTest() {
// stop the fake email server (if started)
if (this.fakeMailServer != null && !isMailServerStopped(fakeMailServer)) {
this.fakeMailServer.stop();
assertTrue(isMailServerStopped(fakeMailServer), "Mail server didn't stop");
}
Expand Down Expand Up @@ -240,29 +240,6 @@ protected WiserMessage validateSend(final Wiser mailServer, final String strSubj
if (!bccAdd.isEmpty()) {
assertTrue(bccAdd.toString().contains(mimeMessage.getHeader("Bcc", null)), "got wrong Bcc: address from mail");
}
assertEquals(strSubject, mimeMessage.getHeader("Subject", null),
"got wrong subject from mail");

//test from address
assertEquals(fromAdd.toString(), mimeMessage.getHeader("From", null),
"got wrong From: address from mail");

//test to address
assertTrue(toAdd.toString().contains(mimeMessage.getHeader("To", null)), "got wrong To: address from mail");

//test cc address
if (!ccAdd.isEmpty())
{
assertTrue(ccAdd.toString().contains(mimeMessage.getHeader("Cc", null)),
"got wrong Cc: address from mail");
}

//test bcc address
if (!bccAdd.isEmpty())
{
assertTrue(bccAdd.toString().contains(mimeMessage.getHeader("Bcc", null)),
"got wrong Bcc: address from mail");
}
} catch (final MessagingException me) {
final IllegalStateException ise = new IllegalStateException("caught MessagingException in validateSend()");
ise.initCause(me);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import org.junit.jupiter.api.Test;


/**
* JUnit test case for DefaultAuthenticator Class.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;


/**
* JUnit test case for EmailAttachment Class.
*
Expand All @@ -33,8 +32,7 @@ public class EmailAttachmentTest extends AbstractEmailTest {
private EmailAttachment attachment;

@BeforeEach
public void setUpAttachmentTest()
{
public void setUpAttachmentTest() {
attachment = new EmailAttachment();
}

Expand Down
4 changes: 1 addition & 3 deletions src/test/java/org/apache/commons/mail/EmailLiveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@
* http://martinfowler.com/articles/mocksArentStubs.html#ClassicalAndMockistTesting).
*/
public class EmailLiveTest extends AbstractEmailTest {

@BeforeEach
public void setUpLiveTest()
{
public void setUpLiveTest() {
// enforce a default charset UTF-8 otherwise non-ASCII attachment names will not work
System.setProperty("mail.mime.charset", "utf-8");

Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/apache/commons/mail/HtmlEmailTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public class HtmlEmailTest extends AbstractEmailTest {
private MockHtmlEmailConcrete email;

@BeforeEach
public void setUpHtmlEmailTest()
{
public void setUpHtmlEmailTest() {
// reusable objects to be used across multiple tests
this.email = new MockHtmlEmailConcrete();
}
Expand Down
12 changes: 0 additions & 12 deletions src/test/java/org/apache/commons/mail/ImageHtmlEmailTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.activation.DataSource;
import javax.mail.internet.MimeMessage;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.mail.mocks.MockImageHtmlEmailConcrete;
import org.apache.commons.mail.resolver.DataSourceClassPathResolver;
import org.apache.commons.mail.resolver.DataSourceCompositeResolver;
import org.apache.commons.mail.resolver.DataSourceUrlResolver;
import org.apache.commons.mail.util.MimeMessageParser;
import org.apache.commons.mail.util.MimeMessageUtils;

import static org.junit.jupiter.api.Assertions.*;

public class ImageHtmlEmailTest extends HtmlEmailTest {
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/org/apache/commons/mail/InvalidAddressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
*/
package org.apache.commons.mail;

import static org.junit.jupiter.api.Assertions.fail;

import org.apache.commons.mail.mocks.MockEmailConcrete;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.fail;

/**
* JUnit test case for invalid Addresses in Email Class
*
Expand All @@ -45,8 +44,7 @@ public class InvalidAddressTest extends AbstractEmailTest {
private MockEmailConcrete email;

@BeforeEach
public void setUpInvalidAddressTest()
{
public void setUpInvalidAddressTest() {
// reusable objects to be used across multiple tests
this.email = new MockEmailConcrete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@
*/
package org.apache.commons.mail;


import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;


import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;


import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;

import javax.mail.internet.InternetAddress;


import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* JUnit test case demonstrating InternetAddress validation.
Expand Down Expand Up @@ -61,14 +56,10 @@ public class InvalidInternetAddressTest extends AbstractEmailTest {
* Setup for a test
*/
@BeforeEach
public void setUpInvalidInternetAddressTest()
{
try
{
public void setUpInvalidInternetAddressTest() {
try {
validateMethod = InternetAddress.class.getMethod("validate");
}
catch (final Exception e)
{
} catch (final Exception e) {
assertEquals(NoSuchMethodException.class, e.getClass(), "Got wrong Exception when looking for validate()");
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/org/apache/commons/mail/MultiPartEmailTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class MultiPartEmailTest extends AbstractEmailTest
{
public class MultiPartEmailTest extends AbstractEmailTest {
/** */
private MockMultiPartEmailConcrete email;
/** File to used to test file attachments (Must be valid) */
private File testFile;

@BeforeEach
public void setUpMultiPartEmailTest() throws Exception
{
public void setUpMultiPartEmailTest() throws Exception {
// reusable objects to be used across multiple tests
this.email = new MockMultiPartEmailConcrete();
testFile = File.createTempFile("testfile", ".txt");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public class SendWithAttachmentsTest extends AbstractEmailTest {
private MockHtmlEmailConcrete email;

@BeforeEach
public void setUpSendWithAttachmentsTest()
{
public void setUpSendWithAttachmentsTest() {
// reusable objects to be used across multiple tests
this.email = new MockHtmlEmailConcrete();
}
Expand Down
7 changes: 2 additions & 5 deletions src/test/java/org/apache/commons/mail/SimpleEmailTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;


/**
* JUnit test case for SimpleEmailTest
*
Expand All @@ -37,8 +36,7 @@ public class SimpleEmailTest extends AbstractEmailTest {
private MockSimpleEmail email;

@BeforeEach
public void setUpSimpleEmailTest()
{
public void setUpSimpleEmailTest() {
// reusable objects to be used across multiple tests
this.email = new MockSimpleEmail();
}
Expand Down Expand Up @@ -98,8 +96,7 @@ public void testSend() throws EmailException, IOException {

@Test
@Disabled
public void testDefaultMimeCharset() throws EmailException, IOException
{
public void testDefaultMimeCharset() throws EmailException, IOException {
/*
* disabling this test as it is dependent on execution order. MimeUtility.getDefaultMIMECharset does some internal caching and if mail.mime.charset is
* not defined, reverts to the default Java charset which is basically the system default file encoding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.commons.mail.DataSourceResolver;
import org.junit.jupiter.api.Test;


/**
* JUnit test case for DataSourceClassPathResolver.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.commons.mail.DataSourceResolver;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URL;

import org.apache.commons.mail.DataSourceResolver;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* JUnit test case for DateSourceResolver.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
*/
package org.apache.commons.mail.resolver;

import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.apache.commons.mail.DataSourceResolver;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;


/**
* JUnit test case for DataSourceUrlResolver.
*
Expand Down

0 comments on commit 2d6182b

Please sign in to comment.