#655 Encapsulate mail service

- Change SendMailSSL to be injected into classes and created regardless of settings
- Various minor cleanups (remove accidentally committed test, add more precise logging statement)
This commit is contained in:
ljacqu
2016-07-02 20:56:53 +02:00
parent d2556b8a04
commit 9a5c432509
9 changed files with 80 additions and 72 deletions
@@ -2,6 +2,7 @@ package fr.xephi.authme.command.executable.register;
import fr.xephi.authme.TestHelper;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.mail.SendMailSSL;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.HashAlgorithm;
@@ -49,6 +50,8 @@ public class RegisterCommandTest {
@Mock
private Management management;
@Mock
private SendMailSSL sendMailSsl;
@BeforeClass
public static void setup() {
@@ -72,7 +75,7 @@ public class RegisterCommandTest {
// then
verify(sender).sendMessage(argThat(containsString("Player only!")));
verifyZeroInteractions(management);
verifyZeroInteractions(management, sendMailSsl);
}
@Test
@@ -86,6 +89,7 @@ public class RegisterCommandTest {
// then
verify(management).performRegister(player, "", "", true);
verifyZeroInteractions(sendMailSsl);
}
@Test
@@ -98,7 +102,7 @@ public class RegisterCommandTest {
// then
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
verifyZeroInteractions(management);
verifyZeroInteractions(management, sendMailSsl);
}
@Test
@@ -112,7 +116,7 @@ public class RegisterCommandTest {
// then
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
verifyZeroInteractions(management);
verifyZeroInteractions(management, sendMailSsl);
}
@Test
@@ -127,7 +131,7 @@ public class RegisterCommandTest {
// then
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
verifyZeroInteractions(management);
verifyZeroInteractions(management, sendMailSsl);
}
@Test
@@ -135,14 +139,15 @@ public class RegisterCommandTest {
// given
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(false);
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("");
given(sendMailSsl.hasAllInformation()).willReturn(false);
Player player = mock(Player.class);
// when
command.executeCommand(player, Collections.singletonList("myMail@example.tld"));
// then
verify(player).sendMessage(argThat(containsString("no email address")));
verify(player).sendMessage(argThat(containsString("not all required settings are set for sending emails")));
verify(sendMailSsl).hasAllInformation();
verifyZeroInteractions(management);
}
@@ -155,6 +160,7 @@ public class RegisterCommandTest {
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
given(sendMailSsl.hasAllInformation()).willReturn(true);
Player player = mock(Player.class);
// when
@@ -175,6 +181,7 @@ public class RegisterCommandTest {
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
given(sendMailSsl.hasAllInformation()).willReturn(true);
Player player = mock(Player.class);
// when
@@ -182,6 +189,7 @@ public class RegisterCommandTest {
// then
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
verify(sendMailSsl).hasAllInformation();
verifyZeroInteractions(management);
}
@@ -196,6 +204,7 @@ public class RegisterCommandTest {
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
given(sendMailSsl.hasAllInformation()).willReturn(true);
Player player = mock(Player.class);
// when
@@ -203,6 +212,7 @@ public class RegisterCommandTest {
// then
verify(commandService).validateEmail(playerMail);
verify(sendMailSsl).hasAllInformation();
verify(management).performRegister(eq(player), argThat(stringWithLength(passLength)), eq(playerMail), eq(true));
}
@@ -217,7 +227,7 @@ public class RegisterCommandTest {
// then
verify(commandService).send(player, MessageKey.PASSWORD_MATCH_ERROR);
verifyZeroInteractions(management);
verifyZeroInteractions(management, sendMailSsl);
}
@Test