chat commands: unregister bh and lms commands

This commit is contained in:
Adam
2020-10-16 12:16:15 -04:00
parent 0a8514fa5f
commit a2d693fc74
2 changed files with 26 additions and 27 deletions

View File

@@ -202,7 +202,10 @@ public class ChatCommandsPlugin extends Plugin
chatCommandManager.unregisterCommand(CMB_COMMAND_STRING); chatCommandManager.unregisterCommand(CMB_COMMAND_STRING);
chatCommandManager.unregisterCommand(PRICE_COMMAND_STRING); chatCommandManager.unregisterCommand(PRICE_COMMAND_STRING);
chatCommandManager.unregisterCommand(LEVEL_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(CLUES_COMMAND_STRING);
chatCommandManager.unregisterCommand(LAST_MAN_STANDING_COMMAND);
chatCommandManager.unregisterCommand(KILLCOUNT_COMMAND_STRING); chatCommandManager.unregisterCommand(KILLCOUNT_COMMAND_STRING);
chatCommandManager.unregisterCommand(QP_COMMAND_STRING); chatCommandManager.unregisterCommand(QP_COMMAND_STRING);
chatCommandManager.unregisterCommand(PB_COMMAND); chatCommandManager.unregisterCommand(PB_COMMAND);
@@ -1049,7 +1052,8 @@ public class ChatCommandsPlugin extends Plugin
* @param chatMessage The chat message containing the command. * @param chatMessage The chat message containing the command.
* @param message The chat message * @param message The chat message
*/ */
private void playerSkillLookup(ChatMessage chatMessage, String message) @VisibleForTesting
void playerSkillLookup(ChatMessage chatMessage, String message)
{ {
if (!config.lvl()) if (!config.lvl())
{ {

View File

@@ -24,12 +24,12 @@
*/ */
package net.runelite.client.plugins.chatcommands; package net.runelite.client.plugins.chatcommands;
import com.google.common.collect.Sets;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule; import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.function.BiConsumer;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.ChatMessageType; import net.runelite.api.ChatMessageType;
import static net.runelite.api.ChatMessageType.FRIENDSCHATNOTIFICATION; 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.HiscoreSkill;
import net.runelite.http.api.hiscore.SingleHiscoreSkillResult; import net.runelite.http.api.hiscore.SingleHiscoreSkillResult;
import net.runelite.http.api.hiscore.Skill; import net.runelite.http.api.hiscore.Skill;
import org.junit.After; import static org.junit.Assert.assertEquals;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -64,6 +64,7 @@ import org.mockito.Mock;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@@ -120,15 +121,28 @@ public class ChatCommandsPluginTest
{ {
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this); 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 @Test
public void after() public void testStartupShutdown()
{ {
chatCommandsPlugin.startUp();
chatCommandsPlugin.shutDown(); chatCommandsPlugin.shutDown();
ArgumentCaptor<String> 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<String> unregisterCaptor = ArgumentCaptor.forClass(String.class);
verify(chatCommandManager, atLeastOnce()).unregisterCommand(unregisterCaptor.capture());
assertEquals(Sets.newHashSet(registerCaptor.getAllValues()), Sets.newHashSet(unregisterCaptor.getAllValues()));
} }
@Test @Test
@@ -448,10 +462,6 @@ public class ChatCommandsPluginTest
@Test @Test
public void testAdventureLogCountersPage() 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 advLogWidget = mock(Widget.class);
Widget advLogExploitsTextWidget = mock(Widget.class); Widget advLogExploitsTextWidget = mock(Widget.class);
when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget);
@@ -505,10 +515,6 @@ public class ChatCommandsPluginTest
@Test @Test
public void testAdventurerLogCountersPage2() 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 advLogWidget = mock(Widget.class);
Widget advLogExploitsTextWidget = mock(Widget.class); Widget advLogExploitsTextWidget = mock(Widget.class);
when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget);
@@ -559,10 +565,6 @@ public class ChatCommandsPluginTest
@Test @Test
public void testNotYourAdventureLogCountersPage() 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 advLogWidget = mock(Widget.class);
Widget advLogExploitsTextWidget = mock(Widget.class); Widget advLogExploitsTextWidget = mock(Widget.class);
when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget);
@@ -585,14 +587,7 @@ public class ChatCommandsPluginTest
@Test @Test
public void testPlayerSkillLookup() throws IOException 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); when(chatCommandsConfig.lvl()).thenReturn(true);
ArgumentCaptor<BiConsumer<ChatMessage, String>> captor = ArgumentCaptor.forClass(BiConsumer.class);
verify(chatCommandManager).registerCommandAsync(eq("!lvl"), captor.capture());
BiConsumer<ChatMessage, String> value = captor.getValue();
SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult(); SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult();
skillResult.setPlayer(PLAYER_NAME); skillResult.setPlayer(PLAYER_NAME);
@@ -606,7 +601,7 @@ public class ChatCommandsPluginTest
chatMessage.setType(ChatMessageType.PUBLICCHAT); chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setName(PLAYER_NAME); chatMessage.setName(PLAYER_NAME);
chatMessage.setMessageNode(messageNode); chatMessage.setMessageNode(messageNode);
value.accept(chatMessage, "!lvl zulrah"); chatCommandsPlugin.playerSkillLookup(chatMessage, "!lvl zulrah");
verify(messageNode).setRuneLiteFormatMessage("<colNORMAL>Level <colHIGHLIGHT>Zulrah: 1000<colNORMAL> Rank: <colHIGHLIGHT>10"); verify(messageNode).setRuneLiteFormatMessage("<colNORMAL>Level <colHIGHLIGHT>Zulrah: 1000<colNORMAL> Rank: <colHIGHLIGHT>10");
} }