Search in sources :

Example 71 with CommandSender

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

the class PurgeLastPositionCommandTest method shouldResetAllLastPositions.

@Test
public void shouldResetAllLastPositions() {
    // given
    PlayerAuth auth1 = mock(PlayerAuth.class);
    PlayerAuth auth2 = mock(PlayerAuth.class);
    PlayerAuth auth3 = mock(PlayerAuth.class);
    given(dataSource.getAllAuths()).willReturn(Arrays.asList(auth1, auth2, auth3));
    CommandSender sender = mock(CommandSender.class);
    // when
    command.executeCommand(sender, Collections.singletonList("*"));
    // then
    verify(dataSource).getAllAuths();
    verifyPositionWasReset(auth1);
    verifyPositionWasReset(auth2);
    verifyPositionWasReset(auth3);
    verify(sender).sendMessage(argThat(containsString("last position locations are now reset")));
}
Also used : CommandSender(org.bukkit.command.CommandSender) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 72 with CommandSender

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

the class PurgeLastPositionCommandTest method shouldHandleNonExistentUser.

@Test
public void shouldHandleNonExistentUser() {
    // given
    String name = "invalidPlayer";
    CommandSender sender = mock(CommandSender.class);
    // when
    command.executeCommand(sender, Collections.singletonList(name));
    // then
    verify(dataSource).getAuth(name);
    verify(service).send(sender, MessageKey.UNKNOWN_USER);
}
Also used : CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 73 with CommandSender

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

the class RecentPlayersCommandTest method shouldShowRecentPlayers.

@Test
public void shouldShowRecentPlayers() {
    // given
    PlayerAuth auth1 = PlayerAuth.builder().name("hannah").realName("Hannah").lastIp("11.11.11.11").lastLogin(// 11/11/2017 @ 8:09am
    1510387755000L).build();
    PlayerAuth auth2 = PlayerAuth.builder().name("matt").realName("MATT").lastIp("22.11.22.33").lastLogin(// 11/09/2017 @ 11:15pm
    1510269301000L).build();
    doReturn(ZoneId.of("UTC")).when(command).getZoneId();
    given(dataSource.getRecentlyLoggedInPlayers()).willReturn(Arrays.asList(auth1, auth2));
    CommandSender sender = mock(CommandSender.class);
    // when
    command.executeCommand(sender, Collections.emptyList());
    // then
    verify(sender).sendMessage(argThat(containsString("Recently logged in players")));
    verify(sender).sendMessage(argThat(equalToIgnoringCase("- Hannah (08:09 AM, 11 Nov with IP 11.11.11.11)")));
    verify(sender).sendMessage(argThat(equalToIgnoringCase("- MATT (11:15 PM, 09 Nov with IP 22.11.22.33)")));
}
Also used : CommandSender(org.bukkit.command.CommandSender) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 74 with CommandSender

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

the class ReloadCommandTest method shouldIssueWarningForChangedDataSourceSetting.

@Test
public void shouldIssueWarningForChangedDataSourceSetting() {
    // given
    CommandSender sender = mock(CommandSender.class);
    given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL);
    given(dataSource.getType()).willReturn(DataSourceType.SQLITE);
    given(reloadableStore.retrieveAllOfType()).willReturn(Collections.emptyList());
    given(settingsDependentStore.retrieveAllOfType()).willReturn(Collections.emptyList());
    // when
    command.executeCommand(sender, Collections.emptyList());
    // then
    verify(settings).reload();
    verify(reloadableStore).retrieveAllOfType();
    verify(settingsDependentStore).retrieveAllOfType();
    verify(sender).sendMessage(argThat(containsString("cannot change database type")));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Test(org.junit.Test)

Example 75 with CommandSender

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

the class TotpDisableAdminCommandTest method shouldHandleUnknownUser.

@Test
public void shouldHandleUnknownUser() {
    // given
    CommandSender sender = mock(CommandSender.class);
    given(dataSource.getAuth("user")).willReturn(null);
    // when
    command.executeCommand(sender, Collections.singletonList("user"));
    // then
    verify(messages).send(sender, MessageKey.UNKNOWN_USER);
    verify(dataSource, only()).getAuth("user");
}
Also used : CommandSender(org.bukkit.command.CommandSender) 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