Fix test.

This commit is contained in:
tastybento 2024-02-03 12:11:57 -08:00
parent 43db8d346c
commit 8217b375d5
2 changed files with 6 additions and 5 deletions

View File

@ -134,11 +134,8 @@ public class CommandRankClickListener implements ClickHandler {
.filter(c -> c.testPermission(user.getSender())) // Only allow them to see commands they have permission to see
.flatMap(c -> getCmdRecursively("/", c).stream())
.filter(label -> user.isOp() || !hiddenItems.contains(CommandCycleClick.COMMAND_RANK_PREFIX + label))
.limit(49) // Silently limit to 49
.toList();
if (result.size() > 49) {
plugin.logError("Number of rank setting commands is too big for GUI");
result.subList(49, result.size()).clear();
}
return result;
}

View File

@ -116,6 +116,7 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
// Tab
when(tab.getIsland()).thenReturn(island);
// User
when(user.isOp()).thenReturn(true);
when(user.getUniqueId()).thenReturn(uuid);
when(user.hasPermission(anyString())).thenReturn(true);
when(user.getPlayer()).thenReturn(player);
@ -137,6 +138,7 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
when(cc.isConfigurableRankCommand()).thenReturn(true);
when(cc.getName()).thenReturn("test");
when(cc.getSubCommands()).thenReturn(Collections.emptyMap());
when(cc.testPermission(any())).thenReturn(true); // All commands are allowed
map.put("test", cc);
when(cm.getCommands()).thenReturn(map);
crcl = new CommandRankClickListener();
@ -157,6 +159,7 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
*/
@Test
public void testOnClickNoPermission() {
when(user.isOp()).thenReturn(false);
when(user.hasPermission(anyString())).thenReturn(false);
assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0));
verify(user).sendMessage("general.errors.no-permission", TextVariables.PERMISSION, "oneblock.settings.COMMAND_RANKS");
@ -207,11 +210,12 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
when(cc.getName()).thenReturn("test" + i);
when(cc.getSubCommands()).thenReturn(Collections.emptyMap());
map.put("test" + i, cc);
when(cc.testPermission(any())).thenReturn(true);
}
when(cm.getCommands()).thenReturn(map);
assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0));
verify(plugin).logError("Number of rank setting commands is too big for GUI");
verify(user).getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, "");
}
/**