From 328981ce912993a6b4dd1d5a30153b80a1632a60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 17 Mar 2014 21:50:33 +0100 Subject: [PATCH] Add test for email action. --- .../rhynodge/actions/EmailActionTest.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/test/java/net/pterodactylus/rhynodge/actions/EmailActionTest.java diff --git a/src/test/java/net/pterodactylus/rhynodge/actions/EmailActionTest.java b/src/test/java/net/pterodactylus/rhynodge/actions/EmailActionTest.java new file mode 100644 index 0000000..960a235 --- /dev/null +++ b/src/test/java/net/pterodactylus/rhynodge/actions/EmailActionTest.java @@ -0,0 +1,51 @@ +package net.pterodactylus.rhynodge.actions; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import javax.mail.Address; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Transport; + +import net.pterodactylus.rhynodge.output.DefaultOutput; +import net.pterodactylus.rhynodge.output.Output; + +import org.junit.Test; + +/** + * Unit test for {@link EmailAction}. + * + * @author David ‘Bombe’ Roden + */ +public class EmailActionTest { + + private final Transport transport = mock(Transport.class); + private final String sender = "sender@sender.de"; + private final String recipient = "recipient@recipient.de"; + private final EmailAction emailAction = new EmailAction(transport, sender, recipient); + private final Output output = new DefaultOutput("Action triggered!").addText("text/plain", "Plain Text.").addText("text/html", "

HTML Text.

"); + + @Test + public void canCreateActionWithNormalConstructor() { + new EmailAction("hostname", "sender", "recipient"); + } + + @Test + public void emailIsGeneratedCorrectly() throws MessagingException { + emailAction.execute(output); + verify(transport).sendMessage(any(Message.class), any(Address[].class)); + } + + @Test + public void exceptionWhenSendingIsSwallowed() throws MessagingException { + doThrow(MessagingException.class).doNothing().when(transport).sendMessage(any(Message.class), any(Address[].class)); + emailAction.execute(output); + emailAction.execute(output); + verify(transport, times(2)).sendMessage(any(Message.class), any(Address[].class)); + } + +} -- 2.7.4