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;
|
||||
|
||||
@@ -5,7 +5,8 @@ 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.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -40,7 +41,10 @@ public class AsyncAddEmailTest {
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Mock
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
@@ -57,8 +61,8 @@ public class AsyncAddEmailTest {
|
||||
given(auth.getEmail()).willReturn(null);
|
||||
given(playerCache.getAuth("tester")).willReturn(auth);
|
||||
given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(true);
|
||||
given(service.validateEmail(email)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(email, player)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, player)).willReturn(true);
|
||||
|
||||
// when
|
||||
asyncAddEmail.addEmail(player, email);
|
||||
@@ -80,8 +84,8 @@ public class AsyncAddEmailTest {
|
||||
given(auth.getEmail()).willReturn(null);
|
||||
given(playerCache.getAuth("tester")).willReturn(auth);
|
||||
given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(false);
|
||||
given(service.validateEmail(email)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(email, player)).willReturn(true);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, player)).willReturn(true);
|
||||
|
||||
// when
|
||||
asyncAddEmail.addEmail(player, email);
|
||||
@@ -117,7 +121,7 @@ public class AsyncAddEmailTest {
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(auth.getEmail()).willReturn(null);
|
||||
given(playerCache.getAuth("my_player")).willReturn(auth);
|
||||
given(service.validateEmail(email)).willReturn(false);
|
||||
given(validationService.validateEmail(email)).willReturn(false);
|
||||
|
||||
// when
|
||||
asyncAddEmail.addEmail(player, email);
|
||||
@@ -136,8 +140,8 @@ public class AsyncAddEmailTest {
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(auth.getEmail()).willReturn(null);
|
||||
given(playerCache.getAuth("testname")).willReturn(auth);
|
||||
given(service.validateEmail(email)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(email, player)).willReturn(false);
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(email, player)).willReturn(false);
|
||||
|
||||
// when
|
||||
asyncAddEmail.addEmail(player, email);
|
||||
|
||||
@@ -4,7 +4,8 @@ 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.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
@@ -39,7 +40,10 @@ public class AsyncChangeEmailTest {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@Test
|
||||
public void shouldAddEmail() {
|
||||
@@ -50,8 +54,8 @@ public class AsyncChangeEmailTest {
|
||||
PlayerAuth auth = authWithMail("old@mail.tld");
|
||||
given(playerCache.getAuth("bobby")).willReturn(auth);
|
||||
given(dataSource.updateEmail(auth)).willReturn(true);
|
||||
given(service.validateEmail(newEmail)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
|
||||
given(validationService.validateEmail(newEmail)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
|
||||
|
||||
// when
|
||||
process.changeEmail(player, "old@mail.tld", newEmail);
|
||||
@@ -71,8 +75,8 @@ public class AsyncChangeEmailTest {
|
||||
PlayerAuth auth = authWithMail("old@mail.tld");
|
||||
given(playerCache.getAuth("bobby")).willReturn(auth);
|
||||
given(dataSource.updateEmail(auth)).willReturn(false);
|
||||
given(service.validateEmail(newEmail)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
|
||||
given(validationService.validateEmail(newEmail)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(true);
|
||||
|
||||
// when
|
||||
process.changeEmail(player, "old@mail.tld", newEmail);
|
||||
@@ -108,7 +112,7 @@ public class AsyncChangeEmailTest {
|
||||
given(playerCache.isAuthenticated("bobby")).willReturn(true);
|
||||
PlayerAuth auth = authWithMail("old@mail.tld");
|
||||
given(playerCache.getAuth("bobby")).willReturn(auth);
|
||||
given(service.validateEmail(newEmail)).willReturn(false);
|
||||
given(validationService.validateEmail(newEmail)).willReturn(false);
|
||||
|
||||
// when
|
||||
process.changeEmail(player, "old@mail.tld", newEmail);
|
||||
@@ -127,7 +131,7 @@ public class AsyncChangeEmailTest {
|
||||
given(playerCache.isAuthenticated("bobby")).willReturn(true);
|
||||
PlayerAuth auth = authWithMail("other@address.email");
|
||||
given(playerCache.getAuth("bobby")).willReturn(auth);
|
||||
given(service.validateEmail(newEmail)).willReturn(true);
|
||||
given(validationService.validateEmail(newEmail)).willReturn(true);
|
||||
|
||||
// when
|
||||
process.changeEmail(player, "old@mail.tld", newEmail);
|
||||
@@ -146,8 +150,8 @@ public class AsyncChangeEmailTest {
|
||||
given(playerCache.isAuthenticated("username")).willReturn(true);
|
||||
PlayerAuth auth = authWithMail("old@example.com");
|
||||
given(playerCache.getAuth("username")).willReturn(auth);
|
||||
given(service.validateEmail(newEmail)).willReturn(true);
|
||||
given(service.isEmailFreeForRegistration(newEmail, player)).willReturn(false);
|
||||
given(validationService.validateEmail(newEmail)).willReturn(true);
|
||||
given(validationService.isEmailFreeForRegistration(newEmail, player)).willReturn(false);
|
||||
|
||||
// when
|
||||
process.changeEmail(player, "old@example.com", newEmail);
|
||||
|
||||
@@ -8,7 +8,7 @@ import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
@@ -56,7 +56,7 @@ public class AsynchronousLoginTest {
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
@Mock
|
||||
private ProcessService processService;
|
||||
private CommonService commonService;
|
||||
@Mock
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
@Mock
|
||||
@@ -81,7 +81,7 @@ public class AsynchronousLoginTest {
|
||||
|
||||
// then
|
||||
verify(playerCache, only()).isAuthenticated(name);
|
||||
verify(processService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
verify(commonService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
verifyZeroInteractions(dataSource);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class AsynchronousLoginTest {
|
||||
|
||||
// then
|
||||
verify(playerCache, only()).isAuthenticated(name);
|
||||
verify(processService).send(player, MessageKey.USER_NOT_REGISTERED);
|
||||
verify(commonService).send(player, MessageKey.USER_NOT_REGISTERED);
|
||||
verify(dataSource, only()).getAuth(name);
|
||||
}
|
||||
|
||||
@@ -111,15 +111,15 @@ public class AsynchronousLoginTest {
|
||||
int groupId = 13;
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).groupId(groupId).build();
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
given(processService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("group");
|
||||
given(processService.getProperty(HooksSettings.NON_ACTIVATED_USERS_GROUP)).willReturn(groupId);
|
||||
given(commonService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("group");
|
||||
given(commonService.getProperty(HooksSettings.NON_ACTIVATED_USERS_GROUP)).willReturn(groupId);
|
||||
|
||||
// when
|
||||
asynchronousLogin.forceLogin(player);
|
||||
|
||||
// then
|
||||
verify(playerCache, only()).isAuthenticated(name);
|
||||
verify(processService).send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||
verify(commonService).send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||
verify(dataSource, only()).getAuth(name);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public class AsynchronousLoginTest {
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).build();
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
given(processService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("");
|
||||
given(commonService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("");
|
||||
doReturn(true).when(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(any(Player.class), anyString());
|
||||
|
||||
// when
|
||||
@@ -141,7 +141,7 @@ public class AsynchronousLoginTest {
|
||||
|
||||
// then
|
||||
verify(playerCache, only()).isAuthenticated(name);
|
||||
verify(processService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
verify(commonService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
verify(dataSource, only()).getAuth(name);
|
||||
verify(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(player, ip);
|
||||
}
|
||||
@@ -156,8 +156,8 @@ public class AsynchronousLoginTest {
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).build();
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
given(processService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("");
|
||||
given(processService.getProperty(PluginSettings.USE_ASYNC_TASKS)).willReturn(true);
|
||||
given(commonService.getProperty(DatabaseSettings.MYSQL_COL_GROUP)).willReturn("");
|
||||
given(commonService.getProperty(PluginSettings.USE_ASYNC_TASKS)).willReturn(true);
|
||||
doReturn(false).when(asynchronousLogin).hasReachedMaxLoggedInPlayersForIp(any(Player.class), anyString());
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
@@ -181,7 +181,7 @@ public class AsynchronousLoginTest {
|
||||
public void shouldPassMaxLoginPerIpCheck() {
|
||||
// given
|
||||
Player player = mockPlayer("Carl");
|
||||
given(processService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(2);
|
||||
given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(2);
|
||||
given(permissionsManager.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)).willReturn(false);
|
||||
mockOnlinePlayersInBukkitService();
|
||||
|
||||
@@ -198,7 +198,7 @@ public class AsynchronousLoginTest {
|
||||
public void shouldSkipIpCheckForZeroThreshold() {
|
||||
// given
|
||||
Player player = mockPlayer("Fiona");
|
||||
given(processService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(0);
|
||||
given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(0);
|
||||
|
||||
// when
|
||||
boolean result = asynchronousLogin.hasReachedMaxLoggedInPlayersForIp(player, "192.168.0.1");
|
||||
@@ -212,7 +212,7 @@ public class AsynchronousLoginTest {
|
||||
public void shouldSkipIpCheckForPlayerWithMultipleAccountsPermission() {
|
||||
// given
|
||||
Player player = mockPlayer("Frank");
|
||||
given(processService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(1);
|
||||
given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(1);
|
||||
given(permissionsManager.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)).willReturn(true);
|
||||
|
||||
// when
|
||||
@@ -228,7 +228,7 @@ public class AsynchronousLoginTest {
|
||||
public void shouldFailIpCheckForIpWithTooManyPlayersOnline() {
|
||||
// given
|
||||
Player player = mockPlayer("Ian");
|
||||
given(processService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(2);
|
||||
given(commonService.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP)).willReturn(2);
|
||||
given(permissionsManager.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)).willReturn(false);
|
||||
mockOnlinePlayersInBukkitService();
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
@@ -45,7 +45,7 @@ public class AsynchronousUnregisterTest {
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
@Mock
|
||||
private ProcessService service;
|
||||
private CommonService service;
|
||||
@Mock
|
||||
private PasswordSecurity passwordSecurity;
|
||||
@Mock
|
||||
|
||||
+11
-54
@@ -1,4 +1,4 @@
|
||||
package fr.xephi.authme.process;
|
||||
package fr.xephi.authme.service;
|
||||
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
@@ -9,7 +9,6 @@ import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
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;
|
||||
@@ -25,16 +24,13 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Test for {@link ProcessService}.
|
||||
* Test for {@link CommonService}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ProcessServiceTest {
|
||||
public class CommonServiceTest {
|
||||
|
||||
@InjectMocks
|
||||
private ProcessService processService;
|
||||
|
||||
@Mock
|
||||
private ValidationService validationService;
|
||||
private CommonService commonService;
|
||||
|
||||
@Mock
|
||||
private Settings settings;
|
||||
@@ -54,22 +50,13 @@ public class ProcessServiceTest {
|
||||
given(settings.getProperty(SecuritySettings.CAPTCHA_LENGTH)).willReturn(8);
|
||||
|
||||
// when
|
||||
int result = processService.getProperty(SecuritySettings.CAPTCHA_LENGTH);
|
||||
int result = commonService.getProperty(SecuritySettings.CAPTCHA_LENGTH);
|
||||
|
||||
// then
|
||||
verify(settings).getProperty(SecuritySettings.CAPTCHA_LENGTH);
|
||||
assertThat(result, equalTo(8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSettings() {
|
||||
// given/when
|
||||
Settings result = processService.getSettings();
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(settings));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendMessageToPlayer() {
|
||||
// given
|
||||
@@ -77,7 +64,7 @@ public class ProcessServiceTest {
|
||||
MessageKey key = MessageKey.ACCOUNT_NOT_ACTIVATED;
|
||||
|
||||
// when
|
||||
processService.send(sender, key);
|
||||
commonService.send(sender, key);
|
||||
|
||||
// then
|
||||
verify(messages).send(sender, key);
|
||||
@@ -91,7 +78,7 @@ public class ProcessServiceTest {
|
||||
String[] replacements = new String[]{"test", "toast"};
|
||||
|
||||
// when
|
||||
processService.send(sender, key, replacements);
|
||||
commonService.send(sender, key, replacements);
|
||||
|
||||
// then
|
||||
verify(messages).send(sender, key, replacements);
|
||||
@@ -105,7 +92,7 @@ public class ProcessServiceTest {
|
||||
given(messages.retrieve(key)).willReturn(lines);
|
||||
|
||||
// when
|
||||
String[] result = processService.retrieveMessage(key);
|
||||
String[] result = commonService.retrieveMessage(key);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(lines));
|
||||
@@ -120,43 +107,13 @@ public class ProcessServiceTest {
|
||||
given(messages.retrieveSingle(key)).willReturn(text);
|
||||
|
||||
// when
|
||||
String result = processService.retrieveSingleMessage(key);
|
||||
String result = commonService.retrieveSingleMessage(key);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(text));
|
||||
verify(messages).retrieveSingle(key);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldValidateEmail() {
|
||||
// given
|
||||
String email = "test@example.tld";
|
||||
given(validationService.validateEmail(email)).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = processService.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 = processService.isEmailFreeForRegistration(email, sender);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
verify(validationService).isEmailFreeForRegistration(email, sender);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCheckPermission() {
|
||||
// given
|
||||
@@ -165,7 +122,7 @@ public class ProcessServiceTest {
|
||||
given(permissionsManager.hasPermission(player, permission)).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = processService.hasPermission(player, permission);
|
||||
boolean result = commonService.hasPermission(player, permission);
|
||||
|
||||
// then
|
||||
verify(permissionsManager).hasPermission(player, permission);
|
||||
@@ -180,7 +137,7 @@ public class ProcessServiceTest {
|
||||
given(authGroupHandler.setGroup(player, type)).willReturn(true);
|
||||
|
||||
// when
|
||||
boolean result = processService.setGroup(player, type);
|
||||
boolean result = commonService.setGroup(player, type);
|
||||
|
||||
// then
|
||||
verify(authGroupHandler).setGroup(player, type);
|
||||
Reference in New Issue
Block a user