Merge remote-tracking branch 'runelite/master'

This commit is contained in:
Owain van Brakel
2021-03-02 13:16:12 +01:00
51 changed files with 2748 additions and 414 deletions

View File

@@ -44,7 +44,10 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@@ -286,4 +289,46 @@ public class ChatNotificationsPluginTest
// set value uses our player name, which has nbsp replaced
verify(messageNode).setValue("<col=005f00><colHIGHLIGHT><u>Logic Knot</u><col=005f00> received a drop: Adamant longsword</col>");
}
}
@Test
public void testLocalPlayerSelfMention()
{
final String localPlayerName = "Broo klyn";
MessageNode messageNode = mock(MessageNode.class);
Player localPlayer = mock(Player.class);
when(client.getLocalPlayer()).thenReturn(localPlayer);
when(localPlayer.getName()).thenReturn(localPlayerName);
lenient().when(config.highlightOwnName()).thenReturn(true);
lenient().when(messageNode.getValue()).thenReturn("Spread love it's the Broo klyn way");
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setName("Broo\u00a0klyn");
chatMessage.setMessageNode(messageNode);
chatNotificationsPlugin.onChatMessage(chatMessage);
verify(messageNode, times(0)).setValue(any());
}
@Test
public void testPrivateChatOutReturn()
{
MessageNode messageNode = mock(MessageNode.class);
lenient().when(config.highlightWordsString()).thenReturn("Brooklyn");
lenient().when(messageNode.getValue()).thenReturn("Spread love it's the Brooklyn way");
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PRIVATECHATOUT);
chatMessage.setMessageNode(messageNode);
chatNotificationsPlugin.startUp();
chatNotificationsPlugin.onChatMessage(chatMessage);
verify(messageNode, times(0)).setValue(any());
}
}

View File

