Search in sources :

Example 76 with CommandSender

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

the class TotpDisableAdminCommandTest method shouldHandleErrorWhileRemovingTotp.

@Test
public void shouldHandleErrorWhileRemovingTotp() {
    // given
    CommandSender sender = mock(CommandSender.class);
    PlayerAuth auth = PlayerAuth.builder().name("Bobby").totpKey("321654").build();
    given(dataSource.getAuth("Bobby")).willReturn(auth);
    given(dataSource.removeTotpKey("Bobby")).willReturn(false);
    // when
    command.executeCommand(sender, Collections.singletonList("Bobby"));
    // then
    verify(messages).send(sender, MessageKey.ERROR);
}
Also used : CommandSender(org.bukkit.command.CommandSender) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 77 with CommandSender

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

the class UnregisterAdminCommandTest method shouldInvokeUnregisterProcessWithNullPlayer.

@Test
public void shouldInvokeUnregisterProcessWithNullPlayer() {
    // given
    String user = "personaNonGrata";
    given(dataSource.isAuthAvailable(user)).willReturn(true);
    given(bukkitService.getPlayerExact(user)).willReturn(null);
    CommandSender sender = mock(CommandSender.class);
    // when
    command.executeCommand(sender, Collections.singletonList(user));
    // then
    verify(dataSource, only()).isAuthAvailable(user);
    verify(bukkitService).getPlayerExact(user);
    verify(management).performUnregisterByAdmin(sender, user, null);
}
Also used : CommandSender(org.bukkit.command.CommandSender) Test(org.junit.Test)

Example 78 with CommandSender

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

the class UnregisterCommandTest method shouldStopIfSenderIsNotPlayer.

@Test
public void shouldStopIfSenderIsNotPlayer() {
    // given
    CommandSender sender = mock(CommandSender.class);
    // when
    command.executeCommand(sender, Collections.singletonList("password"));
    // then
    verifyNoInteractions(playerCache, management);
    verify(sender).sendMessage(argThat(containsString("/authme unregister <player>")));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Test(org.junit.Test)

Example 79 with CommandSender

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

the class MessagesIntegrationTest method shouldNotUseMessageFromDefaultFile.

@Test
public void shouldNotUseMessageFromDefaultFile() {
    // given
    // Key is present in both files
    MessageKey key = MessageKey.WRONG_PASSWORD;
    CommandSender sender = mock(CommandSender.class);
    given(sender.getName()).willReturn("Tester");
    // when
    String message = messages.retrieveSingle(sender, key);
    // then
    assertThat(message, equalTo("§cWrong password!"));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 80 with CommandSender

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

the class MessagesIntegrationTest method shouldLogErrorForInvalidReplacementCount.

@Test
public void shouldLogErrorForInvalidReplacementCount() {
    // given
    Logger logger = mock(Logger.class);
    ConsoleLogger.initialize(logger, null);
    MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR;
    CommandSender sender = mock(CommandSender.class);
    given(sender.getName()).willReturn("Tester");
    // when
    messages.send(sender, key, "rep", "rep2");
    // then
    verify(logger).warning(argThat(containsString("Invalid number of replacements")));
}
Also used : CommandSender(org.bukkit.command.CommandSender) ConsoleLogger(fr.xephi.authme.ConsoleLogger) Logger(java.util.logging.Logger) 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