Merge CommandService and ProcessService to CommonService
- Replace CommandService and ProcessService with CommonService: a service that offers our typical needs to work with settings, messages and permissions - Remove validation methods from CommonService: inject ValidationService directly. Validation methods are not used very frequently and therefore don't belong in CommonService. Their presence was a relict from our architecture before injection was used.
This commit is contained in:
@@ -1,130 +0,0 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import com.github.authme.configme.properties.Property;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Test for {@link CommandService}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CommandServiceTest {
|
||||
|
||||
@InjectMocks
|
||||
private CommandService commandService;
|
||||
@Mock
|
||||
private Messages messages;
|
||||
@Mock
|
||||
private Settings settings;
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@Test
|
||||
public void shouldSendMessage() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
commandService.send(sender, MessageKey.INVALID_EMAIL);
|
||||
|
||||
// then
|
||||
verify(messages).send(sender, MessageKey.INVALID_EMAIL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendMessageWithReplacements() {
|
||||
// given
|
||||
CommandSender sender = mock(Player.class);
|
||||
|
||||
// when
|
||||
commandService.send(sender, MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE, "10");
|
||||
|
||||
// then
|
||||
verify(messages).send(sender, MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE, "10");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveMessage() {
|
||||
// given
|
||||
MessageKey key = MessageKey.USAGE_CAPTCHA;
|
||||
String[] givenMessages = new String[]{"Lorem ipsum...", "Test line test"};
|
||||
given(messages.retrieve(key)).willReturn(givenMessages);
|
||||
|
||||
// when
|
||||
String[] result = commandService.retrieveMessage(key);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(givenMessages));
|
||||
verify(messages).retrieve(key);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveProperty() {
|
||||
// given
|
||||
Property<Integer> property = SecuritySettings.CAPTCHA_LENGTH;
|
||||
given(settings.getProperty(property)).willReturn(7);
|
||||
|
||||
// when
|
||||
int result = commandService.getProperty(property);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(7));
|
||||
verify(settings).getProperty(property);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSettings() {
|
||||
// given/when
|
||||
Settings result = commandService.getSettings();
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(settings));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldValidateEmail() {
|
||||
// given
|
||||
String email = "test@example.tld";
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = commandService.validateEmail(email);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
verify(validationService).validateEmail(email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCheckIfEmailCanBeUsed() {
|
||||
// given
|
||||
String email = "mail@example.com";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(validationService.isEmailFreeForRegistration(email, sender))
|
||||
.willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = commandService.isEmailFreeForRegistration(email, sender);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -36,7 +36,7 @@ public class AccountsCommandTest {
|
||||
@InjectMocks
|
||||
private AccountsCommand command;
|
||||
@Mock
|
||||
private CommandService service;
|
||||
private CommonService service;
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
@Mock
|
||||
|
||||
+2
-2
@@ -1,7 +1,6 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
@@ -9,6 +8,7 @@ import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -39,7 +39,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
private ChangePasswordAdminCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
private CommonService service;
|
||||
|
||||
@Mock
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
@@ -2,10 +2,10 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import ch.jalu.injector.Injector;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.converter.Converter;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -42,7 +42,7 @@ public class ConverterCommandTest {
|
||||
private ConverterCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -32,7 +32,7 @@ public class GetEmailCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
private CommonService service;
|
||||
|
||||
@Test
|
||||
public void shouldReportUnknownUser() {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -39,7 +39,7 @@ public class LastLoginCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
private CommonService service;
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -33,7 +33,7 @@ public class PurgeLastPositionCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
private CommonService service;
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
+3
-3
@@ -1,7 +1,6 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
@@ -9,6 +8,7 @@ import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -51,7 +51,7 @@ public class RegisterAdminCommandTest {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
@@ -164,7 +164,7 @@ public class RegisterAdminCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
given(bukkitService.getPlayerExact(user)).willReturn(player);
|
||||
String kickForAdminRegister = "Admin registered you -- log in again";
|
||||
given(commandService.retrieveSingle(MessageKey.KICK_FOR_ADMIN_REGISTER)).willReturn(kickForAdminRegister);
|
||||
given(commandService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER)).willReturn(kickForAdminRegister);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
|
||||
@@ -3,13 +3,13 @@ package fr.xephi.authme.command.executable.authme;
|
||||
import ch.jalu.injector.Injector;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.output.LogLevel;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
@@ -59,7 +59,7 @@ public class ReloadCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -37,27 +38,30 @@ public class SetEmailCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidMail() {
|
||||
// given
|
||||
String user = "somebody";
|
||||
String email = "some.test@example.org";
|
||||
given(commandService.validateEmail(email)).willReturn(false);
|
||||
given(validationService.validateEmail(email)).willReturn(false);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, email));
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(commandService).send(sender, MessageKey.INVALID_EMAIL);
|
||||
verifyZeroInteractions(dataSource);
|
||||
}
|
||||
@@ -67,7 +71,7 @@ public class SetEmailCommandTest {
|
||||
// given
|
||||
String user = "nonexistent";
|
||||
String email = "mail@example.com";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
given(dataSource.getAuth(user)).willReturn(null);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
@@ -76,7 +80,7 @@ public class SetEmailCommandTest {
|
||||
runOptionallyAsyncTask(bukkitService);
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(dataSource).getAuth(user);
|
||||
verify(commandService).send(sender, MessageKey.UNKNOWN_USER);
|
||||
verifyNoMoreInteractions(dataSource);
|
||||
@@ -87,20 +91,20 @@ public class SetEmailCommandTest {
|
||||
// given
|
||||
String user = "someone";
|
||||
String email = "mail@example.com";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(dataSource.getAuth(user)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(commandService.isEmailFreeForRegistration(email, sender)).willReturn(false);
|
||||
given(validationService.isEmailFreeForRegistration(email, sender)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, email));
|
||||
runOptionallyAsyncTask(bukkitService);
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(dataSource).getAuth(user);
|
||||
verify(commandService).isEmailFreeForRegistration(email, sender);
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
verify(commandService).send(sender, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
||||
verifyNoMoreInteractions(dataSource);
|
||||
verifyZeroInteractions(auth);
|
||||
@@ -111,11 +115,11 @@ public class SetEmailCommandTest {
|
||||
// given
|
||||
String user = "Bobby";
|
||||
String email = "new-addr@example.org";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(dataSource.getAuth(user)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(commandService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(dataSource.updateEmail(auth)).willReturn(false);
|
||||
|
||||
// when
|
||||
@@ -123,9 +127,9 @@ public class SetEmailCommandTest {
|
||||
runOptionallyAsyncTask(bukkitService);
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(dataSource).getAuth(user);
|
||||
verify(commandService).isEmailFreeForRegistration(email, sender);
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
verify(commandService).send(sender, MessageKey.ERROR);
|
||||
verify(dataSource).updateEmail(auth);
|
||||
verifyNoMoreInteractions(dataSource);
|
||||
@@ -136,11 +140,11 @@ public class SetEmailCommandTest {
|
||||
// given
|
||||
String user = "Bobby";
|
||||
String email = "new-addr@example.org";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(dataSource.getAuth(user)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(commandService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(dataSource.updateEmail(auth)).willReturn(true);
|
||||
given(playerCache.getAuth(user)).willReturn(null);
|
||||
|
||||
@@ -149,9 +153,9 @@ public class SetEmailCommandTest {
|
||||
runOptionallyAsyncTask(bukkitService);
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(dataSource).getAuth(user);
|
||||
verify(commandService).isEmailFreeForRegistration(email, sender);
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
verify(commandService).send(sender, MessageKey.EMAIL_CHANGED_SUCCESS);
|
||||
verify(dataSource).updateEmail(auth);
|
||||
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
||||
@@ -163,11 +167,11 @@ public class SetEmailCommandTest {
|
||||
// given
|
||||
String user = "Bobby";
|
||||
String email = "new-addr@example.org";
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(dataSource.getAuth(user)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(commandService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, sender)).willReturn(true);
|
||||
given(dataSource.updateEmail(auth)).willReturn(true);
|
||||
given(playerCache.getAuth(user)).willReturn(mock(PlayerAuth.class));
|
||||
|
||||
@@ -176,9 +180,9 @@ public class SetEmailCommandTest {
|
||||
runOptionallyAsyncTask(bukkitService);
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(email);
|
||||
verify(validationService).validateEmail(email);
|
||||
verify(dataSource).getAuth(user);
|
||||
verify(commandService).isEmailFreeForRegistration(email, sender);
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
verify(commandService).send(sender, MessageKey.EMAIL_CHANGED_SUCCESS);
|
||||
verify(dataSource).updateEmail(auth);
|
||||
verify(playerCache).updatePlayer(auth);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
@@ -33,7 +33,7 @@ public class UnregisterAdminCommandTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@@ -2,8 +2,8 @@ package fr.xephi.authme.command.executable.captcha;
|
||||
|
||||
import fr.xephi.authme.data.CaptchaManager;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -34,7 +34,7 @@ public class CaptchaCommandTest {
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Test
|
||||
public void shouldDetectIfPlayerIsLoggedIn() {
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package fr.xephi.authme.command.executable.changepassword;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
@@ -38,7 +38,7 @@ public class ChangePasswordCommandTest {
|
||||
private ChangePasswordCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -29,7 +29,7 @@ public class AddEmailCommandTest {
|
||||
private AddEmailCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private Management management;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
@@ -9,6 +8,7 @@ import fr.xephi.authme.mail.SendMailSSL;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.RecoveryCodeService;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -50,7 +50,7 @@ public class RecoverEmailCommandTest {
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -30,7 +30,7 @@ public class ShowEmailCommandTest {
|
||||
private ShowEmailCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
|
||||
+14
-11
@@ -1,11 +1,12 @@
|
||||
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.message.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
@@ -21,7 +22,6 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class RegisterCommandTest {
|
||||
private RegisterCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private Management management;
|
||||
@@ -52,6 +52,9 @@ public class RegisterCommandTest {
|
||||
@Mock
|
||||
private SendMailSSL sendMailSsl;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
TestHelper.setupLogger();
|
||||
@@ -70,7 +73,7 @@ public class RegisterCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
command.executeCommand(sender, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("Player only!")));
|
||||
@@ -84,7 +87,7 @@ public class RegisterCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
command.executeCommand(player, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(management).performRegister(player, "", "", true);
|
||||
@@ -97,7 +100,7 @@ public class RegisterCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
command.executeCommand(player, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||
@@ -154,7 +157,7 @@ public class RegisterCommandTest {
|
||||
public void shouldRejectInvalidEmail() {
|
||||
// given
|
||||
String playerMail = "player@example.org";
|
||||
given(commandService.validateEmail(playerMail)).willReturn(false);
|
||||
given(validationService.validateEmail(playerMail)).willReturn(false);
|
||||
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
@@ -165,7 +168,7 @@ public class RegisterCommandTest {
|
||||
command.executeCommand(player, Arrays.asList(playerMail, playerMail));
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(playerMail);
|
||||
verify(validationService).validateEmail(playerMail);
|
||||
verify(commandService).send(player, MessageKey.INVALID_EMAIL);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
@@ -174,7 +177,7 @@ public class RegisterCommandTest {
|
||||
public void shouldRejectInvalidEmailConfirmation() {
|
||||
// given
|
||||
String playerMail = "bobber@bobby.org";
|
||||
given(commandService.validateEmail(playerMail)).willReturn(true);
|
||||
given(validationService.validateEmail(playerMail)).willReturn(true);
|
||||
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
@@ -194,7 +197,7 @@ public class RegisterCommandTest {
|
||||
public void shouldPerformEmailRegistration() {
|
||||
// given
|
||||
String playerMail = "asfd@lakjgre.lds";
|
||||
given(commandService.validateEmail(playerMail)).willReturn(true);
|
||||
given(validationService.validateEmail(playerMail)).willReturn(true);
|
||||
int passLength = 7;
|
||||
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(passLength);
|
||||
|
||||
@@ -207,7 +210,7 @@ public class RegisterCommandTest {
|
||||
command.executeCommand(player, Arrays.asList(playerMail, playerMail));
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(playerMail);
|
||||
verify(validationService).validateEmail(playerMail);
|
||||
verify(sendMailSsl).hasAllInformation();
|
||||
verify(management).performRegister(eq(player), argThat(stringWithLength(passLength)), eq(playerMail), eq(true));
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package fr.xephi.authme.command.executable.unregister;
|
||||
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -31,7 +31,7 @@ public class UnregisterCommandTest {
|
||||
private Management management;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
|
||||
Reference in New Issue
Block a user