Merge remote-tracking branch 'runelite/master'
This commit is contained in:
@@ -24,9 +24,12 @@
|
||||
*/
|
||||
package net.runelite.client.menus;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.MenuAction;
|
||||
@@ -38,24 +41,18 @@ import static net.runelite.api.widgets.WidgetInfo.MINIMAP_WORLDMAP_OPTIONS;
|
||||
import net.runelite.client.util.Text;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MenuManagerTest
|
||||
{
|
||||
private static final MenuEntry CANCEL = new MenuEntry();
|
||||
|
||||
@Inject
|
||||
private MenuManager menuManager;
|
||||
|
||||
@@ -63,14 +60,18 @@ public class MenuManagerTest
|
||||
@Bind
|
||||
private Client client;
|
||||
|
||||
private MenuEntry[] clientMenuEntries = {CANCEL};
|
||||
private final MenuEntry CANCEL = createMenuEntry("Cancel", "", MenuAction.CANCEL, MINIMAP_WORLDMAP_OPTIONS.getPackedId());
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass()
|
||||
private final List<MenuEntry> createdMenuEntries = new ArrayList<>();
|
||||
|
||||
private static MenuEntry createMenuEntry(String option, String target, MenuAction type, int param1)
|
||||
{
|
||||
CANCEL.setOption("Cancel");
|
||||
CANCEL.setType(MenuAction.CANCEL.getId());
|
||||
CANCEL.setParam1(MINIMAP_WORLDMAP_OPTIONS.getPackedId());
|
||||
MenuEntry menuEntry = new TestMenuEntry();
|
||||
menuEntry.setOption(option);
|
||||
menuEntry.setTarget(target);
|
||||
menuEntry.setType(type);
|
||||
menuEntry.setParam1(param1);
|
||||
return menuEntry;
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -78,35 +79,25 @@ public class MenuManagerTest
|
||||
{
|
||||
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
|
||||
|
||||
doAnswer((Answer<Void>) invocationOnMock ->
|
||||
{
|
||||
clientMenuEntries = invocationOnMock.getArgument(0, MenuEntry[].class);
|
||||
return null;
|
||||
}).when(client).setMenuEntries(ArgumentMatchers.any(MenuEntry[].class));
|
||||
when(client.getMenuEntries()).thenAnswer((Answer<MenuEntry[]>) invocationMock -> clientMenuEntries);
|
||||
when(client.createMenuEntry(anyInt()))
|
||||
.thenAnswer(a ->
|
||||
{
|
||||
MenuEntry e = new TestMenuEntry();
|
||||
createdMenuEntries.add(e);
|
||||
return e;
|
||||
});
|
||||
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{CANCEL});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManagedMenuOrder()
|
||||
{
|
||||
final MenuEntry first = new MenuEntry();
|
||||
final MenuEntry second = new MenuEntry();
|
||||
final MenuEntry third = new MenuEntry();
|
||||
first.setOption("Test");
|
||||
first.setTarget("First Entry");
|
||||
first.setParam1(MINIMAP_WORLDMAP_OPTIONS.getPackedId());
|
||||
first.setType(RUNELITE.getId());
|
||||
second.setOption("Test");
|
||||
second.setTarget("Second Entry");
|
||||
second.setParam1(MINIMAP_WORLDMAP_OPTIONS.getPackedId());
|
||||
second.setType(RUNELITE.getId());
|
||||
third.setOption("Test");
|
||||
third.setTarget("Third Entry");
|
||||
third.setParam1(MINIMAP_WORLDMAP_OPTIONS.getPackedId());
|
||||
third.setType(RUNELITE.getId());
|
||||
menuManager.addManagedCustomMenu(new WidgetMenuOption(first.getOption(), first.getTarget(), MINIMAP_WORLDMAP_OPTIONS));
|
||||
menuManager.addManagedCustomMenu(new WidgetMenuOption(second.getOption(), second.getTarget(), MINIMAP_WORLDMAP_OPTIONS));
|
||||
menuManager.addManagedCustomMenu(new WidgetMenuOption(third.getOption(), third.getTarget(), MINIMAP_WORLDMAP_OPTIONS));
|
||||
final MenuEntry first = createMenuEntry("Test", "First Entry", RUNELITE, MINIMAP_WORLDMAP_OPTIONS.getPackedId());
|
||||
final MenuEntry second = createMenuEntry("Test", "Second Entry", RUNELITE, MINIMAP_WORLDMAP_OPTIONS.getPackedId());
|
||||
final MenuEntry third = createMenuEntry("Test", "Third Entry", RUNELITE, MINIMAP_WORLDMAP_OPTIONS.getPackedId());
|
||||
menuManager.addManagedCustomMenu(new WidgetMenuOption(first.getOption(), first.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null);
|
||||
menuManager.addManagedCustomMenu(new WidgetMenuOption(second.getOption(), second.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null);
|
||||
menuManager.addManagedCustomMenu(new WidgetMenuOption(third.getOption(), third.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null);
|
||||
|
||||
menuManager.onMenuEntryAdded(new MenuEntryAdded(
|
||||
CANCEL.getOption(),
|
||||
@@ -116,12 +107,10 @@ public class MenuManagerTest
|
||||
CANCEL.getParam0(),
|
||||
CANCEL.getParam1()));
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> captor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client, atLeastOnce()).setMenuEntries(captor.capture());
|
||||
verify(client, times(3)).createMenuEntry(anyInt());
|
||||
|
||||
final MenuEntry[] resultMenuEntries = captor.getValue();
|
||||
// Strip color tags from menu options before array comparison
|
||||
for (MenuEntry resultEntry : resultMenuEntries)
|
||||
for (MenuEntry resultEntry : createdMenuEntries)
|
||||
{
|
||||
final String resultTarget = resultEntry.getTarget();
|
||||
if (resultTarget != null)
|
||||
@@ -130,6 +119,7 @@ public class MenuManagerTest
|
||||
}
|
||||
}
|
||||
|
||||
assertArrayEquals(new MenuEntry[]{CANCEL, third, second, first}, resultMenuEntries);
|
||||
assertArrayEquals(new MenuEntry[]{third, second, first},
|
||||
Lists.reverse(createdMenuEntries).toArray(new MenuEntry[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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.menus;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class TestMenuEntry extends MenuEntry
|
||||
{
|
||||
private String option;
|
||||
private String target;
|
||||
private int identifier;
|
||||
private int type;
|
||||
private int param0;
|
||||
private int param1;
|
||||
private boolean forceLeftClick;
|
||||
|
||||
@Override
|
||||
public String getOption()
|
||||
{
|
||||
return option;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuEntry setOption(String option)
|
||||
{
|
||||
this.option = option;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTarget()
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuEntry setTarget(String target)
|
||||
{
|
||||
this.target = target;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIdentifier()
|
||||
{
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuEntry setIdentifier(int identifier)
|
||||
{
|
||||
this.identifier = identifier;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuAction getType()
|
||||
{
|
||||
return MenuAction.of(this.type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuEntry setType(MenuAction type)
|
||||
{
|
||||
this.type = type.getId();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getParam0()
|
||||
{
|
||||
return this.param0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuEntry setParam0(int param0)
|
||||
{
|
||||
this.param0 = param0;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getParam1()
|
||||
{
|
||||
return this.param1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuEntry setParam1(int param1)
|
||||
{
|
||||
this.param1 = param1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForceLeftClick()
|
||||
{
|
||||
return this.forceLeftClick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuEntry setForceLeftClick(boolean forceLeftClick)
|
||||
{
|
||||
this.forceLeftClick = forceLeftClick;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeprioritized()
|
||||
{
|
||||
return type >= MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuEntry setDeprioritized(boolean deprioritized)
|
||||
{
|
||||
if (deprioritized)
|
||||
{
|
||||
if (type < MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET)
|
||||
{
|
||||
type += MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type >= MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET)
|
||||
{
|
||||
type -= MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuEntry onClick(Consumer<MenuEntry> callback)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,11 @@ import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Friend;
|
||||
import net.runelite.api.FriendContainer;
|
||||
import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.NameableContainer;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -54,6 +56,14 @@ public class FriendListPluginTest
|
||||
@Bind
|
||||
private FriendListConfig config;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private ConfigManager configManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private ChatMessageManager chatMessageManager;
|
||||
|
||||
@Inject
|
||||
private FriendListPlugin friendListPlugin;
|
||||
|
||||
@@ -78,7 +88,7 @@ public class FriendListPluginTest
|
||||
Friend friend = mock(Friend.class);
|
||||
when(friend.getWorld()).thenReturn(311);
|
||||
|
||||
NameableContainer<Friend> friendContainer = mock(NameableContainer.class);
|
||||
FriendContainer friendContainer = mock(FriendContainer.class);
|
||||
when(friendContainer.findByName("test\u00a0rsn")).thenReturn(friend);
|
||||
when(client.getFriendContainer()).thenReturn(friendContainer);
|
||||
|
||||
|
||||
@@ -0,0 +1,430 @@
|
||||
/*
|
||||
* 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.menuentryswapper;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.util.Arrays;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.KeyCode;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.events.ClientTick;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.menus.TestMenuEntry;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.clearInvocations;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MenuEntrySwapperPluginTest
|
||||
{
|
||||
@Mock
|
||||
@Bind
|
||||
Client client;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
ConfigManager configManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
ItemManager itemManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
MenuEntrySwapperConfig config;
|
||||
|
||||
@Inject
|
||||
MenuEntrySwapperPlugin menuEntrySwapperPlugin;
|
||||
|
||||
private MenuEntry[] entries;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
|
||||
|
||||
when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
|
||||
|
||||
when(client.getMenuEntries()).thenAnswer((Answer<MenuEntry[]>) invocationOnMock ->
|
||||
{
|
||||
// The menu implementation returns a copy of the array, which causes swap() to not
|
||||
// modify the same array being iterated in onClientTick
|
||||
return Arrays.copyOf(entries, entries.length);
|
||||
});
|
||||
doAnswer((Answer<Void>) invocationOnMock ->
|
||||
{
|
||||
Object argument = invocationOnMock.getArguments()[0];
|
||||
entries = (MenuEntry[]) argument;
|
||||
return null;
|
||||
}).when(client).setMenuEntries(any(MenuEntry[].class));
|
||||
|
||||
menuEntrySwapperPlugin.setupSwaps();
|
||||
}
|
||||
|
||||
private static MenuEntry menu(String option, String target, MenuAction menuAction)
|
||||
{
|
||||
return menu(option, target, menuAction, 0);
|
||||
}
|
||||
|
||||
private static MenuEntry menu(String option, String target, MenuAction menuAction, int identifier)
|
||||
{
|
||||
MenuEntry menuEntry = new TestMenuEntry();
|
||||
menuEntry.setOption(option);
|
||||
menuEntry.setTarget(target);
|
||||
menuEntry.setType(menuAction);
|
||||
menuEntry.setIdentifier(identifier);
|
||||
return menuEntry;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSlayerMaster()
|
||||
{
|
||||
lenient().when(config.swapTrade()).thenReturn(true);
|
||||
when(config.swapAssignment()).thenReturn(true);
|
||||
|
||||
entries = new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Rewards", "Duradel", MenuAction.NPC_FIFTH_OPTION),
|
||||
menu("Trade", "Duradel", MenuAction.NPC_FOURTH_OPTION),
|
||||
menu("Assignment", "Duradel", MenuAction.NPC_THIRD_OPTION),
|
||||
menu("Talk-to", "Duradel", MenuAction.NPC_FIRST_OPTION),
|
||||
};
|
||||
menuEntrySwapperPlugin.onClientTick(new ClientTick());
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client).setMenuEntries(argumentCaptor.capture());
|
||||
|
||||
// check the assignment swap is hit first instead of trade
|
||||
assertArrayEquals(new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Rewards", "Duradel", MenuAction.NPC_FIFTH_OPTION),
|
||||
menu("Trade", "Duradel", MenuAction.NPC_FOURTH_OPTION),
|
||||
menu("Talk-to", "Duradel", MenuAction.NPC_FIRST_OPTION),
|
||||
menu("Assignment", "Duradel", MenuAction.NPC_THIRD_OPTION),
|
||||
}, argumentCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBankers()
|
||||
{
|
||||
when(config.swapBank()).thenReturn(true);
|
||||
|
||||
entries = new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Examine", "Gnome banker", MenuAction.EXAMINE_NPC),
|
||||
menu("Examine", "Gnome banker", MenuAction.EXAMINE_NPC),
|
||||
menu("Walk here", "", MenuAction.WALK),
|
||||
|
||||
// Banker 2
|
||||
menu("Collect", "Gnome banker", MenuAction.NPC_FOURTH_OPTION),
|
||||
menu("Bank", "Gnome banker", MenuAction.NPC_THIRD_OPTION),
|
||||
menu("Talk-to", "Gnome banker", MenuAction.NPC_FIRST_OPTION),
|
||||
|
||||
// Banker 1
|
||||
menu("Collect", "Gnome banker", MenuAction.NPC_FOURTH_OPTION),
|
||||
menu("Bank", "Gnome banker", MenuAction.NPC_THIRD_OPTION),
|
||||
menu("Talk-to", "Gnome banker", MenuAction.NPC_FIRST_OPTION),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onClientTick(new ClientTick());
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client, times(2)).setMenuEntries(argumentCaptor.capture());
|
||||
|
||||
assertArrayEquals(new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Examine", "Gnome banker", MenuAction.EXAMINE_NPC),
|
||||
menu("Examine", "Gnome banker", MenuAction.EXAMINE_NPC),
|
||||
menu("Walk here", "", MenuAction.WALK),
|
||||
|
||||
// Banker 2
|
||||
menu("Collect", "Gnome banker", MenuAction.NPC_FOURTH_OPTION),
|
||||
menu("Talk-to", "Gnome banker", MenuAction.NPC_FIRST_OPTION),
|
||||
menu("Bank", "Gnome banker", MenuAction.NPC_THIRD_OPTION),
|
||||
|
||||
// Banker 1
|
||||
menu("Collect", "Gnome banker", MenuAction.NPC_FOURTH_OPTION),
|
||||
menu("Talk-to", "Gnome banker", MenuAction.NPC_FIRST_OPTION),
|
||||
menu("Bank", "Gnome banker", MenuAction.NPC_THIRD_OPTION),
|
||||
}, argumentCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContains()
|
||||
{
|
||||
when(config.swapPay()).thenReturn(true);
|
||||
|
||||
entries = new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Examine", "Kragen", MenuAction.EXAMINE_NPC),
|
||||
menu("Walk here", "", MenuAction.WALK),
|
||||
|
||||
menu("Pay (south)", "Kragen", MenuAction.NPC_FOURTH_OPTION),
|
||||
menu("Pay (north)", "Kragen", MenuAction.NPC_THIRD_OPTION),
|
||||
menu("Talk-to", "Kragen", MenuAction.NPC_FIRST_OPTION),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onClientTick(new ClientTick());
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client).setMenuEntries(argumentCaptor.capture());
|
||||
|
||||
assertArrayEquals(new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Examine", "Kragen", MenuAction.EXAMINE_NPC),
|
||||
menu("Walk here", "", MenuAction.WALK),
|
||||
|
||||
menu("Pay (south)", "Kragen", MenuAction.NPC_FOURTH_OPTION),
|
||||
menu("Talk-to", "Kragen", MenuAction.NPC_FIRST_OPTION),
|
||||
menu("Pay (north)", "Kragen", MenuAction.NPC_THIRD_OPTION),
|
||||
}, argumentCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTeleport()
|
||||
{
|
||||
when(config.swapTeleportSpell()).thenReturn(true);
|
||||
when(client.isKeyPressed(KeyCode.KC_SHIFT)).thenReturn(true);
|
||||
|
||||
// Cast -> Grand Exchange
|
||||
entries = new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
|
||||
menu("Configure", "Varrock Teleport", MenuAction.WIDGET_THIRD_OPTION),
|
||||
menu("Grand Exchange", "Varrock Teleport", MenuAction.WIDGET_SECOND_OPTION),
|
||||
menu("Cast", "Varrock Teleport", MenuAction.WIDGET_FIRST_OPTION),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onClientTick(new ClientTick());
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client).setMenuEntries(argumentCaptor.capture());
|
||||
|
||||
assertArrayEquals(new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
|
||||
menu("Configure", "Varrock Teleport", MenuAction.WIDGET_THIRD_OPTION),
|
||||
menu("Cast", "Varrock Teleport", MenuAction.WIDGET_FIRST_OPTION),
|
||||
menu("Grand Exchange", "Varrock Teleport", MenuAction.WIDGET_SECOND_OPTION),
|
||||
}, argumentCaptor.getValue());
|
||||
|
||||
clearInvocations(client);
|
||||
|
||||
// Grand Exchange -> Cast
|
||||
entries = new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
|
||||
menu("Configure", "Varrock Teleport", MenuAction.WIDGET_THIRD_OPTION),
|
||||
menu("Cast", "Varrock Teleport", MenuAction.WIDGET_SECOND_OPTION),
|
||||
menu("Grand Exchange", "Varrock Teleport", MenuAction.WIDGET_FIRST_OPTION),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onClientTick(new ClientTick());
|
||||
|
||||
argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client).setMenuEntries(argumentCaptor.capture());
|
||||
|
||||
assertArrayEquals(new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
|
||||
menu("Configure", "Varrock Teleport", MenuAction.WIDGET_THIRD_OPTION),
|
||||
menu("Grand Exchange", "Varrock Teleport", MenuAction.WIDGET_FIRST_OPTION),
|
||||
menu("Cast", "Varrock Teleport", MenuAction.WIDGET_SECOND_OPTION),
|
||||
}, argumentCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTobDoor()
|
||||
{
|
||||
when(config.swapQuick()).thenReturn(true);
|
||||
|
||||
//Quick-enter, Enter
|
||||
entries = new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Examine", "Formidable Passage", MenuAction.EXAMINE_OBJECT),
|
||||
menu("Walk here", "", MenuAction.WALK),
|
||||
|
||||
menu("Quick-Enter", "Formidable Passage", MenuAction.GAME_OBJECT_SECOND_OPTION),
|
||||
menu("Enter", "Formidable Passage", MenuAction.GAME_OBJECT_FIRST_OPTION),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onClientTick(new ClientTick());
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client).setMenuEntries(argumentCaptor.capture());
|
||||
|
||||
assertArrayEquals(new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Examine", "Formidable Passage", MenuAction.EXAMINE_OBJECT),
|
||||
menu("Walk here", "", MenuAction.WALK),
|
||||
|
||||
menu("Enter", "Formidable Passage", MenuAction.GAME_OBJECT_FIRST_OPTION),
|
||||
menu("Quick-Enter", "Formidable Passage", MenuAction.GAME_OBJECT_SECOND_OPTION),
|
||||
}, argumentCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShiftWithdraw()
|
||||
{
|
||||
when(config.bankDepositShiftClick()).thenReturn(ShiftDepositMode.EXTRA_OP);
|
||||
when(client.isKeyPressed(KeyCode.KC_SHIFT)).thenReturn(true);
|
||||
|
||||
entries = new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Wield", "Abyssal whip", MenuAction.CC_OP_LOW_PRIORITY, 9),
|
||||
menu("Deposit-1", "Abyssal whip", MenuAction.CC_OP, 2),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onMenuEntryAdded(new MenuEntryAdded(
|
||||
"Deposit-1",
|
||||
"Abyssal whip",
|
||||
MenuAction.CC_OP.getId(),
|
||||
2,
|
||||
-1,
|
||||
-1
|
||||
));
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client).setMenuEntries(argumentCaptor.capture());
|
||||
|
||||
assertArrayEquals(new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Deposit-1", "Abyssal whip", MenuAction.CC_OP, 2),
|
||||
menu("Wield", "Abyssal whip", MenuAction.CC_OP, 9),
|
||||
}, argumentCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShiftDeposit()
|
||||
{
|
||||
when(config.bankDepositShiftClick()).thenReturn(ShiftDepositMode.DEPOSIT_ALL);
|
||||
when(client.isKeyPressed(KeyCode.KC_SHIFT)).thenReturn(true);
|
||||
|
||||
entries = new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Wield", "Rune arrow", MenuAction.CC_OP_LOW_PRIORITY, 9),
|
||||
menu("Deposit-All", "Rune arrow", MenuAction.CC_OP_LOW_PRIORITY, 8),
|
||||
menu("Deposit-1", "Rune arrow", MenuAction.CC_OP, 2),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onMenuEntryAdded(new MenuEntryAdded(
|
||||
"Deposit-1",
|
||||
"Rune arrow",
|
||||
MenuAction.CC_OP.getId(),
|
||||
2,
|
||||
-1,
|
||||
-1
|
||||
));
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client).setMenuEntries(argumentCaptor.capture());
|
||||
|
||||
assertArrayEquals(new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Wield", "Rune arrow", MenuAction.CC_OP_LOW_PRIORITY, 9),
|
||||
menu("Deposit-1", "Rune arrow", MenuAction.CC_OP, 2),
|
||||
menu("Deposit-All", "Rune arrow", MenuAction.CC_OP, 8),
|
||||
}, argumentCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBirdhouse()
|
||||
{
|
||||
when(config.swapBirdhouseEmpty()).thenReturn(true);
|
||||
|
||||
entries = new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Examine", "Redwood birdhouse", MenuAction.EXAMINE_OBJECT),
|
||||
menu("Walk here", "", MenuAction.WALK),
|
||||
|
||||
menu("Empty", "Redwood birdhouse", MenuAction.GAME_OBJECT_THIRD_OPTION),
|
||||
menu("Seeds", "Redwood birdhouse", MenuAction.GAME_OBJECT_SECOND_OPTION),
|
||||
menu("Interact", "Redwood birdhouse", MenuAction.GAME_OBJECT_FIRST_OPTION),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onClientTick(new ClientTick());
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client).setMenuEntries(argumentCaptor.capture());
|
||||
|
||||
assertArrayEquals(new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Examine", "Redwood birdhouse", MenuAction.EXAMINE_OBJECT),
|
||||
menu("Walk here", "", MenuAction.WALK),
|
||||
|
||||
menu("Interact", "Redwood birdhouse", MenuAction.GAME_OBJECT_FIRST_OPTION),
|
||||
menu("Seeds", "Redwood birdhouse", MenuAction.GAME_OBJECT_SECOND_OPTION),
|
||||
menu("Empty", "Redwood birdhouse", MenuAction.GAME_OBJECT_THIRD_OPTION),
|
||||
}, argumentCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZanarisFairyRing()
|
||||
{
|
||||
when(config.swapFairyRing()).thenReturn(FairyRingMode.ZANARIS);
|
||||
|
||||
entries = new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Examine", "Fairy ring", MenuAction.EXAMINE_OBJECT),
|
||||
menu("Walk here", "", MenuAction.WALK),
|
||||
|
||||
menu("Last-destination (AIQ)", "Fairy ring", MenuAction.GAME_OBJECT_SECOND_OPTION),
|
||||
menu("Configure", "Fairy ring", MenuAction.GAME_OBJECT_FIRST_OPTION),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onClientTick(new ClientTick());
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client).setMenuEntries(argumentCaptor.capture());
|
||||
|
||||
assertArrayEquals(new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Examine", "Fairy ring", MenuAction.EXAMINE_OBJECT),
|
||||
menu("Walk here", "", MenuAction.WALK),
|
||||
|
||||
menu("Configure", "Fairy ring", MenuAction.GAME_OBJECT_FIRST_OPTION),
|
||||
menu("Last-destination (AIQ)", "Fairy ring", MenuAction.GAME_OBJECT_SECOND_OPTION),
|
||||
}, argumentCaptor.getValue());
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ 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.menus.TestMenuEntry;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -49,7 +50,6 @@ 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;
|
||||
|
||||
@@ -111,13 +111,12 @@ public class NpcIndicatorsPluginTest
|
||||
|
||||
when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0
|
||||
|
||||
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()});
|
||||
MenuEntry entry = new TestMenuEntry();
|
||||
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{entry});
|
||||
MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1);
|
||||
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);
|
||||
|
||||
MenuEntry target = new MenuEntry();
|
||||
target.setTarget("<col=ff0000>Goblin"); // red
|
||||
verify(client).setMenuEntries(new MenuEntry[]{target});
|
||||
assertEquals("<col=ff0000>Goblin", entry.getTarget()); // red
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,13 +135,12 @@ public class NpcIndicatorsPluginTest
|
||||
|
||||
when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0
|
||||
|
||||
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()});
|
||||
MenuEntry entry = new TestMenuEntry();
|
||||
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{entry});
|
||||
MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1);
|
||||
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);
|
||||
|
||||
MenuEntry target = new MenuEntry();
|
||||
target.setTarget("<col=0000ff>Goblin"); // blue
|
||||
verify(client).setMenuEntries(new MenuEntry[]{target});
|
||||
assertEquals("<col=0000ff>Goblin", entry.getTarget()); // blue
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user