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));
}
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));
}
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));
}
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")));
}
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"));
}
Aggregations