Merge branch 'master' into 745-captcha-login-message

This commit is contained in:
Alexandre Vanhecke
2016-12-12 17:58:37 +01:00
committed by GitHub
267 changed files with 4903 additions and 3436 deletions
@@ -14,7 +14,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import java.util.Collections;
@@ -29,18 +29,18 @@ import static fr.xephi.authme.command.FoundResultStatus.UNKNOWN_LABEL;
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link CommandHandler}.
@@ -85,7 +85,7 @@ public class CommandHandlerTest {
given(injector.newInstance(any(Class.class))).willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Class<?> clazz = (Class<?>) invocation.getArguments()[0];
Class<?> clazz = invocation.getArgument(0);
if (ExecutableCommand.class.isAssignableFrom(clazz)) {
Class<? extends ExecutableCommand> commandClass = (Class<? extends ExecutableCommand>) clazz;
ExecutableCommand mock = mock(commandClass);
@@ -108,7 +108,7 @@ public class CommandHandlerTest {
CommandSender sender = mock(CommandSender.class);
CommandDescription command = mock(CommandDescription.class);
doReturn(TestLoginCommand.class).when(command).getExecutableCommand();
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList()))
.willReturn(new FoundCommandResult(command, asList("Authme", "Login"), asList("myPass"), 0.0, SUCCESS));
// when
@@ -129,7 +129,7 @@ public class CommandHandlerTest {
String[] bukkitArgs = {"testPlayer"};
CommandSender sender = mock(CommandSender.class);
CommandDescription command = mock(CommandDescription.class);
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList()))
.willReturn(new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, NO_PERMISSION));
// when
@@ -148,7 +148,7 @@ public class CommandHandlerTest {
String[] bukkitArgs = {"testPlayer"};
CommandSender sender = mock(CommandSender.class);
CommandDescription command = mock(CommandDescription.class);
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList())).willReturn(
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, INCORRECT_ARGUMENTS));
given(permissionsManager.hasPermission(sender, command.getPermission())).willReturn(true);
@@ -170,7 +170,7 @@ public class CommandHandlerTest {
String[] bukkitArgs = {"testPlayer"};
CommandSender sender = mock(CommandSender.class);
CommandDescription command = mock(CommandDescription.class);
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList())).willReturn(
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, INCORRECT_ARGUMENTS));
given(permissionsManager.hasPermission(sender, command.getPermission())).willReturn(false);
@@ -192,7 +192,7 @@ public class CommandHandlerTest {
String[] bukkitArgs = {"testPlayer"};
CommandSender sender = mock(CommandSender.class);
CommandDescription command = mock(CommandDescription.class);
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList())).willReturn(
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, MISSING_BASE_COMMAND));
// when
@@ -212,7 +212,7 @@ public class CommandHandlerTest {
CommandSender sender = mock(CommandSender.class);
CommandDescription command = mock(CommandDescription.class);
given(command.getLabels()).willReturn(Collections.singletonList("test_cmd"));
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList())).willReturn(
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.01, UNKNOWN_LABEL));
// when
@@ -237,8 +237,7 @@ public class CommandHandlerTest {
String[] bukkitArgs = {"testPlayer"};
CommandSender sender = mock(CommandSender.class);
CommandDescription command = mock(CommandDescription.class);
given(command.getLabels()).willReturn(Collections.singletonList("test_cmd"));
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
given(commandMapper.mapPartsToCommand(any(CommandSender.class), anyList())).willReturn(
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 1.0, UNKNOWN_LABEL));
// when
@@ -263,7 +262,7 @@ public class CommandHandlerTest {
CommandDescription command = mock(CommandDescription.class);
doReturn(TestRegisterCommand.class).when(command).getExecutableCommand();
given(commandMapper.mapPartsToCommand(eq(sender), anyListOf(String.class)))
given(commandMapper.mapPartsToCommand(eq(sender), anyList()))
.willReturn(new FoundCommandResult(command, asList("AuthMe", "REGISTER"), asList("testArg"), 0.0, SUCCESS));
// when
@@ -28,9 +28,10 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
/**
@@ -257,7 +258,7 @@ public class CommandMapperTest {
// given
List<String> parts = asList("email", "helptest", "arg1");
CommandSender sender = mock(CommandSender.class);
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
given(permissionsManager.hasPermission(eq(sender), isNull())).willReturn(true);
// when
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
@@ -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.runners.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);
}
}
@@ -10,10 +10,10 @@ import java.util.Collections;
import java.util.List;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link PlayerCommand}.
@@ -27,7 +27,7 @@ public class PlayerCommandTest {
PlayerCommandImpl command = new PlayerCommandImpl();
// when
command.executeCommand(sender, Collections.<String>emptyList());
command.executeCommand(sender, Collections.emptyList());
// then
verify(sender).sendMessage(argThat(containsString("only for players")));
@@ -54,7 +54,7 @@ public class PlayerCommandTest {
PlayerCommandWithAlt command = new PlayerCommandWithAlt();
// when
command.executeCommand(sender, Collections.<String>emptyList());
command.executeCommand(sender, Collections.emptyList());
// then
verify(sender, times(1)).sendMessage(argThat(containsString("use /authme test <command> instead")));
@@ -11,7 +11,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import java.util.List;
@@ -28,13 +28,13 @@ import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link HelpCommand}.
@@ -1,17 +1,17 @@
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.BukkitService;
import fr.xephi.authme.service.CommonService;
import org.bukkit.command.CommandSender;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Collections;
@@ -20,8 +20,8 @@ import java.util.List;
import static fr.xephi.authme.TestHelper.runInnerRunnable;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -36,7 +36,7 @@ public class AccountsCommandTest {
@InjectMocks
private AccountsCommand command;
@Mock
private CommandService service;
private CommonService service;
@Mock
private DataSource dataSource;
@Mock
@@ -83,7 +83,6 @@ public class AccountsCommandTest {
CommandSender sender = mock(CommandSender.class);
List<String> arguments = Collections.singletonList("SomeUser");
given(dataSource.getAuth("someuser")).willReturn(mock(PlayerAuth.class));
given(dataSource.getAllAuthsByIp(anyString())).willReturn(Collections.<String>emptyList());
// when
command.executeCommand(sender, arguments);
@@ -3,12 +3,12 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.TestHelper;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.datasource.DataSource;
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;
@@ -17,13 +17,13 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import static fr.xephi.authme.TestHelper.runOptionallyAsyncTask;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -39,7 +39,7 @@ public class ChangePasswordAdminCommandTest {
private ChangePasswordAdminCommand command;
@Mock
private CommandService service;
private CommonService service;
@Mock
private PasswordSecurity passwordSecurity;
@@ -84,7 +84,6 @@ public class ChangePasswordAdminCommandTest {
String player = "player";
String password = "password";
given(playerCache.isAuthenticated(player)).willReturn(false);
given(dataSource.getAuth(player)).willReturn(null);
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
// when
@@ -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;
@@ -13,7 +13,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import java.util.HashSet;
@@ -23,14 +23,14 @@ import java.util.Set;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link ConverterCommand}.
@@ -42,7 +42,7 @@ public class ConverterCommandTest {
private ConverterCommand command;
@Mock
private CommandService commandService;
private CommonService commandService;
@Mock
private BukkitService bukkitService;
@@ -7,18 +7,18 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link FirstSpawnCommand}.
@@ -10,17 +10,16 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link ForceLoginCommand}.
@@ -44,7 +43,7 @@ public class ForceLoginCommandTest {
public void shouldRejectOfflinePlayer() {
// given
String playerName = "Bobby";
Player player = mockPlayer(false, playerName);
Player player = mockPlayer(false);
given(bukkitService.getPlayerExact(playerName)).willReturn(player);
CommandSender sender = mock(CommandSender.class);
@@ -53,7 +52,7 @@ public class ForceLoginCommandTest {
// then
verify(bukkitService).getPlayerExact(playerName);
verify(sender).sendMessage(argThat(equalTo("Player needs to be online!")));
verify(sender).sendMessage("Player needs to be online!");
verifyZeroInteractions(management);
}
@@ -69,7 +68,7 @@ public class ForceLoginCommandTest {
// then
verify(bukkitService).getPlayerExact(playerName);
verify(sender).sendMessage(argThat(equalTo("Player needs to be online!")));
verify(sender).sendMessage("Player needs to be online!");
verifyZeroInteractions(management);
}
@@ -77,7 +76,7 @@ public class ForceLoginCommandTest {
public void shouldRejectPlayerWithMissingPermission() {
// given
String playerName = "testTest";
Player player = mockPlayer(true, playerName);
Player player = mockPlayer(true);
given(bukkitService.getPlayerExact(playerName)).willReturn(player);
given(permissionsManager.hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)).willReturn(false);
CommandSender sender = mock(CommandSender.class);
@@ -95,7 +94,7 @@ public class ForceLoginCommandTest {
public void shouldForceLoginPlayer() {
// given
String playerName = "tester23";
Player player = mockPlayer(true, playerName);
Player player = mockPlayer(true);
given(bukkitService.getPlayerExact(playerName)).willReturn(player);
given(permissionsManager.hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)).willReturn(true);
CommandSender sender = mock(CommandSender.class);
@@ -112,24 +111,23 @@ public class ForceLoginCommandTest {
public void shouldForceLoginSenderSelf() {
// given
String senderName = "tester23";
Player player = mockPlayer(true, senderName);
Player player = mockPlayer(true);
given(bukkitService.getPlayerExact(senderName)).willReturn(player);
given(permissionsManager.hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)).willReturn(true);
CommandSender sender = mock(CommandSender.class);
given(sender.getName()).willReturn(senderName);
// when
command.executeCommand(sender, Collections.<String>emptyList());
command.executeCommand(sender, Collections.emptyList());
// then
verify(bukkitService).getPlayerExact(senderName);
verify(management).forceLogin(player);
}
private static Player mockPlayer(boolean isOnline, String name) {
private static Player mockPlayer(boolean isOnline) {
Player player = mock(Player.class);
given(player.isOnline()).willReturn(isOnline);
given(player.getName()).willReturn(name);
return player;
}
}
@@ -1,23 +1,23 @@
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;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link GetEmailCommand}.
@@ -32,7 +32,7 @@ public class GetEmailCommandTest {
private DataSource dataSource;
@Mock
private CommandService service;
private CommonService service;
@Test
public void shouldReportUnknownUser() {
@@ -8,17 +8,17 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link GetIpCommand}.
@@ -1,16 +1,16 @@
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;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import java.util.Date;
@@ -39,7 +39,7 @@ public class LastLoginCommandTest {
private DataSource dataSource;
@Mock
private CommandService service;
private CommonService service;
@Test
@@ -1,14 +1,14 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.task.purge.PurgeService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.task.purge.PurgeService;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import java.util.HashSet;
@@ -16,11 +16,11 @@ import java.util.Set;
import static com.google.common.collect.Sets.newHashSet;
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link PurgeBannedPlayersCommand}.
@@ -7,7 +7,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Calendar;
@@ -17,11 +17,11 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link PurgeCommand}.
@@ -1,24 +1,24 @@
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;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link PurgeLastPositionCommand}.
@@ -33,7 +33,7 @@ public class PurgeLastPositionCommandTest {
private DataSource dataSource;
@Mock
private CommandService service;
private CommonService service;
@Test
@@ -3,12 +3,12 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.TestHelper;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.limbo.LimboCache;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.datasource.DataSource;
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;
@@ -19,15 +19,15 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import static fr.xephi.authme.TestHelper.runSyncTaskFromOptionallyAsyncTask;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -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.output.LogLevel;
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;
@@ -21,7 +21,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.Arrays;
@@ -29,13 +29,13 @@ import java.util.Collections;
import java.util.List;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
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 static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link ReloadCommand}.
@@ -59,7 +59,7 @@ public class ReloadCommandTest {
private DataSource dataSource;
@Mock
private CommandService commandService;
private CommonService commandService;
@BeforeClass
public static void setUpLogger() {
@@ -2,22 +2,23 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.command.CommandService;
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;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import static fr.xephi.authme.TestHelper.runOptionallyAsyncTask;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -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);
@@ -7,15 +7,15 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link SetFirstSpawnCommand}.
@@ -7,15 +7,15 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link SetSpawnCommand}.
@@ -39,7 +39,7 @@ public class SetSpawnCommandTest {
given(spawnLoader.setSpawn(location)).willReturn(true);
// when
command.executeCommand(player, Collections.<String>emptyList());
command.executeCommand(player, Collections.emptyList());
// then
verify(spawnLoader).setSpawn(location);
@@ -55,7 +55,7 @@ public class SetSpawnCommandTest {
given(spawnLoader.setSpawn(location)).willReturn(false);
// when
command.executeCommand(player, Collections.<String>emptyList());
command.executeCommand(player, Collections.emptyList());
// then
verify(spawnLoader).setSpawn(location);
@@ -7,18 +7,18 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link SpawnCommand}.
@@ -1,26 +1,26 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.service.AntiBotService;
import fr.xephi.authme.command.CommandMapper;
import fr.xephi.authme.command.FoundCommandResult;
import fr.xephi.authme.command.help.HelpProvider;
import fr.xephi.authme.service.AntiBotService;
import org.bukkit.command.CommandSender;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link SwitchAntiBotCommand}.
@@ -1,17 +1,17 @@
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;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
@@ -33,7 +33,7 @@ public class UnregisterAdminCommandTest {
private DataSource dataSource;
@Mock
private CommandService commandService;
private CommonService commandService;
@Mock
private BukkitService bukkitService;
@@ -61,7 +61,6 @@ public class UnregisterAdminCommandTest {
// given
String user = "personaNonGrata";
given(dataSource.isAuthAvailable(user)).willReturn(true);
given(dataSource.removeAuth(user)).willReturn(false);
Player player = mock(Player.class);
given(bukkitService.getPlayerExact(user)).willReturn(player);
CommandSender sender = mock(CommandSender.class);
@@ -80,7 +79,6 @@ public class UnregisterAdminCommandTest {
// given
String user = "personaNonGrata";
given(dataSource.isAuthAvailable(user)).willReturn(true);
given(dataSource.removeAuth(user)).willReturn(false);
given(bukkitService.getPlayerExact(user)).willReturn(null);
CommandSender sender = mock(CommandSender.class);
@@ -12,7 +12,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
@@ -37,7 +37,7 @@ public class CaptchaCommandTest {
private PlayerCache playerCache;
@Mock
private CommandService commandService;
private CommonService commandService;
@Mock
private LimboCache limboCache;
@@ -1,36 +1,32 @@
package fr.xephi.authme.command.executable.changepassword;
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.settings.properties.RestrictionSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.service.ValidationService.ValidationResult;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link ChangePasswordCommand}.
@@ -42,7 +38,7 @@ public class ChangePasswordCommandTest {
private ChangePasswordCommand command;
@Mock
private CommandService commandService;
private CommonService commandService;
@Mock
private PlayerCache playerCache;
@@ -53,22 +49,13 @@ public class ChangePasswordCommandTest {
@Mock
private Management management;
@Before
public void setSettings() {
when(commandService.getProperty(SecuritySettings.MIN_PASSWORD_LENGTH)).thenReturn(2);
when(commandService.getProperty(SecuritySettings.MAX_PASSWORD_LENGTH)).thenReturn(50);
// Only allow passwords with alphanumerical characters for the test
when(commandService.getProperty(RestrictionSettings.ALLOWED_PASSWORD_REGEX)).thenReturn("[a-zA-Z0-9]+");
when(commandService.getProperty(SecuritySettings.UNSAFE_PASSWORDS)).thenReturn(Collections.<String>emptyList());
}
@Test
public void shouldRejectNonPlayerSender() {
// given
CommandSender sender = mock(BlockCommandSender.class);
// when
command.executeCommand(sender, new ArrayList<String>());
command.executeCommand(sender, Collections.emptyList());
// then
verify(sender).sendMessage(argThat(containsString("only for players")));
@@ -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;
@@ -10,12 +10,11 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
@@ -30,7 +29,7 @@ public class AddEmailCommandTest {
private AddEmailCommand command;
@Mock
private CommandService commandService;
private CommonService commandService;
@Mock
private Management management;
@@ -41,7 +40,7 @@ public class AddEmailCommandTest {
CommandSender sender = mock(BlockCommandSender.class);
// when
command.executeCommand(sender, new ArrayList<String>());
command.executeCommand(sender, Collections.emptyList());
// then
verifyZeroInteractions(management);
@@ -52,7 +51,6 @@ public class AddEmailCommandTest {
// given
Player sender = mock(Player.class);
String email = "mail@example";
given(commandService.validateEmail(email)).willReturn(true);
// when
command.executeCommand(sender, Arrays.asList(email, email));
@@ -66,7 +64,6 @@ public class AddEmailCommandTest {
// given
Player sender = mock(Player.class);
String email = "asdfasdf@example.com";
given(commandService.validateEmail(email)).willReturn(true);
// when
command.executeCommand(sender, Arrays.asList(email, "wrongConf"));
@@ -8,7 +8,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.Arrays;
@@ -3,15 +3,14 @@ package fr.xephi.authme.command.executable.email;
import fr.xephi.authme.TestHelper;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.datasource.DataSource;
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 fr.xephi.authme.settings.properties.SecuritySettings;
import org.bukkit.entity.Player;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -19,17 +18,17 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Collections;
import static fr.xephi.authme.AuthMeMatchers.stringWithLength;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.verify;
@@ -51,7 +50,7 @@ public class RecoverEmailCommandTest {
private PasswordSecurity passwordSecurity;
@Mock
private CommandService commandService;
private CommonService commandService;
@Mock
private DataSource dataSource;
@@ -169,13 +168,10 @@ public class RecoverEmailCommandTest {
Player sender = mock(Player.class);
given(sender.getName()).willReturn(name);
given(sendMailSsl.hasAllInformation()).willReturn(true);
given(sendMailSsl.sendRecoveryCode(anyString(), anyString(), anyString())).willReturn(true);
given(playerCache.isAuthenticated(name)).willReturn(false);
String email = "v@example.com";
given(dataSource.getAuth(name)).willReturn(newAuthWithEmail(email));
int codeLength = 7;
given(commandService.getProperty(SecuritySettings.RECOVERY_CODE_LENGTH)).willReturn(codeLength);
int hoursValid = 12;
given(commandService.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID)).willReturn(hoursValid);
String code = "a94f37";
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
given(recoveryCodeService.generateCode(name)).willReturn(code);
@@ -202,7 +198,6 @@ public class RecoverEmailCommandTest {
String email = "vulture@example.com";
PlayerAuth auth = newAuthWithEmail(email);
given(dataSource.getAuth(name)).willReturn(auth);
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
given(recoveryCodeService.isCodeValid(name, "bogus")).willReturn(false);
@@ -223,6 +218,7 @@ public class RecoverEmailCommandTest {
Player sender = mock(Player.class);
given(sender.getName()).willReturn(name);
given(sendMailSsl.hasAllInformation()).willReturn(true);
given(sendMailSsl.sendPasswordMail(anyString(), anyString(), anyString())).willReturn(true);
given(playerCache.isAuthenticated(name)).willReturn(false);
String email = "vulture@example.com";
String code = "A6EF3AC8";
@@ -230,7 +226,7 @@ public class RecoverEmailCommandTest {
given(dataSource.getAuth(name)).willReturn(auth);
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
given(passwordSecurity.computeHash(anyString(), eq(name)))
.willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0]));
.willAnswer(invocation -> new HashedPassword(invocation.getArgument(0)));
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
given(recoveryCodeService.isCodeValid(name, code)).willReturn(true);
@@ -257,13 +253,14 @@ public class RecoverEmailCommandTest {
Player sender = mock(Player.class);
given(sender.getName()).willReturn(name);
given(sendMailSsl.hasAllInformation()).willReturn(true);
given(sendMailSsl.sendPasswordMail(anyString(), anyString(), anyString())).willReturn(true);
given(playerCache.isAuthenticated(name)).willReturn(false);
String email = "shark@example.org";
PlayerAuth auth = newAuthWithEmail(email);
given(dataSource.getAuth(name)).willReturn(auth);
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(20);
given(passwordSecurity.computeHash(anyString(), eq(name)))
.willAnswer(invocation -> new HashedPassword((String) invocation.getArguments()[0]));
.willAnswer(invocation -> new HashedPassword(invocation.getArgument(0)));
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(false);
// when
@@ -1,15 +1,15 @@
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;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
@@ -30,7 +30,7 @@ public class ShowEmailCommandTest {
private ShowEmailCommand command;
@Mock
private CommandService commandService;
private CommonService commandService;
@Mock
private PlayerCache playerCache;
@@ -8,17 +8,17 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link LoginCommand}.
@@ -8,16 +8,16 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link LogoutCommand}.
@@ -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;
@@ -19,20 +20,19 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import static fr.xephi.authme.AuthMeMatchers.stringWithLength;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
/**
* Test for {@link RegisterCommand}.
@@ -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,11 +157,10 @@ 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);
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
given(sendMailSsl.hasAllInformation()).willReturn(true);
Player player = mock(Player.class);
@@ -166,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);
}
@@ -175,11 +177,10 @@ 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);
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
given(sendMailSsl.hasAllInformation()).willReturn(true);
Player player = mock(Player.class);
@@ -196,13 +197,12 @@ 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);
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);
@@ -210,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));
}
@@ -1,15 +1,15 @@
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;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
@@ -31,7 +31,7 @@ public class UnregisterCommandTest {
private Management management;
@Mock
private CommandService commandService;
private CommonService commandService;
@Mock
private PlayerCache playerCache;
@@ -21,8 +21,8 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
/**
* Test for {@link HelpMessagesService}.
@@ -39,9 +39,9 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;