Search in sources :

Example 86 with CommandSender

use of org.bukkit.command.CommandSender in project AuthMeReloaded by AuthMe.

the class MessagesIntegrationTest method shouldSendMessageToPlayerWithTagReplacement.

@Test
public void shouldSendMessageToPlayerWithTagReplacement() {
    // given
    MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR;
    CommandSender sender = Mockito.mock(CommandSender.class);
    given(sender.getName()).willReturn("Tester");
    // when
    messages.send(sender, key, "1234");
    // then
    verify(sender, times(1)).sendMessage("Use /captcha 1234 to solve the captcha");
}
Also used : CommandSender(org.bukkit.command.CommandSender) Test(org.junit.Test)

Example 87 with CommandSender

use of org.bukkit.command.CommandSender in project AuthMeReloaded by AuthMe.

the class MessagesIntegrationTest method shouldLoadMessageAndSplitAtNewLines.

@Test
public void shouldLoadMessageAndSplitAtNewLines() {
    // given
    MessageKey key = MessageKey.UNKNOWN_USER;
    CommandSender sender = mock(CommandSender.class);
    given(sender.getName()).willReturn("Tester");
    // when
    String[] message = messages.retrieve(key, sender);
    // then
    String[] lines = new String[] { "We've got", "new lines", "and ' apostrophes" };
    assertThat(message, equalTo(lines));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 88 with CommandSender

use of org.bukkit.command.CommandSender in project AuthMeReloaded by AuthMe.

the class AsyncChangePasswordTest method shouldUpdatePasswordOfLoggedInUser.

@Test
public void shouldUpdatePasswordOfLoggedInUser() {
    // given
    CommandSender sender = mock(CommandSender.class);
    String player = "my_user12";
    String password = "passPass";
    given(playerCache.isAuthenticated(player)).willReturn(true);
    HashedPassword hashedPassword = mock(HashedPassword.class);
    given(passwordSecurity.computeHash(password, player)).willReturn(hashedPassword);
    given(dataSource.updatePassword(player, hashedPassword)).willReturn(true);
    // when
    asyncChangePassword.changePasswordAsAdmin(sender, player, password);
    // then
    verify(commonService).send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
    verify(passwordSecurity).computeHash(password, player);
    verify(dataSource).updatePassword(player, hashedPassword);
}
Also used : CommandSender(org.bukkit.command.CommandSender) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Example 89 with CommandSender

use of org.bukkit.command.CommandSender in project AuthMeReloaded by AuthMe.

the class AsyncChangePasswordTest method shouldRejectCommandForUnknownUser.

@Test
public void shouldRejectCommandForUnknownUser() {
    // given
    CommandSender sender = mock(CommandSender.class);
    String player = "player";
    String password = "password";
    given(playerCache.isAuthenticated(player)).willReturn(false);
    given(dataSource.isAuthAvailable(player)).willReturn(false);
    // when
    asyncChangePassword.changePasswordAsAdmin(sender, player, password);
    // then
    verify(commonService).send(sender, MessageKey.UNKNOWN_USER);
    verify(dataSource, only()).isAuthAvailable(player);
}
Also used : CommandSender(org.bukkit.command.CommandSender) Test(org.junit.Test)

Example 90 with CommandSender

use of org.bukkit.command.CommandSender in project AuthMeReloaded by AuthMe.

the class AsyncChangePasswordTest method shouldUpdatePasswordOfOfflineUser.

@Test
public void shouldUpdatePasswordOfOfflineUser() {
    // given
    CommandSender sender = mock(CommandSender.class);
    String player = "my_user12";
    String password = "passPass";
    given(playerCache.isAuthenticated(player)).willReturn(false);
    given(dataSource.isAuthAvailable(player)).willReturn(true);
    HashedPassword hashedPassword = mock(HashedPassword.class);
    given(passwordSecurity.computeHash(password, player)).willReturn(hashedPassword);
    given(dataSource.updatePassword(player, hashedPassword)).willReturn(true);
    // when
    asyncChangePassword.changePasswordAsAdmin(sender, player, password);
    // then
    verify(commonService).send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
    verify(passwordSecurity).computeHash(password, player);
    verify(dataSource).updatePassword(player, hashedPassword);
}
Also used : CommandSender(org.bukkit.command.CommandSender) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Aggregations

CommandSender (org.bukkit.command.CommandSender)295 Test (org.junit.Test)171 Player (org.bukkit.entity.Player)94 Matchers.containsString (org.hamcrest.Matchers.containsString)68 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)50 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)43 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)30 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)29 PermissionNode (fr.xephi.authme.permission.PermissionNode)17 BlockCommandSender (org.bukkit.command.BlockCommandSender)16 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)12 Location (org.bukkit.Location)10 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)9 ArrayList (java.util.ArrayList)9 List (java.util.List)9 FoundCommandResult (fr.xephi.authme.command.FoundCommandResult)8 IOException (java.io.IOException)7 Entity (org.bukkit.entity.Entity)7 IEssentialsCommand (com.earth2me.essentials.commands.IEssentialsCommand)6 NoChargeException (com.earth2me.essentials.commands.NoChargeException)6