From a2d693fc742d3b6351460564811b89889c40b279 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 16 Oct 2020 12:16:15 -0400 Subject: [PATCH] chat commands: unregister bh and lms commands --- .../chatcommands/ChatCommandsPlugin.java | 6 ++- .../chatcommands/ChatCommandsPluginTest.java | 47 +++++++++---------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index 81e4b4618d..5fce86024c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -202,7 +202,10 @@ public class ChatCommandsPlugin extends Plugin chatCommandManager.unregisterCommand(CMB_COMMAND_STRING); chatCommandManager.unregisterCommand(PRICE_COMMAND_STRING); chatCommandManager.unregisterCommand(LEVEL_COMMAND_STRING); + chatCommandManager.unregisterCommand(BOUNTY_HUNTER_HUNTER_COMMAND); + chatCommandManager.unregisterCommand(BOUNTY_HUNTER_ROGUE_COMMAND); chatCommandManager.unregisterCommand(CLUES_COMMAND_STRING); + chatCommandManager.unregisterCommand(LAST_MAN_STANDING_COMMAND); chatCommandManager.unregisterCommand(KILLCOUNT_COMMAND_STRING); chatCommandManager.unregisterCommand(QP_COMMAND_STRING); chatCommandManager.unregisterCommand(PB_COMMAND); @@ -1049,7 +1052,8 @@ public class ChatCommandsPlugin extends Plugin * @param chatMessage The chat message containing the command. * @param message The chat message */ - private void playerSkillLookup(ChatMessage chatMessage, String message) + @VisibleForTesting + void playerSkillLookup(ChatMessage chatMessage, String message) { if (!config.lvl()) { diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java index db61d333d7..7bdf59971c 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java @@ -24,12 +24,12 @@ */ package net.runelite.client.plugins.chatcommands; +import com.google.common.collect.Sets; import com.google.inject.Guice; import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.BoundFieldModule; import java.io.IOException; import java.util.concurrent.ScheduledExecutorService; -import java.util.function.BiConsumer; import javax.inject.Inject; import net.runelite.api.ChatMessageType; import static net.runelite.api.ChatMessageType.FRIENDSCHATNOTIFICATION; @@ -54,7 +54,7 @@ import net.runelite.http.api.hiscore.HiscoreClient; import net.runelite.http.api.hiscore.HiscoreSkill; import net.runelite.http.api.hiscore.SingleHiscoreSkillResult; import net.runelite.http.api.hiscore.Skill; -import org.junit.After; +import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -64,6 +64,7 @@ import org.mockito.Mock; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -120,15 +121,28 @@ public class ChatCommandsPluginTest { Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this); - when(client.getUsername()).thenReturn(PLAYER_NAME); + Player player = mock(Player.class); + when(player.getName()).thenReturn(PLAYER_NAME); + when(client.getLocalPlayer()).thenReturn(player); - chatCommandsPlugin.startUp(); + when(client.getUsername()).thenReturn(PLAYER_NAME); } - @After - public void after() + @Test + public void testStartupShutdown() { + chatCommandsPlugin.startUp(); chatCommandsPlugin.shutDown(); + + ArgumentCaptor registerCaptor = ArgumentCaptor.forClass(String.class); + verify(chatCommandManager, atLeastOnce()).registerCommand(registerCaptor.capture(), any()); + verify(chatCommandManager, atLeastOnce()).registerCommandAsync(registerCaptor.capture(), any()); + verify(chatCommandManager, atLeastOnce()).registerCommandAsync(registerCaptor.capture(), any(), any()); + + ArgumentCaptor unregisterCaptor = ArgumentCaptor.forClass(String.class); + verify(chatCommandManager, atLeastOnce()).unregisterCommand(unregisterCaptor.capture()); + + assertEquals(Sets.newHashSet(registerCaptor.getAllValues()), Sets.newHashSet(unregisterCaptor.getAllValues())); } @Test @@ -448,10 +462,6 @@ public class ChatCommandsPluginTest @Test public void testAdventureLogCountersPage() { - Player player = mock(Player.class); - when(player.getName()).thenReturn(PLAYER_NAME); - when(client.getLocalPlayer()).thenReturn(player); - Widget advLogWidget = mock(Widget.class); Widget advLogExploitsTextWidget = mock(Widget.class); when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); @@ -505,10 +515,6 @@ public class ChatCommandsPluginTest @Test public void testAdventurerLogCountersPage2() { - Player player = mock(Player.class); - when(player.getName()).thenReturn(PLAYER_NAME); - when(client.getLocalPlayer()).thenReturn(player); - Widget advLogWidget = mock(Widget.class); Widget advLogExploitsTextWidget = mock(Widget.class); when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); @@ -559,10 +565,6 @@ public class ChatCommandsPluginTest @Test public void testNotYourAdventureLogCountersPage() { - Player player = mock(Player.class); - when(player.getName()).thenReturn(PLAYER_NAME); - when(client.getLocalPlayer()).thenReturn(player); - Widget advLogWidget = mock(Widget.class); Widget advLogExploitsTextWidget = mock(Widget.class); when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); @@ -585,14 +587,7 @@ public class ChatCommandsPluginTest @Test public void testPlayerSkillLookup() throws IOException { - Player player = mock(Player.class); - when(player.getName()).thenReturn(PLAYER_NAME); - when(client.getLocalPlayer()).thenReturn(player); - when(chatCommandsConfig.lvl()).thenReturn(true); - ArgumentCaptor> captor = ArgumentCaptor.forClass(BiConsumer.class); - verify(chatCommandManager).registerCommandAsync(eq("!lvl"), captor.capture()); - BiConsumer value = captor.getValue(); SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult(); skillResult.setPlayer(PLAYER_NAME); @@ -606,7 +601,7 @@ public class ChatCommandsPluginTest chatMessage.setType(ChatMessageType.PUBLICCHAT); chatMessage.setName(PLAYER_NAME); chatMessage.setMessageNode(messageNode); - value.accept(chatMessage, "!lvl zulrah"); + chatCommandsPlugin.playerSkillLookup(chatMessage, "!lvl zulrah"); verify(messageNode).setRuneLiteFormatMessage("Level Zulrah: 1000 Rank: 10"); }