@@ -0,0 +1,134 @@
/*
* Copyright (c) 2019, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.cooking;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import javax.inject.Inject;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GraphicID;
import net.runelite.api.Player;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GraphicChanged;
import net.runelite.client.game.ItemManager;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.ArgumentMatchers.any;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class CookingPluginTest
{
private static final String[] COOKING_MESSAGES = {
"You successfully cook a shark.",
"You successfully cook an anglerfish.",
"You manage to cook a tuna.",
"You cook the karambwan. It looks delicious.",
"You roast a lobster.",
"You cook a bass.",
"You successfully bake a tasty garden pie.",
"You dry a piece of meat and extract the sinew."
};
private static final String incenseBurnerMessage = "You burn some marrentill in the incense burner.";
@Inject
CookingPlugin cookingPlugin;
@Mock
@Bind
Client client;
@Mock
@Bind
InfoBoxManager infoBoxManager;
@Mock
@Bind
ItemManager itemManager;
@Mock
@Bind
CookingConfig config;
@Mock
@Bind
CookingOverlay cookingOverlay;
@Mock
@Bind
OverlayManager overlayManager;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testOnChatMessage()
{
for (String message : COOKING_MESSAGES)
{
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", message, "", 0);
cookingPlugin.onChatMessage(chatMessage);
}
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", incenseBurnerMessage, "", 0);
cookingPlugin.onChatMessage(chatMessage);
CookingSession cookingSession = cookingPlugin.getSession();
assertNotNull(cookingSession);
assertEquals(COOKING_MESSAGES.length, cookingSession.getCookAmount());
assertEquals(0, cookingSession.getBurnAmount());
}
@Test
public void testOnGraphicChanged()
{
Player player = mock(Player.class);
when(player.getGraphic()).thenReturn(GraphicID.WINE_MAKE);
when(config.fermentTimer()).thenReturn(true);
when(client.getLocalPlayer()).thenReturn(player);
GraphicChanged graphicChanged = new GraphicChanged();
graphicChanged.setActor(player);
cookingPlugin.onGraphicChanged(graphicChanged);
verify(infoBoxManager).addInfoBox(any(FermentTimer.class));
}
}

View File

@@ -0,0 +1,184 @@
/*
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.npchighlight;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.awt.Color;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
import net.runelite.api.NPC;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.NpcChanged;
import net.runelite.api.events.NpcSpawned;
import net.runelite.client.ui.overlay.OverlayManager;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class NpcIndicatorsPluginTest
{
@Mock
@Bind
private Client client;
@Mock
@Bind
private ScheduledExecutorService executorService;
@Mock
@Bind
private NpcIndicatorsConfig npcIndicatorsConfig;
@Inject
private NpcIndicatorsPlugin npcIndicatorsPlugin;
@Mock
@Bind
private OverlayManager overlayManager;
@Before
public void setUp()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void getHighlights()
{
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin, , zulrah , *wyvern, ,");
final List<String> highlightedNpcs = npcIndicatorsPlugin.getHighlights();
assertEquals("Length of parsed NPCs is incorrect", 3, highlightedNpcs.size());
final Iterator<String> iterator = highlightedNpcs.iterator();
assertEquals("goblin", iterator.next());
assertEquals("zulrah", iterator.next());
assertEquals("*wyvern", iterator.next());
}
@Test
@Ignore
public void testDeadNpcMenuHighlight()
{
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin");
when(npcIndicatorsConfig.deadNpcMenuColor()).thenReturn(Color.RED);
npcIndicatorsPlugin.rebuildAllNpcs();
NPC npc = mock(NPC.class);
when(npc.getName()).thenReturn("Goblin");
when(npc.isDead()).thenReturn(true);
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()});
MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1, false);
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);
MenuEntry target = new MenuEntry();
target.setTarget("<col=ff0000>Goblin"); // red
verify(client).setMenuEntries(new MenuEntry[]{target});
}
@Test
@Ignore
public void testAliveNpcMenuHighlight()
{
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin");
when(npcIndicatorsConfig.highlightMenuNames()).thenReturn(true);
when(npcIndicatorsConfig.getHighlightColor()).thenReturn(Color.BLUE);
npcIndicatorsPlugin.rebuildAllNpcs();
NPC npc = mock(NPC.class);
when(npc.getName()).thenReturn("Goblin");
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()});
MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1, false);
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);
MenuEntry target = new MenuEntry();
target.setTarget("<col=0000ff>Goblin"); // blue
verify(client).setMenuEntries(new MenuEntry[]{target});
}
@Test
public void taggedNpcChanges()
{
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("Joseph");
npcIndicatorsPlugin.rebuildAllNpcs();
NPC npc = mock(NPC.class);
when(npc.getName()).thenReturn("Joseph");
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
when(npc.getName()).thenReturn("Werewolf");
npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null));
assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
}
@Test
public void npcChangesToTagged()
{
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("Werewolf");
npcIndicatorsPlugin.rebuildAllNpcs();
NPC npc = mock(NPC.class);
when(npc.getName()).thenReturn("Joseph");
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
when(npc.getName()).thenReturn("Werewolf");
npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null));
assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
}
}

View File

@@ -53,6 +53,7 @@ import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.Notifier;
import net.runelite.client.chat.ChatCommandManager;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.ItemManager;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
@@ -64,6 +65,7 @@ import org.junit.runner.RunWith;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import org.mockito.Mock;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -137,6 +139,10 @@ public class SlayerPluginTest
@Bind
Client client;
@Mock
@Bind
ConfigManager configManager;
@Mock
@Bind
SlayerConfig slayerConfig;
@@ -283,7 +289,7 @@ public class SlayerPluginTest
assertEquals("Vet'ion", slayerPlugin.getTaskName());
assertEquals(3, slayerPlugin.getAmount());
verify(slayerConfig).points(914);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.POINTS_KEY, 914);
}
@Test
@@ -296,7 +302,7 @@ public class SlayerPluginTest
assertEquals("Chaos Elemental", slayerPlugin.getTaskName());
assertEquals(3, slayerPlugin.getAmount());
verify(slayerConfig).points(914);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.POINTS_KEY, 914);
}
@Test
@@ -309,7 +315,7 @@ public class SlayerPluginTest
assertEquals("Alchemical Hydra", slayerPlugin.getTaskName());
assertEquals(35, slayerPlugin.getAmount());
verify(slayerConfig).points(724);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.POINTS_KEY, 724);
}
@Test
@@ -440,7 +446,7 @@ public class SlayerPluginTest
when(client.getWidget(WidgetInfo.SLAYER_REWARDS_TOPBAR)).thenReturn(rewardBar);
slayerPlugin.onGameTick(new GameTick());
verify(slayerConfig).points(17566);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.POINTS_KEY, 17566);
}
@Test
@@ -449,7 +455,7 @@ public class SlayerPluginTest
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_ONE, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
verify(slayerConfig).streak(1);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.STREAK_KEY, 1);
assertEquals("", slayerPlugin.getTaskName());
assertEquals(0, slayerPlugin.getAmount());
}
@@ -460,7 +466,7 @@ public class SlayerPluginTest
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_COMPLETE_NO_POINTS, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
verify(slayerConfig).streak(3);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.STREAK_KEY, 3);
assertEquals("", slayerPlugin.getTaskName());
assertEquals(0, slayerPlugin.getAmount());
}
@@ -471,10 +477,10 @@ public class SlayerPluginTest
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_POINTS, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
verify(slayerConfig).streak(9);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.STREAK_KEY, 9);
assertEquals("", slayerPlugin.getTaskName());
assertEquals(0, slayerPlugin.getAmount());
verify(slayerConfig).points(18_000);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.POINTS_KEY, 18_000);
}
@Test
@@ -483,10 +489,10 @@ public class SlayerPluginTest
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_LARGE_STREAK, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
verify(slayerConfig).streak(2465);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.STREAK_KEY, 2465);
assertEquals("", slayerPlugin.getTaskName());
assertEquals(0, slayerPlugin.getAmount());
verify(slayerConfig).points(131_071);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.POINTS_KEY, 131_071);
}
@Test
@@ -495,7 +501,7 @@ public class SlayerPluginTest
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_COMPETE_TURAEL, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
verify(slayerConfig).streak(104);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.STREAK_KEY, 104);
assertEquals("", slayerPlugin.getTaskName());
assertEquals(0, slayerPlugin.getAmount());
}
@@ -506,8 +512,8 @@ public class SlayerPluginTest
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_MAX_STREAK, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
verify(slayerConfig).streak(16_000);
verify(slayerConfig).points(131_071);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.STREAK_KEY, 16000);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.POINTS_KEY, 131_071);
assertEquals("", slayerPlugin.getTaskName());
assertEquals(0, slayerPlugin.getAmount());
}
@@ -518,8 +524,8 @@ public class SlayerPluginTest
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_MAX_POINTS, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
verify(slayerConfig).streak(9);
verify(slayerConfig).points(131_071);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.STREAK_KEY, 9);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.POINTS_KEY, 131_071);
assertEquals("", slayerPlugin.getTaskName());
assertEquals(0, slayerPlugin.getAmount());
}
@@ -530,8 +536,8 @@ public class SlayerPluginTest
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_WILDERNESS, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
verify(slayerConfig).streak(9);
verify(slayerConfig).points(18_000);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.STREAK_KEY, 9);
verify(configManager).setRSProfileConfiguration(SlayerConfig.GROUP_NAME, SlayerConfig.POINTS_KEY, 18_000);
assertEquals("", slayerPlugin.getTaskName());
assertEquals(0, slayerPlugin.getAmount());
}
@@ -919,7 +925,10 @@ public class SlayerPluginTest
@Test
public void infoboxNotAddedOnLogin()
{
when(slayerConfig.taskName()).thenReturn(Task.BLOODVELD.getName());
when(slayerPlugin.getStringProfileConfig(SlayerConfig.TASK_NAME_KEY)).thenReturn(Task.BLOODVELD.getName());
when(slayerPlugin.getIntProfileConfig(SlayerConfig.AMOUNT_KEY)).thenReturn(50);
// Lenient required as this is not called assuming correct plugin logic
lenient().when(slayerConfig.showInfobox()).thenReturn(true);
GameStateChanged loggingIn = new GameStateChanged();
loggingIn.setGameState(GameState.LOGGING_IN);