Search in sources :

Example 91 with CommandSender

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

the class PermissionsManagerTest method shouldHandleNullPermissionForCommandSender.

@Test
public void shouldHandleNullPermissionForCommandSender() {
    // given
    PermissionNode node = null;
    CommandSender sender = mock(CommandSender.class);
    // when
    boolean result = permissionsManager.hasPermission(sender, node);
    // then
    assertThat(result, equalTo(true));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Test(org.junit.Test)

Example 92 with CommandSender

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

the class PermissionsManagerTest method shouldGrantToOpCommandSender.

@Test
public void shouldGrantToOpCommandSender() {
    // given
    PermissionNode node = TestPermissions.DELETE_USER;
    CommandSender sender = mock(CommandSender.class);
    given(sender.isOp()).willReturn(true);
    // when
    boolean result = permissionsManager.hasPermission(sender, node);
    // then
    assertThat(result, equalTo(true));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Test(org.junit.Test)

Example 93 with CommandSender

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

the class PermissionsManagerTest method shouldDenyPermissionEvenForOpCommandSender.

@Test
public void shouldDenyPermissionEvenForOpCommandSender() {
    // given
    PermissionNode node = TestPermissions.WORLD_DOMINATION;
    CommandSender sender = mock(CommandSender.class);
    // when
    boolean result = permissionsManager.hasPermission(sender, node);
    // then
    assertThat(result, equalTo(false));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Test(org.junit.Test)

Example 94 with CommandSender

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

the class DebugCommandTest method shouldNotListAnyDebugSection.

@Test
public void shouldNotListAnyDebugSection() {
    // given
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(false);
    // when
    command.executeCommand(sender, emptyList());
    // then
    verify(debugSectionFactory, atLeast(MIN_DEBUG_SECTIONS)).newInstance(any(Class.class));
    verify(permissionsManager, atLeast(MIN_DEBUG_SECTIONS)).hasPermission(eq(sender), any(DebugSectionPermissions.class));
    ArgumentCaptor<String> strCaptor = ArgumentCaptor.forClass(String.class);
    verify(sender, times(3)).sendMessage(strCaptor.capture());
    assertThat(strCaptor.getAllValues(), contains(equalTo(ChatColor.BLUE + "AuthMe debug utils"), equalTo("Sections available to you:"), containsString("You don't have permission to view any debug section")));
}
Also used : DebugSectionPermissions(fr.xephi.authme.permission.DebugSectionPermissions) CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) PermissionNode(fr.xephi.authme.permission.PermissionNode) Test(org.junit.Test)

Example 95 with CommandSender

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

the class DebugCommandTest method shouldRunSection.

@Test
public void shouldRunSection() {
    // given
    DebugSection section = spy(InputValidator.class);
    doNothing().when(section).execute(any(CommandSender.class), anyList());
    // Mockito throws a runtime error if below we use the usual "given(factory.newInstance(...)).willReturn(...)"
    doReturn(section).when(debugSectionFactory).newInstance(InputValidator.class);
    CommandSender sender = mock(CommandSender.class);
    given(permissionsManager.hasPermission(sender, section.getRequiredPermission())).willReturn(true);
    List<String> arguments = Arrays.asList(section.getName().toUpperCase(), "test", "toast");
    // when
    command.executeCommand(sender, arguments);
    // then
    verify(permissionsManager).hasPermission(sender, section.getRequiredPermission());
    verify(section).execute(sender, Arrays.asList("test", "toast"));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) 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