client: Remove all plugins

This commit is contained in:
Owain van Brakel
2020-02-04 05:25:51 +01:00
parent c26d6ffbb8
commit cbb5c50939
1918 changed files with 0 additions and 240603 deletions

View File

@@ -1,253 +0,0 @@
/*
* Copyright (c) 2018, 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.attackstyles;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.Set;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.Skill;
import net.runelite.api.VarPlayer;
import net.runelite.api.Varbits;
import net.runelite.api.events.VarbitChanged;
import net.runelite.api.events.WidgetHiddenChanged;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.ui.overlay.OverlayManager;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import static org.mockito.Mockito.atLeastOnce;
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 AttackStylesPluginTest
{
@Mock
@Bind
Client client;
@Mock
@Bind
OverlayManager overlayManager;
@Mock
@Bind
AttackStylesConfig attackConfig;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Inject
AttackStylesPlugin attackPlugin;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
/*
* Verify that red text is displayed when attacking with a style that gains experience
* in one of the unwanted skills.
*/
@Test
public void testWarning()
{
ConfigChanged warnForAttackEvent = new ConfigChanged();
warnForAttackEvent.setGroup("attackIndicator");
warnForAttackEvent.setKey("warnForAttack");
warnForAttackEvent.setNewValue("true");
attackPlugin.onConfigChanged(warnForAttackEvent);
// Verify there is a warned skill
Set<Skill> warnedSkills = attackPlugin.getWarnedSkills();
assertTrue(warnedSkills.contains(Skill.ATTACK));
// Set mock client to attack in style that gives attack xp
when(client.getVar(VarPlayer.ATTACK_STYLE)).thenReturn(AttackStyle.ACCURATE.ordinal());
// verify that earning xp in a warned skill will display red text on the widget
attackPlugin.onVarbitChanged(new VarbitChanged());
assertTrue(attackPlugin.isWarnedSkillSelected());
// Switch to attack style that doesn't give attack xp
when(client.getVar(VarPlayer.ATTACK_STYLE)).thenReturn(AttackStyle.AGGRESSIVE.ordinal());
// Verify the widget will now display white text
attackPlugin.onVarbitChanged(new VarbitChanged());
warnedSkills = attackPlugin.getWarnedSkills();
assertTrue(warnedSkills.contains(Skill.ATTACK));
assertFalse(attackPlugin.isWarnedSkillSelected());
}
/*
* Verify that attack style widgets are hidden when filtered with the AttackStylesPlugin.
*/
@Test
public void testHiddenWidget()
{
ConfigChanged warnForAttackEvent = new ConfigChanged();
warnForAttackEvent.setGroup("attackIndicator");
warnForAttackEvent.setKey("warnForAttack");
warnForAttackEvent.setNewValue("true");
attackPlugin.onConfigChanged(warnForAttackEvent);
// Set up mock widgets for atk and str attack styles
Widget atkWidget = mock(Widget.class);
Widget strWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.COMBAT_STYLE_ONE)).thenReturn(atkWidget);
when(client.getWidget(WidgetInfo.COMBAT_STYLE_TWO)).thenReturn(strWidget);
// Set widgets to return their hidden value in widgetsToHide when isHidden() is called
when(atkWidget.isHidden()).thenAnswer(x -> isAtkHidden());
when(strWidget.isHidden()).thenAnswer(x -> isStrHidden());
// equip type_4 weapon type on player
when(client.getVar(Varbits.EQUIPPED_WEAPON_TYPE)).thenReturn(WeaponType.TYPE_4.ordinal());
attackPlugin.onVarbitChanged(new VarbitChanged());
// Verify there is a warned skill
Set<Skill> warnedSkills = attackPlugin.getWarnedSkills();
assertTrue(warnedSkills.contains(Skill.ATTACK));
// Enable hiding widgets
ConfigChanged hideWidgetEvent = new ConfigChanged();
hideWidgetEvent.setGroup("attackIndicator");
hideWidgetEvent.setKey("removeWarnedStyles");
hideWidgetEvent.setNewValue("true");
attackPlugin.onConfigChanged(hideWidgetEvent);
when(attackConfig.removeWarnedStyles()).thenReturn(true);
// verify that the accurate attack style widget is hidden
assertTrue(atkWidget.isHidden());
// add another warned skill
ConfigChanged warnForStrengthEvent = new ConfigChanged();
warnForStrengthEvent.setGroup("attackIndicator");
warnForStrengthEvent.setKey("warnForStrength");
warnForStrengthEvent.setNewValue("true");
attackPlugin.onConfigChanged(warnForStrengthEvent);
// verify that the aggressive attack style widget is now hidden
assertTrue(strWidget.isHidden());
// disable hiding attack style widgets
hideWidgetEvent.setGroup("attackIndicator");
hideWidgetEvent.setKey("removeWarnedStyles");
hideWidgetEvent.setNewValue("false");
attackPlugin.onConfigChanged(hideWidgetEvent);
// verify that the aggressive and accurate attack style widgets are no longer hidden
assertFalse(attackPlugin.getHiddenWidgets().get(WeaponType.TYPE_4,
WidgetInfo.COMBAT_STYLE_ONE));
assertFalse(attackPlugin.getHiddenWidgets().get(WeaponType.TYPE_4,
WidgetInfo.COMBAT_STYLE_THREE));
}
/*
* Verify that the defensive style is hidden when switching from bludgeon to bow
*/
@Test
public void testHiddenLongrange()
{
final ArgumentCaptor<Boolean> captor = ArgumentCaptor.forClass(Boolean.class);
final ConfigChanged warnForAttackEvent = new ConfigChanged();
warnForAttackEvent.setGroup("attackIndicator");
warnForAttackEvent.setKey("warnForDefensive");
warnForAttackEvent.setNewValue("true");
attackPlugin.onConfigChanged(warnForAttackEvent);
// verify there is a warned skill
Set<Skill> warnedSkills = attackPlugin.getWarnedSkills();
assertTrue(warnedSkills.contains(Skill.DEFENCE));
// Set up mock widget for strength and longrange
final Widget widget = mock(Widget.class);
when(client.getWidget(WidgetInfo.COMBAT_STYLE_FOUR)).thenReturn(widget);
// Set up hidden changed event
final WidgetHiddenChanged widgetHiddenChanged = new WidgetHiddenChanged();
widgetHiddenChanged.setWidget(widget);
when(widget.getId()).thenReturn(WidgetInfo.COMBAT_STYLE_FOUR.getPackedId());
// Enable hiding widgets
final ConfigChanged hideWidgetEvent = new ConfigChanged();
hideWidgetEvent.setGroup("attackIndicator");
hideWidgetEvent.setKey("removeWarnedStyles");
hideWidgetEvent.setNewValue("true");
attackPlugin.onConfigChanged(hideWidgetEvent);
attackPlugin.removeWarnedStyles = true;
// equip bludgeon on player
when(client.getVar(Varbits.EQUIPPED_WEAPON_TYPE)).thenReturn(WeaponType.TYPE_26.ordinal());
attackPlugin.onVarbitChanged(new VarbitChanged());
attackPlugin.onWidgetHiddenChanged(widgetHiddenChanged);
// verify that the agressive style style widget is showing
verify(widget, atLeastOnce()).setHidden(captor.capture());
assertFalse(captor.getValue());
// equip bow on player
// the equipped weaopn varbit will change after the hiddenChanged event has been dispatched
attackPlugin.onWidgetHiddenChanged(widgetHiddenChanged);
when(client.getVar(Varbits.EQUIPPED_WEAPON_TYPE)).thenReturn(WeaponType.TYPE_3.ordinal());
attackPlugin.onVarbitChanged(new VarbitChanged());
// verify that the longrange attack style widget is now hidden
verify(widget, atLeastOnce()).setHidden(captor.capture());
System.out.println(captor.getValue());
assertTrue(captor.getValue());
}
private boolean isAtkHidden()
{
if (attackPlugin.getHiddenWidgets().size() == 0)
{
return false;
}
return attackPlugin.getHiddenWidgets().get(WeaponType.TYPE_4, WidgetInfo.COMBAT_STYLE_ONE);
}
private boolean isStrHidden()
{
if (attackPlugin.getHiddenWidgets().size() == 0)
{
return false;
}
return attackPlugin.getHiddenWidgets().get(WeaponType.TYPE_4, WidgetInfo.COMBAT_STYLE_TWO);
}
}

View File

@@ -1,113 +0,0 @@
/*
* Copyright (c) 2019, Ron Young <https://github.com/raiyni>
* 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.bank;
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.Client;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemDefinition;
import net.runelite.api.ItemID;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.game.ItemManager;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class BankPluginTest
{
@Mock
@Bind
private Client client;
@Mock
@Bind
private ItemManager itemManager;
@Mock
@Bind
private BankConfig bankConfig;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Inject
private BankPlugin bankPlugin;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testValueSearch()
{
int itemId = ItemID.ABYSSAL_WHIP;
ItemContainer itemContainer = mock(ItemContainer.class);
when(itemContainer.getItems()).thenReturn(new Item[]{new Item(itemId, 30)});
when(client.getItemContainer(InventoryID.BANK)).thenReturn(itemContainer);
ItemDefinition comp = mock(ItemDefinition.class);
// 60k HA price * 30 = 1.8m
when(comp.getPrice())
.thenReturn(100_000);
// 400k GE Price * 30 = 12m
when(itemManager.getItemPrice(itemId))
.thenReturn(400_000);
when(itemManager.getItemDefinition(itemId))
.thenReturn(comp);
assertTrue(bankPlugin.valueSearch(itemId, ">500k"));
assertTrue(bankPlugin.valueSearch(itemId, "< 5.5b"));
assertTrue(bankPlugin.valueSearch(itemId, "500k - 20.6m"));
assertTrue(bankPlugin.valueSearch(itemId, "ha=1.8m"));
assertTrue(bankPlugin.valueSearch(itemId, "ha 500k - 20.6m"));
assertTrue(bankPlugin.valueSearch(itemId, "ha > 940k"));
assertFalse(bankPlugin.valueSearch(itemId, "<500k"));
assertFalse(bankPlugin.valueSearch(itemId, "ha >2m"));
assertFalse(bankPlugin.valueSearch(itemId, "ge > 0.02b"));
assertFalse(bankPlugin.valueSearch(itemId, "1000k"));
}
}

View File

@@ -1,93 +0,0 @@
/*
* 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.bank;
import com.google.common.collect.ImmutableList;
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.Client;
import net.runelite.api.Item;
import net.runelite.api.ItemDefinition;
import net.runelite.api.ItemID;
import net.runelite.client.game.ItemManager;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class ContainerCalculationTest
{
@Mock
@Bind
private Client client;
@Mock
@Bind
private ItemManager itemManager;
@Inject
private ContainerCalculation containerCalculation;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testCalculate()
{
Item coins = new Item(ItemID.COINS_995, Integer.MAX_VALUE);
Item whip = new Item(ItemID.ABYSSAL_WHIP, 1_000_000_000);
Item[] items = ImmutableList.of(
coins,
whip
).toArray(new Item[0]);
ItemDefinition whipComp = mock(ItemDefinition.class);
when(whipComp.getPrice())
.thenReturn(7); // 7 * .6 = 4, 4 * 1m overflows
when(itemManager.getItemDefinition(ItemID.ABYSSAL_WHIP))
.thenReturn(whipComp);
when(itemManager.getItemPrice(ItemID.ABYSSAL_WHIP))
.thenReturn(3); // 1b * 3 overflows
final ContainerPrices prices = containerCalculation.calculate(items);
assertNotNull(prices);
assertTrue(prices.getHighAlchPrice() > Integer.MAX_VALUE);
assertTrue(prices.getGePrice() > Integer.MAX_VALUE);
}
}

View File

@@ -1,157 +0,0 @@
/*
* Copyright (c) 2019, Ron Young <https://github.com/raiyni>
* 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.banktags;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.ItemDefinition;
import net.runelite.api.ItemID;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.config.RuneLiteConfig;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.SpriteManager;
import net.runelite.client.game.chatbox.ChatboxPanelManager;
import net.runelite.client.input.KeyManager;
import net.runelite.client.input.MouseManager;
import net.runelite.client.plugins.banktags.tabs.BankSearch;
import net.runelite.client.plugins.banktags.tabs.TabInterface;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class ItemValueSearchTest
{
@Mock
@Bind
private Client client;
@Mock
@Bind
private ItemManager itemManager;
@Inject
private BankTagsPlugin bankTagsPlugin;
@Mock
@Bind
private ClientThread clientThread;
@Mock
@Bind
private ChatboxPanelManager chatboxPanelManager;
@Mock
@Bind
private MouseManager mouseManager;
@Mock
@Bind
private BankTagsConfig config;
@Mock
@Bind
private TagManager tagManager;
@Mock
@Bind
private TabInterface tabInterface;
@Mock
@Bind
private BankSearch bankSearch;
@Mock
@Bind
private KeyManager keyManager;
@Mock
@Bind
private SpriteManager spriteManager;
@Mock
@Bind
private RuneLiteConfig runeLiteConfig;
@Mock
@Bind
private ScheduledExecutorService scheduledExecutorService;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testCalculate()
{
int itemId = ItemID.ABYSSAL_WHIP;
bankTagsPlugin.itemQuantities.add(itemId, 30);
ItemDefinition comp = mock(ItemDefinition.class);
// 60k HA price * 30 = 1.8m
when(comp.getPrice())
.thenReturn(100_000);
// 400k GE Price * 30 = 12m
when(itemManager.getItemPrice(itemId))
.thenReturn(400_000);
when(itemManager.getItemDefinition(itemId))
.thenReturn(comp);
assertTrue(bankTagsPlugin.valueSearch(itemId, ">500k"));
assertTrue(bankTagsPlugin.valueSearch(itemId, "< 5.5b"));
assertTrue(bankTagsPlugin.valueSearch(itemId, "500k - 20.6m"));
assertTrue(bankTagsPlugin.valueSearch(itemId, "ha=1.8m"));
assertTrue(bankTagsPlugin.valueSearch(itemId, "ha 500k - 20.6m"));
assertTrue(bankTagsPlugin.valueSearch(itemId, "ha > 940k"));
assertFalse(bankTagsPlugin.valueSearch(itemId, "<500k"));
assertFalse(bankTagsPlugin.valueSearch(itemId, "ha >2m"));
assertFalse(bankTagsPlugin.valueSearch(itemId, "ge > 0.02b"));
assertFalse(bankTagsPlugin.valueSearch(itemId, "1000k"));
}
}

View File

@@ -1,97 +0,0 @@
/*
* Copyright (c) 2018, 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.cerberus;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.Arrays;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.NPC;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.events.GameTick;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.ui.overlay.OverlayManager;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class CerberusPluginTest
{
@Mock
@Bind
OverlayManager overlayManager;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Inject
CerberusPlugin cerberusPlugin;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testOnGameTick()
{
List<NPC> ghosts = cerberusPlugin.getGhosts();
ghosts.addAll(Arrays.asList(
mockNpc(new LocalPoint(0, 0)),
mockNpc(new LocalPoint(1, 0)),
mockNpc(new LocalPoint(0, 5)),
mockNpc(new LocalPoint(2, 0)),
mockNpc(new LocalPoint(2, 5)),
mockNpc(new LocalPoint(1, 5))
));
cerberusPlugin.onGameTick(GameTick.INSTANCE);
// Expected sort is by lowest y first, then by lowest x
assertEquals(ghosts.get(0).getLocalLocation(), new LocalPoint(0, 0));
assertEquals(ghosts.get(1).getLocalLocation(), new LocalPoint(1, 0));
assertEquals(ghosts.get(2).getLocalLocation(), new LocalPoint(2, 0));
assertEquals(ghosts.get(3).getLocalLocation(), new LocalPoint(0, 5));
assertEquals(ghosts.get(4).getLocalLocation(), new LocalPoint(1, 5));
assertEquals(ghosts.get(5).getLocalLocation(), new LocalPoint(2, 5));
}
private static NPC mockNpc(LocalPoint localPoint)
{
NPC npc = mock(NPC.class);
when(npc.getLocalLocation()).thenReturn(localPoint);
return npc;
}
}

View File

@@ -1,400 +0,0 @@
/*
* Copyright (c) 2018, 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.chatcommands;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject;
import static net.runelite.api.ChatMessageType.FRIENDSCHATNOTIFICATION;
import static net.runelite.api.ChatMessageType.GAMEMESSAGE;
import static net.runelite.api.ChatMessageType.TRADE;
import net.runelite.api.Client;
import net.runelite.api.events.ChatMessage;
import net.runelite.client.config.ChatColorConfig;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.config.OpenOSRSConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import org.mockito.Mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class ChatCommandsPluginTest
{
@Mock
@Bind
Client client;
@Mock
@Bind
ConfigManager configManager;
@Mock
@Bind
ScheduledExecutorService scheduledExecutorService;
@Mock
@Bind
ChatColorConfig chatColorConfig;
@Mock
@Bind
ChatCommandsConfig chatCommandsConfig;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Inject
ChatCommandsPlugin chatCommandsPlugin;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testCorporealBeastKill()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Corporeal Beast kill count is: <col=ff0000>4</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "corporeal beast", 4);
}
@Test
public void testTheatreOfBlood()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood count is: <col=ff0000>73</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "theatre of blood", 73);
}
@Test
public void testWintertodt()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your subdued Wintertodt count is: <col=ff0000>4</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "wintertodt", 4);
}
@Test
public void testKreearra()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: <col=ff0000>4</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "kree'arra", 4);
}
@Test
public void testBarrows()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Barrows chest count is: <col=ff0000>277</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "barrows chests", 277);
}
@Test
public void testHerbiboar()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your herbiboar harvest count is: <col=ff0000>4091</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "herbiboar", 4091);
}
@Test
public void testGauntlet()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage gauntletMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: <col=ff0000>123</col>.", null, 0);
chatCommandsPlugin.onChatMessage(gauntletMessage);
verify(configManager).setConfiguration("killcount.adam", "gauntlet", 123);
}
@Test
public void testCorruptedGauntlet()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage corruptedGauntletMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Corrupted Gauntlet completion count is: <col=ff0000>4729</col>.", null, 0);
chatCommandsPlugin.onChatMessage(corruptedGauntletMessage);
verify(configManager).setConfiguration("killcount.adam", "corrupted gauntlet", 4729);
}
@Test
public void testPersonalBest()
{
final String FIGHT_DURATION = "Fight duration: <col=ff0000>2:06</col>. Personal best: 1:19.";
when(client.getUsername()).thenReturn("Adam");
// This sets lastBoss
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: <col=ff0000>4</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION, null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("kree'arra"), eq(79));
}
@Test
public void testPersonalBestNoTrailingPeriod()
{
final String FIGHT_DURATION = "Fight duration: <col=ff0000>0:59</col>. Personal best: 0:55";
when(client.getUsername()).thenReturn("Adam");
// This sets lastBoss
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Zulrah kill count is: <col=ff0000>4</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION, null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("zulrah"), eq(55));
}
@Test
public void testNewPersonalBest()
{
final String NEW_PB = "Fight duration: <col=ff0000>3:01</col> (new personal best).";
when(client.getUsername()).thenReturn("Adam");
// This sets lastBoss
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: <col=ff0000>4</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB, null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("kree'arra"), eq(181));
}
@Test
public void testDuelArenaWin()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You won! You have now won 27 duels.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "duel arena wins", 27);
verify(configManager).setConfiguration("killcount.adam", "duel arena win streak", 1);
}
@Test
public void testDuelArenaWin2()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You were defeated! You have won 22 duels.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "duel arena wins", 22);
}
@Test
public void testDuelArenaLose()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You have now lost 999 duels.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "duel arena losses", 999);
}
@Test
public void testAgilityLap()
{
final String NEW_PB = "Lap duration: <col=ff0000>1:01</col> (new personal best).";
when(client.getUsername()).thenReturn("Adam");
// This sets lastBoss
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Prifddinas Agility Course lap count is: <col=ff0000>2</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB, null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("prifddinas agility course"), eq(61));
verify(configManager).setConfiguration(eq("killcount.adam"), eq("prifddinas agility course"), eq(2));
}
@Test
public void testZukNewPb()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your TzKal-Zuk kill count is: <col=ff0000>2</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: <col=ff0000>104:31</col> (new personal best)", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("tzkal-zuk"), eq(104 * 60 + 31));
verify(configManager).setConfiguration(eq("killcount.adam"), eq("tzkal-zuk"), eq(2));
}
@Test
public void testZukKill()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your TzKal-Zuk kill count is: <col=ff0000>3</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: <col=ff0000>172:18</col>. Personal best: 134:52", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("tzkal-zuk"), eq(134 * 60 + 52));
verify(configManager).setConfiguration(eq("killcount.adam"), eq("tzkal-zuk"), eq(3));
}
@Test
public void testGgNewPb()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: <col=ff0000>1:36</col> (new personal best)", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: <col=ff0000>179</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("grotesque guardians"), eq(96));
verify(configManager).setConfiguration(eq("killcount.adam"), eq("grotesque guardians"), eq(179));
}
@Test
public void testGgKill()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: <col=ff0000>2:41</col>. Personal best: 2:14", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: <col=ff0000>32</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("grotesque guardians"), eq(2 * 60 + 14));
verify(configManager).setConfiguration(eq("killcount.adam"), eq("grotesque guardians"), eq(32));
}
@Test
public void testGuantletPersonalBest()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: <col=ff0000>10:24</col>. Personal best: 7:59.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: <col=ff0000>124</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("killcount.adam"), eq("gauntlet"), eq(124));
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("gauntlet"), eq(7 * 60 + 59));
}
@Test
public void testGuantletNewPersonalBest()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: <col=ff0000>10:24</col> (new personal best).", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: <col=ff0000>124</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("gauntlet"), eq(10 * 60 + 24));
verify(configManager).setConfiguration(eq("killcount.adam"), eq("gauntlet"), eq(124));
}
@Test
public void testCoXKill()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete! Duration:</col> <col=ff0000>37:04</col>", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: <col=ff0000>51</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("killcount.adam"), eq("chambers of xeric"), eq(51));
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("chambers of xeric"), eq(37 * 60 + 4));
}
@Test
public void testCoXKillNoPb()
{
when(client.getUsername()).thenReturn("Adam");
when(configManager.getConfiguration(anyString(), anyString(), any())).thenReturn(2224);
ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete! Duration:</col> <col=ff0000>1:45:04</col>", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: <col=ff0000>52</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
verify(configManager).setConfiguration(eq("killcount.adam"), eq("chambers of xeric"), eq(52));
verify(configManager, never()).setConfiguration(eq("personalbest.adam"), eq("chambers of xeric"), anyInt());
}
}

View File

@@ -1,184 +0,0 @@
/*
* Copyright (c) 2019, Adam <Adam@sigterm.info>
* Copyright (c) 2019, osrs-music-map <osrs-music-map@users.noreply.github.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.chatfilter;
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.Client;
import net.runelite.api.Player;
import net.runelite.client.config.OpenOSRSConfig;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class ChatFilterPluginTest
{
@Mock
@Bind
private Client client;
@Mock
@Bind
private ChatFilterConfig chatFilterConfig;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Mock
private Player localPlayer;
@Inject
private ChatFilterPlugin chatFilterPlugin;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
chatFilterPlugin.setFilterType(ChatFilterType.CENSOR_WORDS);
chatFilterPlugin.setFilteredWords("");
chatFilterPlugin.setFilteredRegex("");
when(client.getLocalPlayer()).thenReturn(localPlayer);
}
@Test
public void testCensorWords()
{
chatFilterPlugin.setFilteredWords("hat");
chatFilterPlugin.updateFilteredPatterns();
assertEquals("w***s up", chatFilterPlugin.censorMessage("whats up"));
}
@Test
public void testCensorRegex()
{
chatFilterPlugin.setFilterType(ChatFilterType.REMOVE_MESSAGE);
chatFilterPlugin.setFilteredRegex("5[0-9]x2\n(");
chatFilterPlugin.updateFilteredPatterns();
assertNull(chatFilterPlugin.censorMessage("55X2 Dicing | Trusted Ranks | Huge Pay Outs!"));
}
@Test
public void testBrokenRegex()
{
chatFilterPlugin.setFilteredRegex("Test\n)\n73");
chatFilterPlugin.updateFilteredPatterns();
assertEquals("** isn't funny", chatFilterPlugin.censorMessage("73 isn't funny"));
}
@Test
public void testCaseSensitivity()
{
chatFilterPlugin.setFilterType(ChatFilterType.CENSOR_MESSAGE);
chatFilterPlugin.setFilteredWords("ReGeX!!!");
chatFilterPlugin.updateFilteredPatterns();
assertEquals("Hey, everyone, I just tried to say something very silly!",
chatFilterPlugin.censorMessage("I love regex!!!!!!!!"));
}
@Test
public void testNonPrintableCharacters()
{
chatFilterPlugin.setFilterType(ChatFilterType.REMOVE_MESSAGE);
chatFilterPlugin.setFilteredWords("test");
chatFilterPlugin.updateFilteredPatterns();
assertNull(chatFilterPlugin.censorMessage("te\u008Cst"));
}
@Test
public void testReplayedMessage()
{
chatFilterPlugin.setFilterType(ChatFilterType.REMOVE_MESSAGE);
chatFilterPlugin.setFilteredWords("hello osrs");
chatFilterPlugin.updateFilteredPatterns();
assertNull(chatFilterPlugin.censorMessage("hello\u00A0osrs"));
}
@Test
public void testMessageFromFriendIsFiltered()
{
chatFilterPlugin.setFilterFriends(true);
when(client.isClanMember("Iron Mammal")).thenReturn(false);
assertTrue(chatFilterPlugin.shouldFilterPlayerMessage("Iron Mammal"));
}
@Test
public void testMessageFromFriendIsNotFiltered()
{
when(client.isFriended("Iron Mammal", false)).thenReturn(true);
chatFilterPlugin.setFilterFriends(false);
assertFalse(chatFilterPlugin.shouldFilterPlayerMessage("Iron Mammal"));
}
@Test
public void testMessageFromClanIsFiltered()
{
when(client.isFriended("B0aty", false)).thenReturn(false);
assertTrue(chatFilterPlugin.shouldFilterPlayerMessage("B0aty"));
}
@Test
public void testMessageFromClanIsNotFiltered()
{
lenient().when(client.isClanMember("B0aty")).thenReturn(true);
chatFilterPlugin.setFilterClan(false);
assertFalse(chatFilterPlugin.shouldFilterPlayerMessage("B0aty"));
}
@Test
public void testMessageFromSelfIsNotFiltered()
{
lenient().when(localPlayer.getName()).thenReturn("Swampletics");
assertFalse(chatFilterPlugin.shouldFilterPlayerMessage("Swampletics"));
}
@Test
public void testMessageFromNonFriendNonClanIsFiltered()
{
lenient().when(client.isFriended("Woox", false)).thenReturn(false);
lenient().when(client.isClanMember("Woox")).thenReturn(false);
assertTrue(chatFilterPlugin.shouldFilterPlayerMessage("Woox"));
}
}

View File

@@ -1,234 +0,0 @@
/*
* Copyright (c) 2018, 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.chatnotifications;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.MessageNode;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.util.Text;
import net.runelite.client.Notifier;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.config.OpenOSRSConfig;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
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 ChatNotificationsPluginTest
{
@Mock
@Bind
private Client client;
@Mock
@Bind
private ChatNotificationsConfig config;
@Mock
@Bind
private ChatMessageManager chatMessageManager;
@Mock
@Bind
private Notifier notifier;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Inject
private ChatNotificationsPlugin chatNotificationsPlugin;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void onChatMessage()
{
when(config.highlightWordsString()).thenReturn("Deathbeam, Deathbeam OSRS , test");
MessageNode messageNode = mock(MessageNode.class);
when(messageNode.getValue()).thenReturn("Deathbeam, Deathbeam OSRS");
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setMessageNode(messageNode);
chatNotificationsPlugin.startUp(); // load highlight config
chatNotificationsPlugin.onChatMessage(chatMessage);
verify(messageNode).setValue("<colHIGHLIGHT>Deathbeam<colNORMAL>, <colHIGHLIGHT>Deathbeam<colNORMAL> OSRS");
}
@Test
public void testLtGt()
{
when(config.highlightWordsString()).thenReturn("<test>");
String message = "test <lt>test<gt> test";
MessageNode messageNode = mock(MessageNode.class);
when(messageNode.getValue()).thenReturn(message);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setMessageNode(messageNode);
chatNotificationsPlugin.startUp(); // load highlight config
chatNotificationsPlugin.onChatMessage(chatMessage);
verify(messageNode).setValue("test <colHIGHLIGHT><lt>test<gt><colNORMAL> test");
}
@Test
public void testFullStop()
{
when(config.highlightWordsString()).thenReturn("test");
String message = "foo test. bar";
MessageNode messageNode = mock(MessageNode.class);
when(messageNode.getValue()).thenReturn(message);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setMessageNode(messageNode);
chatNotificationsPlugin.startUp(); // load highlight config
chatNotificationsPlugin.onChatMessage(chatMessage);
verify(messageNode).setValue("foo <colHIGHLIGHT>test<colNORMAL>. bar");
}
@Test
public void testColor()
{
when(config.highlightWordsString()).thenReturn("you. It");
String message = "Your dodgy necklace protects you. <col=ff0000>It has 1 charge left.</col>";
MessageNode messageNode = mock(MessageNode.class);
when(messageNode.getValue()).thenReturn(message);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setMessageNode(messageNode);
chatNotificationsPlugin.startUp(); // load highlight config
chatNotificationsPlugin.onChatMessage(chatMessage);
verify(messageNode).setValue("Your dodgy necklace protects <colHIGHLIGHT>you. It<col=ff0000> has 1 charge left.</col>");
}
@Test
public void testPreceedingColor()
{
when(config.highlightWordsString()).thenReturn("you. It");
String message = "Your dodgy <col=00ff00>necklace protects you. It has 1 charge left.</col>";
MessageNode messageNode = mock(MessageNode.class);
when(messageNode.getValue()).thenReturn(message);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setMessageNode(messageNode);
chatNotificationsPlugin.startUp(); // load highlight config
chatNotificationsPlugin.onChatMessage(chatMessage);
verify(messageNode).setValue("Your dodgy <col=00ff00>necklace protects <colHIGHLIGHT>you. It<col=00ff00> has 1 charge left.</col>");
}
@Test
public void testEmoji()
{
when(config.highlightWordsString()).thenReturn("test");
String message = "emoji test <img=29>";
MessageNode messageNode = mock(MessageNode.class);
when(messageNode.getValue()).thenReturn(message);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setMessageNode(messageNode);
chatNotificationsPlugin.startUp(); // load highlight config
chatNotificationsPlugin.onChatMessage(chatMessage);
verify(messageNode).setValue("emoji <colHIGHLIGHT>test<colNORMAL> <img=29>");
}
@Test
public void testNonMatchedColors()
{
when(config.highlightWordsString()).thenReturn("test");
String message = "<col=ff0000>color</col> test <img=29>";
MessageNode messageNode = mock(MessageNode.class);
when(messageNode.getValue()).thenReturn(message);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setMessageNode(messageNode);
chatNotificationsPlugin.startUp(); // load highlight config
chatNotificationsPlugin.onChatMessage(chatMessage);
verify(messageNode).setValue("<col=ff0000>color</col> <colHIGHLIGHT>test<colNORMAL> <img=29>");
}
@Test
public void highlightListTest()
{
when(config.highlightWordsString()).thenReturn("this,is, a , test, ");
final List<String> higlights = Text.fromCSV(config.highlightWordsString());
assertEquals(4, higlights.size());
final Iterator<String> iterator = higlights.iterator();
assertEquals("this", iterator.next());
assertEquals("is", iterator.next());
assertEquals("a", iterator.next());
assertEquals("test", iterator.next());
}
@Test
public void testStripColor()
{
assertEquals("you. It", ChatNotificationsPlugin.stripColor("you. <col=ff0000>It"));
}
}

View File

@@ -1,64 +0,0 @@
/*
* Copyright (c) 2019 Hydrox6 <ikada@protonmail.ch>
* 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.cluescrolls;
import net.runelite.api.coords.WorldPoint;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import org.junit.Test;
public class ClueScrollPluginTest
{
@Test
public void getGetMirrorPoint()
{
WorldPoint point, converted;
// Zalcano's entrance portal
point = new WorldPoint(3282, 6058, 0);
converted = ClueScrollPlugin.getMirrorPoint(point, true);
assertNotEquals(point, converted);
// Elven Crystal Chest, which is upstairs
point = new WorldPoint(3273, 6082, 2);
converted = ClueScrollPlugin.getMirrorPoint(point, true);
assertNotEquals(point, converted);
// Around the area of the Elite coordinate clue
point = new WorldPoint(2185, 3280, 0);
// To overworld
converted = ClueScrollPlugin.getMirrorPoint(point, true);
assertEquals(point, converted);
// To real
converted = ClueScrollPlugin.getMirrorPoint(point, false);
assertNotEquals(point, converted);
// Brugsen Bursen, Grand Exchange
point = new WorldPoint(3165, 3477, 0);
converted = ClueScrollPlugin.getMirrorPoint(point, false);
assertEquals(point, converted);
}
}

View File

@@ -1,38 +0,0 @@
/*
* 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.cluescrolls.clues;
import net.runelite.api.coords.WorldPoint;
import org.junit.Test;
public class CoordinateClueTest
{
@Test
public void testDuplicateCoordinates()
{
// If this doesn't throw then the clues map doesn't have duplicate keys
new CoordinateClue("test", new WorldPoint(0, 0, 0), null);
}
}

View File

@@ -1,79 +0,0 @@
/*
* Copyright (c) 2019, Jordan Atwood <nightfirecat@protonmail.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.cluescrolls.clues.hotcold;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Test;
public class HotColdTemperatureTest
{
private static final String[] VALID_MESSAGES = {
"The device is warm, and warmer than last time.",
"The device is visibly shaking and burns to the touch. This must be the spot.",
"The device is cold.",
"The device is ice cold.",
"The device is very cold.",
"The device is hot.",
"The device is incredibly hot.",
};
private static final String[] INVALID_MESSAGES = {
"The device is an octopus, and is wetter than last time.",
"foobar",
"a q p w",
"My feet are cold, I should put them in some lukewarm water, or run hot water over them.",
};
@Test
public void testValidTemperatureMessages()
{
for (final String message : VALID_MESSAGES)
{
assertNotNull(message, HotColdTemperature.getFromTemperatureSet(HotColdTemperature.BEGINNER_HOT_COLD_TEMPERATURES, message));
assertNotNull(message, HotColdTemperature.getFromTemperatureSet(HotColdTemperature.MASTER_HOT_COLD_TEMPERATURES, message));
}
}
@Test
public void testInvalidTemperatureMessages()
{
for (final String message : INVALID_MESSAGES)
{
assertNull(message, HotColdTemperature.getFromTemperatureSet(HotColdTemperature.BEGINNER_HOT_COLD_TEMPERATURES, message));
assertNull(message, HotColdTemperature.getFromTemperatureSet(HotColdTemperature.MASTER_HOT_COLD_TEMPERATURES, message));
}
}
@Test
public void testAmbiguousTemperatureMessages()
{
assertEquals(HotColdTemperature.ICE_COLD, HotColdTemperature.getFromTemperatureSet(HotColdTemperature.MASTER_HOT_COLD_TEMPERATURES, "The device is ice cold."));
assertEquals(HotColdTemperature.VERY_COLD, HotColdTemperature.getFromTemperatureSet(HotColdTemperature.MASTER_HOT_COLD_TEMPERATURES, "The device is very cold."));
assertEquals(HotColdTemperature.VERY_HOT, HotColdTemperature.getFromTemperatureSet(HotColdTemperature.MASTER_HOT_COLD_TEMPERATURES, "The device is very hot."));
assertEquals(HotColdTemperature.COLD, HotColdTemperature.getFromTemperatureSet(HotColdTemperature.BEGINNER_HOT_COLD_TEMPERATURES, "The device is cold, and warmer than last time."));
assertEquals(HotColdTemperature.WARM, HotColdTemperature.getFromTemperatureSet(HotColdTemperature.BEGINNER_HOT_COLD_TEMPERATURES, "The device is warm, but colder than last time."));
}
}

View File

@@ -1,396 +0,0 @@
/*
* Copyright (c) 2018, Brett Middle <https://github.com/bmiddle>
* 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.combatlevel;
import net.runelite.api.Experience;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class CombatLevelPluginTest
{
@Test
public void testNewPlayer()
{
int attackLevel = 1;
int strengthLevel = 1;
int defenceLevel = 1;
int hitpointsLevel = 10;
int magicLevel = 1;
int rangeLevel = 1;
int prayerLevel = 1;
int combatLevel = Experience.getCombatLevel(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int meleeNeed = Experience.getNextCombatLevelMelee(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int hpDefNeed = Experience.getNextCombatLevelHpDef(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int rangeNeed = Experience.getNextCombatLevelRange(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int magicNeed = Experience.getNextCombatLevelMagic(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int prayerNeed = Experience.getNextCombatLevelPrayer(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
// test combat level
assertEquals(3, combatLevel);
// test attack/strength
assertEquals(2, meleeNeed);
// test defence/hitpoints
assertEquals(3, hpDefNeed);
// test ranged
assertEquals(2, rangeNeed);
// test magic
assertEquals(2, magicNeed);
// test prayer
assertEquals(5, prayerNeed);
}
@Test
public void testAll10()
{
int attackLevel = 10;
int strengthLevel = 10;
int defenceLevel = 10;
int hitpointsLevel = 10;
int magicLevel = 10;
int rangeLevel = 10;
int prayerLevel = 10;
int combatLevel = Experience.getCombatLevel(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int meleeNeed = Experience.getNextCombatLevelMelee(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int hpDefNeed = Experience.getNextCombatLevelHpDef(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int rangeNeed = Experience.getNextCombatLevelRange(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int magicNeed = Experience.getNextCombatLevelMagic(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int prayerNeed = Experience.getNextCombatLevelPrayer(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
// test combat level
assertEquals(12, combatLevel);
// test attack/strength
assertEquals(1, meleeNeed);
// test defence/hitpoints
assertEquals(1, hpDefNeed);
// test ranged
assertEquals(4, rangeNeed);
// test magic
assertEquals(4, magicNeed);
// test prayer
assertEquals(2, prayerNeed);
}
@Test
public void testPlayerBmid()
{
// snapshot of current stats 2018-10-2
int attackLevel = 65;
int strengthLevel = 70;
int defenceLevel = 60;
int hitpointsLevel = 71;
int magicLevel = 73;
int rangeLevel = 75;
int prayerLevel = 56;
int combatLevel = Experience.getCombatLevel(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int meleeNeed = Experience.getNextCombatLevelMelee(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int hpDefNeed = Experience.getNextCombatLevelHpDef(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int rangeNeed = Experience.getNextCombatLevelRange(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int magicNeed = Experience.getNextCombatLevelMagic(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int prayerNeed = Experience.getNextCombatLevelPrayer(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
// test combat level
assertEquals(83, combatLevel);
// test attack/strength
assertEquals(2, meleeNeed);
// test defence/hitpoints
assertEquals(2, hpDefNeed);
// test ranged
assertEquals(17, rangeNeed);
// test magic
assertEquals(19, magicNeed);
// test prayer
assertEquals(4, prayerNeed);
}
@Test
public void testPlayerRunelite()
{
// snapshot of current stats 2018-10-2
int attackLevel = 43;
int strengthLevel = 36;
int defenceLevel = 1;
int hitpointsLevel = 42;
int magicLevel = 64;
int rangeLevel = 51;
int prayerLevel = 15;
int combatLevel = Experience.getCombatLevel(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int meleeNeed = Experience.getNextCombatLevelMelee(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int hpDefNeed = Experience.getNextCombatLevelHpDef(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int rangeNeed = Experience.getNextCombatLevelRange(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int magicNeed = Experience.getNextCombatLevelMagic(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int prayerNeed = Experience.getNextCombatLevelPrayer(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
// test combat level
assertEquals(43, combatLevel);
// test attack/strength
assertEquals(18, meleeNeed);
// test defence/hitpoints
assertEquals(2, hpDefNeed);
// test ranged
assertEquals(14, rangeNeed);
// test magic
assertEquals(1, magicNeed);
// test prayer
assertEquals(3, prayerNeed);
}
@Test
public void testPlayerZezima()
{
// snapshot of current stats 2018-10-3
// Zezima cannot earn a combat level from ranged/magic anymore, so it won't show as the result is too high
int attackLevel = 74;
int strengthLevel = 74;
int defenceLevel = 72;
int hitpointsLevel = 72;
int magicLevel = 60;
int rangeLevel = 44;
int prayerLevel = 52;
int combatLevel = Experience.getCombatLevel(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int meleeNeed = Experience.getNextCombatLevelMelee(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int hpDefNeed = Experience.getNextCombatLevelHpDef(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int prayerNeed = Experience.getNextCombatLevelPrayer(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
// test combat level
assertEquals(90, combatLevel);
// test attack/strength
assertEquals(2, meleeNeed);
// test defence/hitpoints
assertEquals(2, hpDefNeed);
// test prayer
assertEquals(4, prayerNeed);
}
@Test
public void testPrayerLevelsNeeded()
{
int attackLevel = 99;
int strengthLevel = 99;
int defenceLevel = 99;
int hitpointsLevel = 99;
int magicLevel = 99;
int rangeLevel = 99;
int prayerLevel = 89;
int combatLevel = Experience.getCombatLevel(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int prayerNeed = Experience.getNextCombatLevelPrayer(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
// test combat level
assertEquals(124, combatLevel);
// test prayer
assertEquals(1, prayerNeed);
}
@Test
public void testEvenPrayerLevelsNeededWhenNearNextCombatLevel()
{
int attackLevel = 74;
int strengthLevel = 75;
int defenceLevel = 72;
int hitpointsLevel = 72;
int magicLevel = 60;
int rangeLevel = 44;
int prayerLevel = 52;
int combatLevel = Experience.getCombatLevel(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int prayerNeed = Experience.getNextCombatLevelPrayer(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
// test combat level
assertEquals(90, combatLevel);
// test prayer
assertEquals(2, prayerNeed);
}
@Test
public void testOddPrayerLevelsNeededWhenNearNextCombatLevel()
{
int attackLevel = 74;
int strengthLevel = 75;
int defenceLevel = 72;
int hitpointsLevel = 72;
int magicLevel = 60;
int rangeLevel = 44;
int prayerLevel = 53;
int combatLevel = Experience.getCombatLevel(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int prayerNeed = Experience.getNextCombatLevelPrayer(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
// test combat level
assertEquals(90, combatLevel);
// test prayer
assertEquals(1, prayerNeed);
}
@Test
public void testNextMagicLevelBarelyReachesNextCombatLevel()
{
int attackLevel = 40;
int strengthLevel = 44;
int defenceLevel = 46;
int hitpointsLevel = 39;
int magicLevel = 57;
int rangeLevel = 40;
int prayerLevel = 29;
int combatLevel = Experience.getCombatLevel(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int meleeNeed = Experience.getNextCombatLevelMelee(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int hpDefNeed = Experience.getNextCombatLevelHpDef(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int rangeNeed = Experience.getNextCombatLevelRange(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int magicNeed = Experience.getNextCombatLevelMagic(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int prayerNeed = Experience.getNextCombatLevelPrayer(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
// test combat level
assertEquals(52, combatLevel);
// test attack/strength
assertEquals(3, meleeNeed);
// test defence/hitpoints
assertEquals(3, hpDefNeed);
// test ranged
assertEquals(18, rangeNeed);
// test magic
assertEquals(1, magicNeed);
// test prayer
assertEquals(5, prayerNeed);
}
@Test
public void testRangeMagicLevelsNeeded()
{
int attackLevel = 60;
int strengthLevel = 69;
int defenceLevel = 1;
int hitpointsLevel = 78;
int magicLevel = 85;
int rangeLevel = 85;
int prayerLevel = 52;
int combatLevel = Experience.getCombatLevel(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int meleeNeed = Experience.getNextCombatLevelMelee(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int hpDefNeed = Experience.getNextCombatLevelHpDef(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int rangeNeed = Experience.getNextCombatLevelRange(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int magicNeed = Experience.getNextCombatLevelMagic(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
int prayerNeed = Experience.getNextCombatLevelPrayer(attackLevel, strengthLevel, defenceLevel, hitpointsLevel,
magicLevel, rangeLevel, prayerLevel);
// test combat level
assertEquals(68, combatLevel);
// test attack/strength
assertEquals(3, meleeNeed);
// test defence/hitpoints
assertEquals(4, hpDefNeed);
// test ranged
assertEquals(3, rangeNeed);
// test magic
assertEquals(3, magicNeed);
// test prayer
assertEquals(8, prayerNeed);
}
}

View File

@@ -1,133 +0,0 @@
/*
* 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.SpotAnimationChanged;
import net.runelite.client.config.OpenOSRSConfig;
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."
};
@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;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@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);
}
CookingSession cookingSession = cookingPlugin.getSession();
assertNotNull(cookingSession);
assertEquals(COOKING_MESSAGES.length, cookingSession.getCookAmount());
}
@Test
public void testOnSpotAnimationChanged()
{
Player player = mock(Player.class);
when(player.getSpotAnimation()).thenReturn(GraphicID.WINE_MAKE);
cookingPlugin.setFermentTimer(true);
when(client.getLocalPlayer()).thenReturn(player);
SpotAnimationChanged graphicChanged = new SpotAnimationChanged();
graphicChanged.setActor(player);
cookingPlugin.onSpotAnimationChanged(graphicChanged);
verify(infoBoxManager).addInfoBox(any(FermentTimer.class));
}
}

View File

@@ -1,136 +0,0 @@
/*
* 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.emojis;
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 net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.IndexedSprite;
import net.runelite.api.MessageNode;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameStateChanged;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.config.OpenOSRSConfig;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Before;
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 EmojiPluginTest
{
@Mock
@Bind
private Client client;
@Mock
@Bind
private ChatMessageManager chatMessageManager;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Inject
private EmojiPlugin emojiPlugin;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testOnChatMessage()
{
when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
when(client.getModIcons()).thenReturn(new IndexedSprite[0]);
when(client.createIndexedSprite()).thenReturn(mock(IndexedSprite.class));
// Trip emoji loading
GameStateChanged gameStateChanged = new GameStateChanged();
gameStateChanged.setGameState(GameState.LOGGED_IN);
emojiPlugin.onGameStateChanged(gameStateChanged);
MessageNode messageNode = mock(MessageNode.class);
// With chat recolor, message may be wrapped in col tags
when(messageNode.getValue()).thenReturn("<col=ff0000>:) :) :)</col>");
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setMessageNode(messageNode);
emojiPlugin.onChatMessage(chatMessage);
verify(messageNode).setRuneLiteFormatMessage("<col=ff0000><img=0> <img=0> <img=0></col>");
}
@Test
public void testGtLt()
{
when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
when(client.getModIcons()).thenReturn(new IndexedSprite[0]);
when(client.createIndexedSprite()).thenReturn(mock(IndexedSprite.class));
// Trip emoji loading
GameStateChanged gameStateChanged = new GameStateChanged();
gameStateChanged.setGameState(GameState.LOGGED_IN);
emojiPlugin.onGameStateChanged(gameStateChanged);
MessageNode messageNode = mock(MessageNode.class);
when(messageNode.getValue()).thenReturn("<gt>:D<lt>");
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setMessageNode(messageNode);
emojiPlugin.onChatMessage(chatMessage);
verify(messageNode).setRuneLiteFormatMessage("<img=10>");
}
@Test
public void testEmojiUpdateMessage()
{
String PARTY_POPPER = "<img=" + (-1 + Emoji.getEmoji("@@@").ordinal()) + '>';
String OPEN_MOUTH = "<img=" + (-1 + Emoji.getEmoji(":O").ordinal()) + '>';
assertNull(emojiPlugin.updateMessage("@@@@@"));
assertEquals(PARTY_POPPER, emojiPlugin.updateMessage("@@@"));
assertEquals(PARTY_POPPER + ' ' + PARTY_POPPER, emojiPlugin.updateMessage("@@@ @@@"));
assertEquals(PARTY_POPPER + ' ' + OPEN_MOUTH, emojiPlugin.updateMessage("@@@\u00A0:O"));
assertEquals(PARTY_POPPER + ' ' + OPEN_MOUTH + ' ' + PARTY_POPPER, emojiPlugin.updateMessage("@@@\u00A0:O @@@"));
assertEquals(PARTY_POPPER + " Hello World " + PARTY_POPPER, emojiPlugin.updateMessage("@@@\u00A0Hello World\u00A0@@@"));
}
}

View File

@@ -1,136 +0,0 @@
/*
* 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.examine;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.ItemID;
import net.runelite.api.MenuOpcode;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.widgets.Widget;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.game.ItemManager;
import net.runelite.http.api.examine.ExamineClient;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class ExaminePluginTest
{
@Inject
ExaminePlugin examinePlugin;
@Mock
@Bind
ExamineClient examineClient;
@Mock
@Bind
Client client;
@Mock
@Bind
ChatMessageManager chatMessageManager;
@Mock
@Bind
ItemManager itemManager;
@Mock
@Bind
ScheduledExecutorService scheduledExecutorService;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testItem()
{
when(client.getWidget(anyInt(), anyInt())).thenReturn(mock(Widget.class));
MenuOptionClicked menuOptionClicked = new MenuOptionClicked(
"Examine",
"Something",
ItemID.ABYSSAL_WHIP,
MenuOpcode.EXAMINE_ITEM.getId(),
123,
456,
false
);
examinePlugin.onMenuOptionClicked(menuOptionClicked);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.ITEM_EXAMINE, "", "A weapon from the abyss.", "", 0);
examinePlugin.onChatMessage(chatMessage);
// This passes due to not mocking the ItemDefinition for the whip
verify(examineClient).submitItem(anyInt(), anyString());
}
@Test
public void testLargeStacks()
{
when(client.getWidget(anyInt(), anyInt())).thenReturn(mock(Widget.class));
MenuOptionClicked menuOptionClicked = new MenuOptionClicked(
"Examine",
"Something",
ItemID.ABYSSAL_WHIP,
MenuOpcode.EXAMINE_ITEM.getId(),
123,
456,
false
);
examinePlugin.onMenuOptionClicked(menuOptionClicked);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.ITEM_EXAMINE, "", "100000 x Abyssal whip", "", 0);
examinePlugin.onChatMessage(chatMessage);
verify(examineClient, never()).submitItem(anyInt(), anyString());
}
}

View File

@@ -1,199 +0,0 @@
/*
* Copyright (c) 2018, 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.gpu;
import com.jogamp.nativewindow.AbstractGraphicsConfiguration;
import com.jogamp.nativewindow.NativeWindowFactory;
import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration;
import com.jogamp.nativewindow.awt.JAWTWindow;
import com.jogamp.opengl.GL4;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLContext;
import com.jogamp.opengl.GLDrawable;
import com.jogamp.opengl.GLDrawableFactory;
import com.jogamp.opengl.GLProfile;
import java.awt.Canvas;
import java.util.function.Function;
import javax.swing.JFrame;
import static net.runelite.client.plugins.gpu.GLUtil.inputStreamToString;
import net.runelite.client.plugins.gpu.template.Template;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
public class ShaderTest
{
private static final String VERTEX_SHADER = "" +
"void main() {" +
" gl_Position = vec4(1.0, 1.0, 1.0, 1.0);" +
"}";
private GL4 gl;
@Before
public void before()
{
Canvas canvas = new Canvas();
JFrame frame = new JFrame();
frame.setSize(100, 100);
frame.add(canvas);
frame.setVisible(true);
GLProfile glProfile = GLProfile.getMaxFixedFunc(true);
GLCapabilities glCaps = new GLCapabilities(glProfile);
AbstractGraphicsConfiguration config = AWTGraphicsConfiguration.create(canvas.getGraphicsConfiguration(),
glCaps, glCaps);
JAWTWindow jawtWindow = (JAWTWindow) NativeWindowFactory.getNativeWindow(canvas, config);
GLDrawableFactory glDrawableFactory = GLDrawableFactory.getFactory(glProfile);
GLDrawable glDrawable = glDrawableFactory.createGLDrawable(jawtWindow);
glDrawable.setRealized(true);
GLContext glContext = glDrawable.createContext(null);
int res = glContext.makeCurrent();
if (res == GLContext.CONTEXT_NOT_CURRENT)
{
fail("error making context current");
}
gl = glContext.getGL().getGL4();
}
@Test
@Ignore
public void testUnordered() throws ShaderException
{
int glComputeProgram = gl.glCreateProgram();
int glComputeShader = gl.glCreateShader(gl.GL_COMPUTE_SHADER);
try
{
Function<String, String> func = (s) -> inputStreamToString(getClass().getResourceAsStream(s));
Template template = new Template(func);
String source = template.process(func.apply("comp_unordered.glsl"));
int line = 0;
for (String str : source.split("\\n"))
{
System.out.println(++line + " " + str);
}
GLUtil.loadComputeShader(gl, glComputeProgram, glComputeShader, source);
}
finally
{
gl.glDeleteShader(glComputeShader);
gl.glDeleteProgram(glComputeProgram);
}
}
@Test
@Ignore
public void testSmall() throws ShaderException
{
int glComputeProgram = gl.glCreateProgram();
int glComputeShader = gl.glCreateShader(gl.GL_COMPUTE_SHADER);
try
{
Function<String, String> func = (s) -> inputStreamToString(getClass().getResourceAsStream(s));
Template template = new Template(func);
String source = template.process(func.apply("comp_small.glsl"));
int line = 0;
for (String str : source.split("\\n"))
{
System.out.println(++line + " " + str);
}
GLUtil.loadComputeShader(gl, glComputeProgram, glComputeShader, source);
}
finally
{
gl.glDeleteShader(glComputeShader);
gl.glDeleteProgram(glComputeProgram);
}
}
@Test
@Ignore
public void testComp() throws ShaderException
{
int glComputeProgram = gl.glCreateProgram();
int glComputeShader = gl.glCreateShader(gl.GL_COMPUTE_SHADER);
try
{
Function<String, String> func = (s) -> inputStreamToString(getClass().getResourceAsStream(s));
Template template = new Template(func);
String source = template.process(func.apply("comp.glsl"));
int line = 0;
for (String str : source.split("\\n"))
{
System.out.println(++line + " " + str);
}
GLUtil.loadComputeShader(gl, glComputeProgram, glComputeShader, source);
}
finally
{
gl.glDeleteShader(glComputeShader);
gl.glDeleteProgram(glComputeProgram);
}
}
@Test
@Ignore
public void testGeom() throws ShaderException
{
int glComputeProgram = gl.glCreateProgram();
int glVertexShader = gl.glCreateShader(gl.GL_VERTEX_SHADER);
int glGeometryShader = gl.glCreateShader(gl.GL_GEOMETRY_SHADER);
int glFragmentShader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER);
try
{
Function<String, String> func = (s) -> inputStreamToString(getClass().getResourceAsStream(s));
Template template = new Template(func);
String source = template.process(func.apply("geom.glsl"));
int line = 0;
for (String str : source.split("\\n"))
{
System.out.println(++line + " " + str);
}
GLUtil.loadShaders(gl, glComputeProgram, glVertexShader, glGeometryShader, glFragmentShader, VERTEX_SHADER, source, "");
}
finally
{
gl.glDeleteShader(glVertexShader);
gl.glDeleteShader(glGeometryShader);
gl.glDeleteShader(glFragmentShader);
gl.glDeleteProgram(glComputeProgram);
}
}
}

View File

@@ -1,62 +0,0 @@
/*
* Copyright (c) 2018, 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.gpu.template;
import java.util.function.Function;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class TemplateTest
{
private static final String FILE1 = "" +
"test1\n" +
"#include file2\n" +
"test3\n";
private static final String FILE2 = "" +
"test4\n" +
"test5\n";
private static final String RESULT = "" +
"test1\n" +
"test4\n" +
"test5\n" +
"test3\n";
@Test
public void testProcess()
{
Function<String, String> func = (String resource) ->
{
if ("file2".equals(resource))
{
return FILE2;
}
throw new RuntimeException("unknown resource");
};
String out = new Template(func).process(FILE1);
assertEquals(RESULT, out);
}
}

View File

@@ -1,54 +0,0 @@
/*
* Copyright (c) 2018, SomeoneWithAnInternetConnection
* 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.grandexchange;
import net.runelite.api.GrandExchangeOffer;
import net.runelite.api.GrandExchangeOfferState;
import net.runelite.api.ItemDefinition;
import net.runelite.client.util.AsyncBufferedImage;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class GrandExchangeOfferSlotTest
{
@Mock
private GrandExchangeOffer offer;
@Test
public void testUpdateOffer()
{
when(offer.getState()).thenReturn(GrandExchangeOfferState.CANCELLED_BUY);
GrandExchangeOfferSlot offerSlot = new GrandExchangeOfferSlot();
offerSlot.updateOffer(mock(ItemDefinition.class), mock(AsyncBufferedImage.class), offer);
}
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright (c) 2018, 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.grounditems;
import java.util.Arrays;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class WildcardMatchLoaderTest
{
@Test
public void testLoad()
{
WildcardMatchLoader loader = new WildcardMatchLoader(Arrays.asList("rune*", "Abyssal whip"));
assertTrue(loader.load("rune pouch"));
assertTrue(loader.load("Rune pouch"));
assertFalse(loader.load("Adamant dagger"));
assertTrue(loader.load("Runeite Ore"));
assertTrue(loader.load("Abyssal whip"));
assertFalse(loader.load("Abyssal dagger"));
}
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright (c) 2017, 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.hiscore;
import org.junit.Test;
public class HiscorePanelTest
{
@Test
public void testConstructor()
{
new HiscorePanel(new HiscorePlugin() {});
}
}

View File

@@ -1,302 +0,0 @@
/*
* 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.idlenotifier;
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.EnumSet;
import net.runelite.api.Actor;
import net.runelite.api.AnimationID;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.Hitsplat;
import net.runelite.api.NPC;
import net.runelite.api.NPCDefinition;
import net.runelite.api.Player;
import net.runelite.api.VarPlayer;
import net.runelite.api.WorldType;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.HitsplatApplied;
import net.runelite.api.events.InteractingChanged;
import net.runelite.client.Notifier;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.game.SoundManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class IdleNotifierPluginTest
{
private static final String PLAYER_NAME = "Deathbeam";
@Mock
@Bind
private Client client;
@Mock
@Bind
private IdleNotifierConfig config;
@Mock
@Bind
private SoundManager soundManager;
@Mock
@Bind
private Notifier notifier;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Inject
private IdleNotifierPlugin plugin;
@Mock
private NPC monster;
@Mock
private NPC randomEvent;
@Mock
private Player player;
@Before
public void setUp()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
// Mock monster
final String[] monsterActions = new String[]{"Attack", "Examine"};
final NPCDefinition monsterComp = mock(NPCDefinition.class);
when(monsterComp.getActions()).thenReturn(monsterActions);
when(monster.getDefinition()).thenReturn(monsterComp);
// Mock random event
final String[] randomEventActions = new String[]{"Talk-to", "Dismiss", "Examine"};
final NPCDefinition randomEventComp = mock(NPCDefinition.class);
when(randomEventComp.getActions()).thenReturn(randomEventActions);
when(randomEvent.getDefinition()).thenReturn(randomEventComp);
// Mock player
when(player.getName()).thenReturn(PLAYER_NAME);
when(player.getAnimation()).thenReturn(AnimationID.IDLE);
when(client.getLocalPlayer()).thenReturn(player);
// Mock config
plugin.setLogoutIdle(true);
plugin.setAnimationIdle(true);
plugin.setInteractionIdle(true);
plugin.setGetIdleNotificationDelay(0);
plugin.setGetHitpointsThreshold(42);
plugin.setGetPrayerThreshold(42);
// Mock client
when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
when(client.getKeyboardIdleTicks()).thenReturn(42);
when(client.getMouseLastPressedMillis()).thenReturn(System.currentTimeMillis() - 100_000L);
when(client.getWorldType()).thenReturn(EnumSet.of(WorldType.DEADMAN));
}
@Test
public void checkAnimationIdle()
{
when(player.getAnimation()).thenReturn(AnimationID.WOODCUTTING_BRONZE);
AnimationChanged animationChanged = new AnimationChanged();
animationChanged.setActor(player);
plugin.onAnimationChanged(animationChanged);
plugin.onGameTick(GameTick.INSTANCE);
when(player.getAnimation()).thenReturn(AnimationID.IDLE);
plugin.onAnimationChanged(animationChanged);
plugin.onGameTick(GameTick.INSTANCE);
verify(notifier).notify("[" + PLAYER_NAME + "] is now idle!");
}
@Test
public void checkAnimationReset()
{
when(player.getAnimation()).thenReturn(AnimationID.WOODCUTTING_BRONZE);
AnimationChanged animationChanged = new AnimationChanged();
animationChanged.setActor(player);
plugin.onAnimationChanged(animationChanged);
plugin.onGameTick(GameTick.INSTANCE);
when(player.getAnimation()).thenReturn(AnimationID.LOOKING_INTO);
plugin.onAnimationChanged(animationChanged);
plugin.onGameTick(GameTick.INSTANCE);
when(player.getAnimation()).thenReturn(AnimationID.IDLE);
plugin.onAnimationChanged(animationChanged);
plugin.onGameTick(GameTick.INSTANCE);
verify(notifier, times(0)).notify(any());
}
@Test
public void checkAnimationLogout()
{
when(player.getAnimation()).thenReturn(AnimationID.WOODCUTTING_BRONZE);
AnimationChanged animationChanged = new AnimationChanged();
animationChanged.setActor(player);
plugin.onAnimationChanged(animationChanged);
plugin.onGameTick(GameTick.INSTANCE);
// Logout
when(client.getGameState()).thenReturn(GameState.LOGIN_SCREEN);
GameStateChanged gameStateChanged = new GameStateChanged();
gameStateChanged.setGameState(GameState.LOGIN_SCREEN);
plugin.onGameStateChanged(gameStateChanged);
// Log back in
when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
gameStateChanged.setGameState(GameState.LOGGED_IN);
plugin.onGameStateChanged(gameStateChanged);
// Tick
when(player.getAnimation()).thenReturn(AnimationID.IDLE);
plugin.onAnimationChanged(animationChanged);
plugin.onGameTick(GameTick.INSTANCE);
verify(notifier, times(0)).notify(any());
}
@Test
public void checkCombatIdle()
{
when(player.getInteracting()).thenReturn(monster);
plugin.onInteractingChanged(new InteractingChanged(player, monster));
plugin.onGameTick(GameTick.INSTANCE);
when(player.getInteracting()).thenReturn(null);
plugin.onInteractingChanged(new InteractingChanged(player, null));
plugin.onGameTick(GameTick.INSTANCE);
verify(notifier).notify("[" + PLAYER_NAME + "] is now out of combat!");
}
@Test
public void checkCombatReset()
{
when(player.getInteracting()).thenReturn(mock(Actor.class));
plugin.onInteractingChanged(new InteractingChanged(player, monster));
plugin.onGameTick(GameTick.INSTANCE);
plugin.onInteractingChanged(new InteractingChanged(player, randomEvent));
plugin.onGameTick(GameTick.INSTANCE);
plugin.onInteractingChanged(new InteractingChanged(player, null));
plugin.onGameTick(GameTick.INSTANCE);
verify(notifier, times(0)).notify(any());
}
@Test
public void checkCombatLogout()
{
plugin.onInteractingChanged(new InteractingChanged(player, monster));
when(player.getInteracting()).thenReturn(mock(Actor.class));
plugin.onGameTick(GameTick.INSTANCE);
// Logout
when(client.getGameState()).thenReturn(GameState.LOGIN_SCREEN);
GameStateChanged gameStateChanged = new GameStateChanged();
gameStateChanged.setGameState(GameState.LOGIN_SCREEN);
plugin.onGameStateChanged(gameStateChanged);
// Log back in
when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
gameStateChanged.setGameState(GameState.LOGGED_IN);
plugin.onGameStateChanged(gameStateChanged);
// Tick
plugin.onInteractingChanged(new InteractingChanged(player, null));
plugin.onGameTick(GameTick.INSTANCE);
verify(notifier, times(0)).notify(any());
}
@Test
public void checkCombatLogoutIdle()
{
// Player is idle
when(client.getMouseIdleTicks()).thenReturn(80_000);
// But player is being damaged (is in combat)
final HitsplatApplied hitsplatApplied = new HitsplatApplied();
hitsplatApplied.setActor(player);
hitsplatApplied.setHitsplat(new Hitsplat(Hitsplat.HitsplatType.DAMAGE, 0, 0));
plugin.onHitsplatApplied(hitsplatApplied);
plugin.onGameTick(GameTick.INSTANCE);
verify(notifier, times(0)).notify(any());
}
@Test
public void doubleNotifyOnMouseReset()
{
// Player is idle, but in combat so the idle packet is getting set repeatedly
// make sure we are not notifying
when(client.getKeyboardIdleTicks()).thenReturn(80_000);
when(client.getMouseIdleTicks()).thenReturn(14_500);
plugin.onGameTick(GameTick.INSTANCE);
plugin.onGameTick(GameTick.INSTANCE);
verify(notifier, times(1)).notify(any());
}
@Test
public void testSpecRegen()
{
plugin.setGetSpecEnergyThreshold(50);
when(client.getVar(eq(VarPlayer.SPECIAL_ATTACK_PERCENT))).thenReturn(400); // 40%
plugin.onGameTick(GameTick.INSTANCE); // once to set lastSpecEnergy to 400
verify(notifier, never()).notify(any());
when(client.getVar(eq(VarPlayer.SPECIAL_ATTACK_PERCENT))).thenReturn(500); // 50%
plugin.onGameTick(GameTick.INSTANCE);
verify(notifier).notify(eq("[" + PLAYER_NAME + "] has restored spec energy!"));
}
@Test
public void testMovementIdle()
{
plugin.setMovementIdle(true);
when(player.getWorldLocation()).thenReturn(new WorldPoint(0, 0, 0));
plugin.onGameTick(GameTick.INSTANCE);
when(player.getWorldLocation()).thenReturn(new WorldPoint(1, 0, 0));
plugin.onGameTick(GameTick.INSTANCE);
// No movement here
plugin.onGameTick(GameTick.INSTANCE);
verify(notifier).notify(eq("[" + PLAYER_NAME + "] has stopped moving!"));
}
}

View File

@@ -1,156 +0,0 @@
/*
* Copyright (c) 2018, 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.itemcharges;
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.concurrent.ScheduledExecutorService;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.EquipmentInventorySlot;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import net.runelite.api.events.ChatMessage;
import net.runelite.client.Notifier;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.config.RuneLiteConfig;
import net.runelite.client.ui.overlay.OverlayManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.ArgumentMatchers.eq;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class ItemChargePluginTest
{
private static final String CHECK = "Your dodgy necklace has 10 charges left.";
private static final String PROTECT = "Your dodgy necklace protects you. It has 9 charges left.";
private static final String PROTECT_1 = "Your dodgy necklace protects you. <col=ff0000>It has 1 charge left.</col>";
private static final String BREAK = "Your dodgy necklace protects you. <col=ff0000>It then crumbles to dust.</col>";
private static final String CHECK_RING_OF_FORGING_FULL = "You can smelt 140 more pieces of iron ore before a ring melts.";
private static final String CHECK_RING_OF_FORGING_ONE = "You can smelt one more piece of iron ore before a ring melts.";
private static final String USED_RING_OF_FORGING = "You retrieve a bar of iron.";
private static final String BREAK_RING_OF_FORGING = "<col=7f007f>Your Ring of Forging has melted.</col>";
@Mock
@Bind
private Client client;
@Mock
@Bind
private ScheduledExecutorService scheduledExecutorService;
@Mock
@Bind
private RuneLiteConfig runeLiteConfig;
@Mock
@Bind
private OverlayManager overlayManager;
@Mock
@Bind
private Notifier notifier;
@Mock
@Bind
private ItemChargeConfig config;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Inject
private ItemChargePlugin itemChargePlugin;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testOnChatMessage()
{
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHECK, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).dodgyNecklace(eq(10));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", PROTECT, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).dodgyNecklace(eq(9));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", PROTECT_1, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).dodgyNecklace(eq(1));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", BREAK, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).dodgyNecklace(eq(10));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHECK_RING_OF_FORGING_ONE, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).ringOfForging(eq(1));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHECK_RING_OF_FORGING_FULL, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).ringOfForging(eq(140));
reset(config);
// Create equipment inventory with ring of forging
ItemContainer equipmentItemContainer = mock(ItemContainer.class);
when(client.getItemContainer(eq(InventoryID.EQUIPMENT))).thenReturn(equipmentItemContainer);
Item[] items = new Item[EquipmentInventorySlot.RING.getSlotIdx() + 1];
when(equipmentItemContainer.getItems()).thenReturn(items);
Item ring = new Item(ItemID.RING_OF_FORGING, 1);
items[EquipmentInventorySlot.RING.getSlotIdx()] = ring;
// Run message
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", USED_RING_OF_FORGING, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).ringOfForging(eq(139));
reset(config);
chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", BREAK_RING_OF_FORGING, "", 0);
itemChargePlugin.onChatMessage(chatMessage);
verify(config).ringOfForging(eq(140));
reset(config);
}
}

View File

@@ -1,690 +0,0 @@
/*
* Copyright (c) 2019, TheStonedTurtle <https://github.com/TheStonedTurtle>
* 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.itemskeptondeath;
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 java.util.Collections;
import java.util.List;
import net.runelite.api.Client;
import net.runelite.api.Item;
import net.runelite.api.ItemDefinition;
import net.runelite.api.ItemID;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.ItemReclaimCost;
import static net.runelite.client.plugins.itemskeptondeath.ItemsKeptOnDeathPlugin.DeathItems;
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.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class ItemsKeptOnDeathPluginTest
{
@Mock
@Bind
private Client client;
@Mock
@Bind
private ItemManager itemManager;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Inject
private ItemsKeptOnDeathPlugin plugin;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
resetBuffs();
}
private void resetBuffs()
{
plugin.isSkulled = false;
plugin.protectingItem = false;
plugin.wildyLevel = -1;
}
// Mocks an item and the necessary itemManager functions for it
private Item mItem(final int id, final int qty, final String name, final boolean tradeable, final int price)
{
// Mock Item Composition and necessary ItemManager methods for this item
ItemDefinition c = mock(ItemDefinition.class);
when(c.getId())
.thenReturn(id);
when(c.getName())
.thenReturn(name);
when(c.isTradeable())
.thenReturn(tradeable);
when(c.getPrice())
.thenReturn(price);
if (!tradeable)
{
when(c.getNote()).thenReturn(-1);
when(c.getLinkedNoteId()).thenReturn(-1);
}
when(itemManager.getItemDefinition(id)).thenReturn(c);
when(itemManager.canonicalize(id)).thenReturn(id);
when(itemManager.getItemPrice(id, true)).thenReturn(price);
return item(id, qty);
}
// Creates a new item
private static Item item(final int id, final int qty)
{
return new Item(id, qty);
}
@Test
public void deathPriceTestRegularItems()
{
final Item acs = mItem(ItemID.ARMADYL_CHAINSKIRT, 1, "Armadyl chainskirt", true, 27837495);
assertEquals(27837495, plugin.getDeathPrice(acs));
final Item karambwan = mItem(ItemID.COOKED_KARAMBWAN, 1, "Cooked karambwan", true, 608);
assertEquals(608, plugin.getDeathPrice(karambwan));
final Item defender = mItem(ItemID.RUNE_DEFENDER, 1, "Rune defender", false, 35000);
assertEquals(35000, plugin.getDeathPrice(defender));
}
@Test
public void deathPriceTestItemMapping()
{
mItem(ItemID.OCCULT_NECKLACE, 1, "Occult necklace", true, 1000000);
mItem(ItemID.OCCULT_ORNAMENT_KIT, 1, "Occult ornament kit", true, 3000000);
final Item occult = mItem(ItemID.OCCULT_NECKLACE_OR, 1, "Occult necklace (or)", false, 0);
assertEquals(4000000, plugin.getDeathPrice(occult));
mItem(ItemID.BLACK_MASK, 1, "Black mask", true, 1000000);
final Item blackMask8 = mItem(ItemID.BLACK_MASK_8, 1, "Black mask (8)", false, 0);
assertEquals(1000000, plugin.getDeathPrice(blackMask8));
final Item slayerHelm = mItem(ItemID.SLAYER_HELMET, 1, "Slayer helmet", false, 0);
assertEquals(1000000, plugin.getDeathPrice(slayerHelm));
}
@Test
public void deathPriceTestFixedPriceItems()
{
mItem(ItemID.KARILS_COIF_0, 1, "Karil's coif 0", true, 35000);
final Item coif = mItem(ItemID.KARILS_COIF_100, 1, "Karil's coif 100", false, 0);
final int coifOffset = FixedPriceItem.KARILS_COIF_100.getOffset();
assertEquals(35000 + coifOffset, plugin.getDeathPrice(coif));
mItem(ItemID.AHRIMS_ROBETOP_0, 1, "Ahrim's robetop 0", true, 2500000);
final Item robetop = mItem(ItemID.AHRIMS_ROBETOP_25, 1, "Ahrim's robetop 100", false, 0);
final int robetopOffset = FixedPriceItem.AHRIMS_ROBETOP_25.getOffset();
assertEquals(2500000 + robetopOffset, plugin.getDeathPrice(robetop));
mItem(ItemID.AMULET_OF_GLORY, 1, "Amulet of glory", true, 13000);
final Item glory = mItem(ItemID.AMULET_OF_GLORY3, 1, "Amulet of glory(3)", true, 0);
final int gloryOffset = FixedPriceItem.AMULET_OF_GLORY3.getOffset();
assertEquals(13000 + gloryOffset, plugin.getDeathPrice(glory));
mItem(ItemID.COMBAT_BRACELET, 1, "Combat bracelet", true, 13500);
final Item brace = mItem(ItemID.COMBAT_BRACELET1, 1, "Combat bracelet(1)", true, 0);
final int braceletOffset = FixedPriceItem.COMBAT_BRACELET1.getOffset();
assertEquals(13500 + braceletOffset, plugin.getDeathPrice(brace));
final Item amulet = mItem(ItemID.SALVE_AMULETEI, 1, "Salve Amulet(ei)", false, 300);
assertEquals(210200, plugin.getDeathPrice(amulet));
}
@Test
public void deathPriceTestDynamicPriceItems()
{
final Item rod8 = mItem(ItemID.RING_OF_DUELING8, 1, "Ring of dueling(8)", true, 725);
final Item rod3 = mItem(ItemID.RING_OF_DUELING3, 1, "Ring of dueling(3)", true, 0);
final Item rod1 = mItem(ItemID.RING_OF_DUELING1, 1, "Ring of dueling(1)", true, 0);
// Dynamic price items
final int rodPrice = 725 / 8;
assertEquals(rodPrice, plugin.getDeathPrice(rod1));
assertEquals(725, plugin.getDeathPrice(rod8));
assertEquals(rodPrice * 3, plugin.getDeathPrice(rod3));
final Item nop5 = mItem(ItemID.NECKLACE_OF_PASSAGE5, 1, "Necklace of passage(5)", true, 1250);
final Item nop4 = mItem(ItemID.NECKLACE_OF_PASSAGE4, 1, "Necklace of passage(4)", true, 0);
final Item nop2 = mItem(ItemID.NECKLACE_OF_PASSAGE2, 1, "Necklace of passage(2)", true, 0);
final int nopPrice = 1250 / 5;
assertEquals(nopPrice * 2, plugin.getDeathPrice(nop2));
assertEquals(nopPrice * 4, plugin.getDeathPrice(nop4));
assertEquals(1250, plugin.getDeathPrice(nop5));
}
private Item[] getFourExpensiveItems()
{
return new Item[]
{
mItem(ItemID.TWISTED_BOW, 1, "Twister bow", true, Integer.MAX_VALUE),
mItem(ItemID.SCYTHE_OF_VITUR, 1, "Scythe of vitur", true, Integer.MAX_VALUE),
mItem(ItemID.ELYSIAN_SPIRIT_SHIELD, 1, "Elysian spirit shield", true, 800000000),
mItem(ItemID.ARCANE_SPIRIT_SHIELD, 1, "Arcane spirit shield", true, 250000000)
};
}
@Test
public void alwaysLostTestRunePouch()
{
final Item[] inv = getFourExpensiveItems();
final Item[] equip = new Item[]
{
mItem(ItemID.RUNE_POUCH, 1, "Rune pouch", false, 1)
};
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
assertFalse(deathItems.isHasAlwaysLost());
}
@Test
public void alwaysLostTestRunePouchWildy()
{
final Item[] inv = getFourExpensiveItems();
final Item[] equip = new Item[]
{
mItem(ItemID.RUNE_POUCH, 1, "Rune pouch", false, 1)
};
plugin.wildyLevel = 1;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
assertTrue(deathItems.isHasAlwaysLost());
}
@Test
public void alwaysLostTestLootBag()
{
final Item[] inv = getFourExpensiveItems();
final Item[] equip = new Item[]
{
mItem(ItemID.LOOTING_BAG, 1, "Looting bag", false, 1)
};
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
assertTrue(deathItems.isHasAlwaysLost());
}
@Test
public void alwaysLostTestLootBagWildy()
{
final Item[] inv = getFourExpensiveItems();
final Item[] equip = new Item[]
{
mItem(ItemID.LOOTING_BAG, 1, "Looting bag", false, 1)
};
plugin.wildyLevel = 1;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
assertTrue(deathItems.isHasAlwaysLost());
}
private Item[] getClueBoxTestInventory()
{
return new Item[]
{
mItem(ItemID.BLACK_DHIDE_BODY, 1, "Black d'hide body", true, 7552),
mItem(ItemID.ARMADYL_CHAINSKIRT, 1, "Armadyl chainskirt", true, 27837495),
mItem(ItemID.PEGASIAN_BOOTS, 1, "Pegasian boots", true, 30542187),
mItem(ItemID.DRAGON_SCIMITAR, 1, "Dragon scimitar", true, 63123),
mItem(ItemID.HELM_OF_NEITIZNOT, 1, "Helm of neitiznot", true, 45519),
mItem(ItemID.RUNE_DEFENDER, 1, "Rune defender", false, 35000),
mItem(ItemID.SPADE, 1, "Spade", true, 104),
mItem(ItemID.CLUE_SCROLL_EASY, 1, "Clue scroll (easy)", false, 50),
mItem(ItemID.CLUE_BOX, 1, "Clue box", false, 50),
mItem(ItemID.COOKED_KARAMBWAN, 1, "Cooked karambwan", true, 608),
mItem(ItemID.COOKED_KARAMBWAN, 1, "Cooked karambwan", true, 608),
mItem(ItemID.COOKED_KARAMBWAN, 1, "Cooked karambwan", true, 608),
mItem(ItemID.COOKED_KARAMBWAN, 1, "Cooked karambwan", true, 608),
mItem(ItemID.COOKED_KARAMBWAN, 1, "Cooked karambwan", true, 608),
mItem(ItemID.LAW_RUNE, 200, "Law rune", true, 212),
mItem(ItemID.DUST_RUNE, 200, "Dust rune", true, 3),
mItem(ItemID.CLUE_SCROLL_MASTER, 1, "Clue scroll (master)", false, 50),
mItem(ItemID.CLUELESS_SCROLL, 1, "Clueless scroll", false, 50),
};
}
@Test
public void isClueBoxableTest()
{
getClueBoxTestInventory();
mItem(ItemID.REWARD_CASKET_EASY, 1, "Reward casket (easy)", false, 50);
assertTrue(plugin.isClueBoxable(ItemID.CLUE_SCROLL_EASY));
assertTrue(plugin.isClueBoxable(ItemID.CLUE_SCROLL_MASTER));
assertTrue(plugin.isClueBoxable(ItemID.REWARD_CASKET_EASY));
assertFalse(plugin.isClueBoxable(ItemID.CLUELESS_SCROLL));
assertFalse(plugin.isClueBoxable(ItemID.LAW_RUNE));
assertFalse(plugin.isClueBoxable(ItemID.SPADE));
}
@Test
public void clueBoxTestDefault()
{
final Item[] inv = getClueBoxTestInventory();
final Item[] equip = new Item[0];
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> kept = deathItems.getKeptItems();
final List<ItemStack> expectedKept = Arrays.asList(
new ItemStack(ItemID.PEGASIAN_BOOTS, 1),
new ItemStack(ItemID.ARMADYL_CHAINSKIRT, 1),
new ItemStack(ItemID.DRAGON_SCIMITAR, 1),
new ItemStack(ItemID.RUNE_DEFENDER, 1),
new ItemStack(ItemID.CLUE_SCROLL_EASY, 1),
new ItemStack(ItemID.CLUE_SCROLL_MASTER, 1),
new ItemStack(ItemID.CLUELESS_SCROLL, 1)
);
assertEquals(expectedKept, kept);
final List<ItemStack> lost = deathItems.getLostItems();
assertEquals((inv.length + equip.length) - expectedKept.size(), lost.size());
}
@Test
public void clueBoxTestDeepWildy()
{
final Item[] inv = getClueBoxTestInventory();
final Item[] equip = new Item[0];
plugin.wildyLevel = 21;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> kept = deathItems.getKeptItems();
final List<ItemStack> expectedKept = Arrays.asList(
new ItemStack(ItemID.PEGASIAN_BOOTS, 1),
new ItemStack(ItemID.ARMADYL_CHAINSKIRT, 1),
new ItemStack(ItemID.DRAGON_SCIMITAR, 1),
new ItemStack(ItemID.CLUE_SCROLL_MASTER, 1)
);
assertEquals(expectedKept, kept);
final List<ItemStack> lost = deathItems.getLostItems();
final int keptOffset = expectedKept.size();
assertEquals((inv.length + equip.length) - keptOffset, lost.size());
}
@Test
public void clueBoxTestDeepWildyProtectItem()
{
final Item[] inv = getClueBoxTestInventory();
final Item[] equip = new Item[0];
plugin.wildyLevel = 21;
plugin.protectingItem = true;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> kept = deathItems.getKeptItems();
final List<ItemStack> expectedKept = Arrays.asList(
new ItemStack(ItemID.PEGASIAN_BOOTS, 1),
new ItemStack(ItemID.ARMADYL_CHAINSKIRT, 1),
new ItemStack(ItemID.DRAGON_SCIMITAR, 1),
new ItemStack(ItemID.HELM_OF_NEITIZNOT, 1),
new ItemStack(ItemID.CLUE_SCROLL_MASTER, 1) // Clue box
);
assertEquals(expectedKept, kept);
final List<ItemStack> lost = deathItems.getLostItems();
final int keptOffset = expectedKept.size();
assertEquals((inv.length + equip.length) - keptOffset, lost.size());
}
@Test
public void clueBoxTestDeepWildySkulled()
{
final Item[] inv = getClueBoxTestInventory();
final Item[] equip = new Item[0];
plugin.wildyLevel = 21;
plugin.isSkulled = true;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> kept = deathItems.getKeptItems();
final List<ItemStack> expectedKept = Collections.singletonList(
new ItemStack(ItemID.CLUE_SCROLL_MASTER, 1)
);
assertEquals(expectedKept, kept);
final List<ItemStack> lost = deathItems.getLostItems();
final int keptOffset = expectedKept.size();
assertEquals(lost.size(), (inv.length + equip.length) - keptOffset);
}
@Test
public void clueBoxTestLowWildy()
{
final Item[] inv = getClueBoxTestInventory();
final Item[] equip = new Item[0];
plugin.wildyLevel = 1;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> kept = deathItems.getKeptItems();
final List<ItemStack> expectedKept = Arrays.asList(
new ItemStack(ItemID.PEGASIAN_BOOTS, 1),
new ItemStack(ItemID.ARMADYL_CHAINSKIRT, 1),
new ItemStack(ItemID.DRAGON_SCIMITAR, 1),
new ItemStack(ItemID.RUNE_DEFENDER, 1), // Rune defender protected because of broken variant
new ItemStack(ItemID.CLUE_SCROLL_MASTER, 1)
);
assertEquals(expectedKept, kept);
final List<ItemStack> lost = deathItems.getLostItems();
final int keptOffset = expectedKept.size();
assertEquals(lost.size(), (inv.length + equip.length) - keptOffset);
}
@Test
public void clueBoxTestLowWildyProtectItem()
{
final Item[] inv = getClueBoxTestInventory();
final Item[] equip = new Item[0];
plugin.wildyLevel = 1;
plugin.protectingItem = true;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> kept = deathItems.getKeptItems();
final List<ItemStack> expectedKept = Arrays.asList(
new ItemStack(ItemID.PEGASIAN_BOOTS, 1),
new ItemStack(ItemID.ARMADYL_CHAINSKIRT, 1),
new ItemStack(ItemID.DRAGON_SCIMITAR, 1),
new ItemStack(ItemID.HELM_OF_NEITIZNOT, 1),
new ItemStack(ItemID.RUNE_DEFENDER, 1), // Rune defender protected because of broken variant
new ItemStack(ItemID.CLUE_SCROLL_MASTER, 1)
);
assertEquals(expectedKept, kept);
final List<ItemStack> lost = deathItems.getLostItems();
final int keptOffset = expectedKept.size();
assertEquals((inv.length + equip.length) - keptOffset, lost.size());
}
@Test
public void clueBoxTestLowWildySkulled()
{
final Item[] inv = getClueBoxTestInventory();
final Item[] equip = new Item[0];
plugin.wildyLevel = 1;
plugin.isSkulled = true;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> kept = deathItems.getKeptItems();
final List<ItemStack> expectedKept = Arrays.asList(
new ItemStack(ItemID.RUNE_DEFENDER, 1), // Rune defender protected because of broken variant
new ItemStack(ItemID.CLUE_SCROLL_MASTER, 1)
);
assertEquals(expectedKept, kept);
final List<ItemStack> lost = deathItems.getLostItems();
final int keptOffset = expectedKept.size();
assertEquals((inv.length + equip.length) - keptOffset, lost.size());
}
private Item[] getClueBoxCasketTestInventory()
{
// Reward caskets can stack but the clue box should only protect one
return new Item[]
{
mItem(ItemID.BLACK_DHIDE_BODY, 1, "Black d'hide body", true, 7552),
mItem(ItemID.ARMADYL_CHAINSKIRT, 1, "Armadyl chainskirt", true, 27837495),
mItem(ItemID.PEGASIAN_BOOTS, 1, "Pegasian boots", true, 30542187),
mItem(ItemID.DRAGON_SCIMITAR, 1, "Dragon scimitar", true, 63123),
mItem(ItemID.SPADE, 1, "Spade", true, 104),
mItem(ItemID.CLUE_SCROLL_EASY, 1, "Clue scroll (easy)", false, 50),
mItem(ItemID.REWARD_CASKET_EASY, 20, "Reward casket (easy)", false, 50),
mItem(ItemID.CLUE_BOX, 1, "Clue box", false, 50),
mItem(ItemID.COOKED_KARAMBWAN, 1, "Cooked karambwan", true, 608),
mItem(ItemID.COOKED_KARAMBWAN, 1, "Cooked karambwan", true, 608),
mItem(ItemID.COOKED_KARAMBWAN, 1, "Cooked karambwan", true, 608),
mItem(ItemID.COOKED_KARAMBWAN, 1, "Cooked karambwan", true, 608),
mItem(ItemID.LAW_RUNE, 200, "Law rune", true, 212),
mItem(ItemID.DUST_RUNE, 200, "Dust rune", true, 3),
};
}
@Test
public void clueBoxTestCasketProtect()
{
final Item[] inv = getClueBoxCasketTestInventory();
final Item[] equip = new Item[0];
plugin.wildyLevel = 1;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> kept = deathItems.getKeptItems();
final List<ItemStack> expectedKept = Arrays.asList(
new ItemStack(ItemID.PEGASIAN_BOOTS, 1),
new ItemStack(ItemID.ARMADYL_CHAINSKIRT, 1),
new ItemStack(ItemID.DRAGON_SCIMITAR, 1),
new ItemStack(ItemID.REWARD_CASKET_EASY, 1) // Clue box
);
assertEquals(expectedKept, kept);
final List<ItemStack> lost = deathItems.getLostItems();
final int keptOffset = expectedKept.size() - 1; // We are still losing some reward caskets.
assertEquals((inv.length + equip.length) - keptOffset, lost.size());
}
private Item[] getFullGracefulItems()
{
return new Item[]
{
mItem(ItemID.GRACEFUL_HOOD, 1, "Graceful hood", false, 35),
mItem(ItemID.GRACEFUL_CAPE, 1, "Graceful cape", false, 40),
mItem(ItemID.GRACEFUL_TOP, 1, "Graceful top", false, 55),
mItem(ItemID.GRACEFUL_LEGS, 1, "Graceful legs", false, 60),
mItem(ItemID.GRACEFUL_BOOTS, 1, "Graceful boots", false, 40),
mItem(ItemID.GRACEFUL_GLOVES, 1, "Graceful gloves", false, 30),
};
}
@Test
public void gracefulValueTest()
{
final Item[] inv = getFullGracefulItems();
final Item[] equip = new Item[]
{
mItem(ItemID.AMULET_OF_GLORY6, 1, "Amulet of glory (6)", true, 20000)
};
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> kept = deathItems.getKeptItems();
final List<ItemStack> expectedKept = Arrays.asList(
new ItemStack(ItemID.AMULET_OF_GLORY6, 1),
new ItemStack(ItemID.GRACEFUL_CAPE, 1),
new ItemStack(ItemID.GRACEFUL_TOP, 1),
new ItemStack(ItemID.GRACEFUL_LEGS, 1),
new ItemStack(ItemID.GRACEFUL_BOOTS, 1),
new ItemStack(ItemID.GRACEFUL_HOOD, 1),
new ItemStack(ItemID.GRACEFUL_GLOVES, 1)
);
assertEquals(expectedKept, kept);
final List<ItemStack> lost = deathItems.getLostItems();
assertEquals((inv.length + equip.length) - expectedKept.size(), lost.size());
}
@Test
public void gracefulValueTestWildy()
{
final Item[] inv = getFullGracefulItems();
final Item[] equip = new Item[]
{
mItem(ItemID.AMULET_OF_GLORY6, 1, "Amulet of glory (6)", true, 20000)
};
plugin.wildyLevel = 1;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> kept = deathItems.getKeptItems();
final List<ItemStack> expectedKept = Arrays.asList(
new ItemStack(ItemID.AMULET_OF_GLORY6, 1),
new ItemStack(ItemID.GRACEFUL_CAPE, 1),
new ItemStack(ItemID.GRACEFUL_TOP, 1)
);
assertEquals(expectedKept, kept);
final List<ItemStack> lost = deathItems.getLostItems();
assertEquals((inv.length + equip.length) - expectedKept.size(), lost.size());
}
@Test
public void lostIfNotProtectedTestLost()
{
final Item[] inv = getFourExpensiveItems();
final Item[] equip = new Item[]
{
mItem(ItemID.SHADOW_SWORD, 1, "Shadow sword", false, 1)
};
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> lost = deathItems.getLostItems();
assertTrue(lost.contains(new ItemStack(ItemID.SHADOW_SWORD, 1)));
}
@Test
public void lostIfNotProtectedTestKept()
{
final Item[] inv = new Item[]
{
mItem(ItemID.SHADOW_SWORD, 1, "Shadow sword", false, 1)
};
final Item[] equip = new Item[0];
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, equip);
final List<ItemStack> kept = deathItems.getKeptItems();
assertTrue(kept.contains(new ItemStack(ItemID.SHADOW_SWORD, 1)));
}
@Test
public void brokenOnDeathTestRepairPrice()
{
// Dragon defender price should actually be pulled from BrokenOnDeathItem, and be lost on death
final Item[] inv = new Item[]
{
mItem(ItemID.BARROWS_GLOVES, 1, "Barrows gloves", false, 130000),
mItem(ItemID.DRAGON_DEFENDER, 1, "Dragon defender", false, 68007),
mItem(ItemID.DRAGON_SCIMITAR, 1, "Dragon scimitar", true, 63123),
mItem(ItemID.HELM_OF_NEITIZNOT, 1, "Helm of neitiznot", true, 45519),
};
plugin.wildyLevel = 21;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, new Item[0]);
final List<ItemStack> lost = deathItems.getLostItems();
assertTrue(lost.contains(new ItemStack(ItemID.DRAGON_DEFENDER, 1)));
}
@Test
public void avernicDefenderPriceTest()
{
final Item defender = mItem(ItemID.AVERNIC_DEFENDER, 1, "Avernic defender", false, 0);
final int defenderOffset = FixedPriceItem.AVERNIC_DEFENDER.getOffset();
final ItemReclaimCost defenderBrokenPrice = ItemReclaimCost.of(ItemID.AVERNIC_DEFENDER);
final int defenderExpectedPrice = (defenderBrokenPrice == null ? 0 : defenderBrokenPrice.getValue()) + defenderOffset;
assertEquals(defenderExpectedPrice, plugin.getDeathPrice(defender));
final Item[] inv = new Item[]
{
defender,
mItem(ItemID.BERSERKER_RING_I, 1, "Berserker Ring (i)", false, 3042579)
};
plugin.isSkulled = true;
plugin.protectingItem = true;
plugin.wildyLevel = 21;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, new Item[0]);
final List<ItemStack> kept = deathItems.getKeptItems();
assertTrue(kept.contains(new ItemStack(ItemID.AVERNIC_DEFENDER, 1)));
}
@Test
public void lockedItemTest()
{
// Base item data needs to exist for each locked item tested as the death price is pulled from the base item.
final Item defenderBase = mItem(ItemID.AVERNIC_DEFENDER, 1, "Avernic defender", false, 0);
final Item defenderLocked = mItem(ItemID.AVERNIC_DEFENDER_L, 1, "Avernic defender (l)", false, 0);
assertEquals(plugin.getDeathPrice(defenderBase), plugin.getDeathPrice(defenderLocked));
final Item[] inv = new Item[]
{
defenderLocked,
mItem(ItemID.DRAGON_CLAWS, 1, "Dragon Claws", true, 30042579)
};
plugin.isSkulled = true;
plugin.protectingItem = true;
plugin.wildyLevel = 21;
final DeathItems deathItems = plugin.calculateKeptLostItems(inv, new Item[0]);
final List<ItemStack> kept = deathItems.getKeptItems();
assertEquals(inv.length, kept.size());
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright (c) 2016-2018, 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.itemstats;
import org.junit.Test;
public class ItemStatChangesTest
{
@Test
public void testInit()
{
new ItemStatChanges();
}
}

View File

@@ -1,69 +0,0 @@
/*
* Copyright (c) 2019, Bartvollebregt <https://github.com/Bartvollebregt>
* 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.maxhit.calculators;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import net.runelite.api.Client;
import net.runelite.client.plugins.maxhit.calculators.testconfig.MagicMaxHitConfig;
import net.runelite.client.plugins.maxhit.calculators.testconfig.MaxHitConfig;
import net.runelite.client.plugins.maxhit.calculators.testconfig.MeleeMaxHitConfig;
import net.runelite.client.plugins.maxhit.calculators.testconfig.RangeMaxHitConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MaxHitCalculatorTest
{
@Mock
@Bind
protected Client client;
@Before
public void setUp()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void calculate()
{
testMaxHitConfig(MeleeMaxHitConfig.values());
testMaxHitConfig(RangeMaxHitConfig.values());
testMaxHitConfig(MagicMaxHitConfig.values());
}
private void testMaxHitConfig(MaxHitConfig[] maxHitConfigs)
{
for (MaxHitConfig maxHitConfig : maxHitConfigs)
{
maxHitConfig.test(client);
}
}
}

View File

@@ -1,248 +0,0 @@
/*
* Copyright (c) 2019, Bartvollebregt <https://github.com/Bartvollebregt>
* 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.maxhit.calculators.testconfig;
import net.runelite.api.Client;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import net.runelite.api.Skill;
import net.runelite.api.Varbits;
import net.runelite.client.plugins.maxhit.calculators.MagicMaxHitCalculator;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public enum MagicMaxHitConfig implements MaxHitConfig
{
TRIDENT_SLAYER(new int[]{75, 83, 99}, 0, new Item[]
{
mockItem(ItemID.SLAYER_HELMET_I),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.OCCULT_NECKLACE),
mockItem(ItemID.TRIDENT_OF_THE_SEAS),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, new int[]{25, 27, 34}),
TRIDENT_OF_SEAS(new int[]{75, 83, 99}, 0, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.TRIDENT_OF_THE_SEAS),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, new int[]{20, 22, 28}),
TRIDENT_OF_SWAMP(new int[]{75, 83, 99}, 0, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.TRIDENT_OF_THE_SWAMP),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, new int[]{23, 25, 31}),
MAGIC_DART(new int[]{75, 83, 99}, 18, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.SLAYERS_STAFF),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, new int[]{17, 18, 19}),
FIRE_BOLT(75, 8, new Item[]
{
mockItem(ItemID.SLAYER_HELMET_I),
mockItem(ItemID.IMBUED_SARADOMIN_CAPE),
mockItem(ItemID.OCCULT_NECKLACE),
mockItem(ItemID.STAFF_OF_THE_DEAD),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.TOME_OF_FIRE),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.CHAOS_GAUNTLETS),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, 31),
WIND_BLAST(75, 9, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.STAFF_OF_AIR),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, 13),
EARTH_WAVE(75, 15, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.OCCULT_NECKLACE),
mockItem(ItemID.STAFF_OF_EARTH),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.TOME_OF_FIRE),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, 20),
FLAMES_OF_ZAMORAK(75, 20, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.STAFF_OF_THE_DEAD),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, 23),
SARADOMIN_STRIKE(75, 52, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.STAFF_OF_LIGHT),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, 23),
;
private final int[] magicLevels;
private final int spellId;
private final Item[] equipedItems;
private final int[] expectedMaxHits;
MagicMaxHitConfig(int magicLevel, int spellId, Item[] equipedItems, int expectedMaxHit)
{
this.magicLevels = new int[]{magicLevel};
this.spellId = spellId;
this.equipedItems = equipedItems;
this.expectedMaxHits = new int[]{expectedMaxHit};
}
MagicMaxHitConfig(int[] magicLevels, int spellId, Item[] equipedItems, int[] expectedMaxHits)
{
this.magicLevels = magicLevels;
this.spellId = spellId;
this.equipedItems = equipedItems;
this.expectedMaxHits = expectedMaxHits;
}
private static Item mockItem(int itemId)
{
Item item = mock(Item.class);
when(item.getId()).thenReturn(itemId);
return item;
}
public void test(Client client)
{
int[] magicLevels = this.magicLevels;
for (int i = 0, magicLevelsLength = magicLevels.length; i < magicLevelsLength; i++)
{
int magicLevel = magicLevels[i];
int expectedMaxHit = this.expectedMaxHits[i];
// Mock equipment container
ItemContainer equipmentContainer = mock(ItemContainer.class);
when(equipmentContainer.getItems())
.thenReturn(this.equipedItems);
when(client.getItemContainer(InventoryID.EQUIPMENT)).thenReturn(equipmentContainer);
// Mock Varbits
when(client.getBoostedSkillLevel(Skill.MAGIC)).thenReturn(magicLevel);
when(client.getVar(Varbits.AUTO_CAST_SPELL)).thenReturn(this.spellId);
// Test
MagicMaxHitCalculator maxHitCalculator = new MagicMaxHitCalculator(client, this.equipedItems);
assertEquals(this.toString(), expectedMaxHit, maxHitCalculator.getMaxHit(), 0);
}
}
}

View File

@@ -1,32 +0,0 @@
/*
* Copyright (c) 2019, Bartvollebregt <https://github.com/Bartvollebregt>
* 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.maxhit.calculators.testconfig;
import net.runelite.api.Client;
public interface MaxHitConfig
{
void test(Client client);
}

View File

@@ -1,223 +0,0 @@
/*
* Copyright (c) 2019, Bartvollebregt <https://github.com/Bartvollebregt>
* 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.maxhit.calculators.testconfig;
import net.runelite.api.Client;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import net.runelite.api.Skill;
import net.runelite.api.VarPlayer;
import net.runelite.api.Varbits;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.plugins.attackstyles.WeaponType;
import net.runelite.client.plugins.maxhit.calculators.MeleeMaxHitCalculator;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public enum MeleeMaxHitConfig implements MaxHitConfig
{
DRAGON_SCIMITAR(new int[]{75, 83, 99}, 66, WeaponType.TYPE_9, 1, new Item[]
{
mockItem(ItemID.IRON_FULL_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.DRAGON_SCIMITAR),
mockItem(ItemID.IRON_PLATEBODY),
mockItem(ItemID.IRON_KITESHIELD),
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[]{17, 19, 22}),
DRAGON_SCIMITAR_DEFENDER(new int[]{75, 83, 99}, 76, WeaponType.TYPE_9, 1, new Item[]
{
mockItem(ItemID.IRON_FULL_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.DRAGON_SCIMITAR),
mockItem(ItemID.IRON_PLATEBODY),
mockItem(ItemID.DRAGON_DEFENDER),
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[]{19, 21, 24}),
DRAGON_SCIMITAR_COMPLETE(new int[]{75, 83, 99}, 108, WeaponType.TYPE_9, 1, new Item[]
{
mockItem(ItemID.SLAYER_HELMET),
mockItem(ItemID.FIRE_CAPE),
mockItem(ItemID.AMULET_OF_FURY),
mockItem(ItemID.DRAGON_SCIMITAR),
mockItem(ItemID.FIGHTER_TORSO),
mockItem(ItemID.DRAGON_DEFENDER),
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.BARROWS_GLOVES),
mockItem(ItemID.DRAGON_BOOTS),
mockItem(ItemID.BERSERKER_RING)
}, new int[]{26, 29, 35}),
OBSIDIAN_SET(new int[]{75, 83, 99}, 61, WeaponType.TYPE_17, 2, new Item[]
{
mockItem(ItemID.OBSIDIAN_HELMET),
mockItem(ItemID.OBSIDIAN_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.TOKTZXILAK),
mockItem(ItemID.OBSIDIAN_PLATEBODY),
mockItem(ItemID.TOKTZKETXIL),
null,
mockItem(ItemID.OBSIDIAN_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[]{18, 19, 23}),
DHAROK_SET(new int[]{75, 75, 75, 83, 83, 83, 99, 99, 99}, 105, WeaponType.TYPE_1, 1,
new int[][]{{99, 99}, {1, 99}, {32, 75}, {99, 99}, {1, 99}, {32, 75}, {99, 99}, {1, 99}, {32, 75}},
new Item[]
{
mockItem(ItemID.DHAROKS_HELM_100),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.DHAROKS_GREATAXE_100),
mockItem(ItemID.DHAROKS_PLATEBODY_100),
null,
null,
mockItem(ItemID.DHAROKS_PLATELEGS_100),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[]{23, 45, 30, 25, 49, 33, 29, 57, 38}),
VOID_SET(new int[]{75, 83, 99}, 66, WeaponType.TYPE_9, 1, new Item[]
{
mockItem(ItemID.VOID_MELEE_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.DRAGON_SCIMITAR),
mockItem(ItemID.VOID_KNIGHT_TOP),
mockItem(ItemID.IRON_KITESHIELD),
null,
mockItem(ItemID.VOID_KNIGHT_ROBE),
null,
mockItem(ItemID.VOID_KNIGHT_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[]{19, 21, 25}),
;
private final int[] strengthLevels;
private final WeaponType weaponType;
private final int attackStyleId;
private final Item[] equipedItems;
private final int[] expectedMaxHits;
private final int[][] hitpoints;
private final int meleeEquipmentStrength;
MeleeMaxHitConfig(int[] strengthLevels, int meleeEquipmentStrength, WeaponType weaponType, int attackStyleId, int[][] hitpoints, Item[] equipedItems, int[] expectedMaxHits)
{
this.strengthLevels = strengthLevels;
this.meleeEquipmentStrength = meleeEquipmentStrength;
this.weaponType = weaponType;
this.attackStyleId = attackStyleId;
this.hitpoints = hitpoints;
this.equipedItems = equipedItems;
this.expectedMaxHits = expectedMaxHits;
}
MeleeMaxHitConfig(int[] strengthLevels, int meleeEquipmentStrength, WeaponType weaponType, int attackStyleId, Item[] equipedItems, int[] expectedMaxHits)
{
this.strengthLevels = strengthLevels;
this.hitpoints = new int[strengthLevels.length][2];
this.meleeEquipmentStrength = meleeEquipmentStrength;
this.weaponType = weaponType;
this.attackStyleId = attackStyleId;
this.equipedItems = equipedItems;
this.expectedMaxHits = expectedMaxHits;
}
private static Item mockItem(int itemId)
{
Item item = mock(Item.class);
when(item.getId()).thenReturn(itemId);
return item;
}
public void test(Client client)
{
int[] strengthLevels = this.strengthLevels;
for (int i = 0, strengthLevelsLength = strengthLevels.length; i < strengthLevelsLength; i++)
{
int strengthLevel = strengthLevels[i];
int[] hitpoints = this.hitpoints[i];
int expectedMaxHit = this.expectedMaxHits[i];
// Mock equipment container
ItemContainer equipmentContainer = mock(ItemContainer.class);
when(equipmentContainer.getItems())
.thenReturn(this.equipedItems);
when(client.getItemContainer(InventoryID.EQUIPMENT)).thenReturn(equipmentContainer);
// Mock equipment strength
Widget equipmentWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.EQUIPMENT_MELEE_STRENGTH)).thenReturn(equipmentWidget);
when(equipmentWidget.getText()).thenReturn("Melee strength: " + this.meleeEquipmentStrength);
// Mock Varbits
when(client.getVar(Varbits.EQUIPPED_WEAPON_TYPE)).thenReturn(this.weaponType.ordinal());
when(client.getVar(VarPlayer.ATTACK_STYLE)).thenReturn(this.attackStyleId);
// Mock strength
when(client.getBoostedSkillLevel(Skill.STRENGTH)).thenReturn(strengthLevel);
// Mock hitpoints
when(client.getBoostedSkillLevel(Skill.HITPOINTS)).thenReturn(hitpoints[0]);
when(client.getRealSkillLevel(Skill.HITPOINTS)).thenReturn(hitpoints[1]);
// Test
MeleeMaxHitCalculator maxHitCalculator = new MeleeMaxHitCalculator(client, this.equipedItems);
assertEquals(this.toString(), expectedMaxHit, maxHitCalculator.getMaxHit(), 0);
}
}
}

View File

@@ -1,171 +0,0 @@
/*
* Copyright (c) 2019, Bartvollebregt <https://github.com/Bartvollebregt>
* 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.maxhit.calculators.testconfig;
import net.runelite.api.Client;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import net.runelite.api.Skill;
import net.runelite.api.VarPlayer;
import net.runelite.api.Varbits;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.plugins.maxhit.attackstyle.WeaponType;
import net.runelite.client.plugins.maxhit.calculators.RangeMaxHitCalculator;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public enum RangeMaxHitConfig implements MaxHitConfig
{
MAGIC_SHORTBOW(new int[]{75, 83, 99}, 49, WeaponType.TYPE_3, 1, new Item[]
{
mockItem(ItemID.IRON_FULL_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.MAGIC_SHORTBOW),
mockItem(ItemID.IRON_PLATEBODY),
null,
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING),
mockItem(ItemID.RUNE_ARROW)
}, new int[]{15, 16, 19}),
RUNE_CROSSBOW(new int[]{75, 83, 99}, 115, WeaponType.TYPE_5, 0, new Item[]
{
mockItem(ItemID.IRON_FULL_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.RUNE_CROSSBOW),
mockItem(ItemID.IRON_PLATEBODY),
null,
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING),
mockItem(ItemID.RUNITE_BOLTS)
}, new int[]{24, 26, 31}),
BLOwPIPE(new int[]{75, 83, 99}, 50, WeaponType.TYPE_19, 1, new Item[]
{
mockItem(ItemID.IRON_FULL_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.TOXIC_BLOWPIPE),
mockItem(ItemID.IRON_PLATEBODY),
null,
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[]{15, 16, 19}),
VOID_SET(new int[]{75, 83, 99}, 115, WeaponType.TYPE_5, 1, new Item[]
{
mockItem(ItemID.VOID_RANGER_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.RUNE_CROSSBOW),
mockItem(ItemID.VOID_KNIGHT_TOP),
mockItem(ItemID.IRON_KITESHIELD),
null,
mockItem(ItemID.VOID_KNIGHT_ROBE),
null,
mockItem(ItemID.VOID_KNIGHT_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[]{26, 28, 33}),
;
private final int[] rangeLevels;
private final WeaponType weaponType;
private final int attackStyleId;
private final Item[] equipedItems;
private final int[] expectedMaxHits;
private final int ammoEquipmentStrength;
RangeMaxHitConfig(int[] rangeLevels, int ammoEquipmentStrength, WeaponType weaponType, int attackStyleId, Item[] equipedItems, int[] expectedMaxHits)
{
this.rangeLevels = rangeLevels;
this.ammoEquipmentStrength = ammoEquipmentStrength;
this.weaponType = weaponType;
this.attackStyleId = attackStyleId;
this.equipedItems = equipedItems;
this.expectedMaxHits = expectedMaxHits;
}
private static Item mockItem(int itemId)
{
Item item = mock(Item.class);
when(item.getId()).thenReturn(itemId);
return item;
}
public void test(Client client)
{
int[] rangeLevels = this.rangeLevels;
for (int i = 0, rangeLevelsLength = rangeLevels.length; i < rangeLevelsLength; i++)
{
int rangeLevel = rangeLevels[i];
int expectedMaxHit = this.expectedMaxHits[i];
// Mock equipment container
ItemContainer equipmentContainer = mock(ItemContainer.class);
when(client.getItemContainer(InventoryID.EQUIPMENT)).thenReturn(equipmentContainer);
// Mock equipment strength
Widget equipmentWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.EQUIPMENT_RANGED_STRENGTH)).thenReturn(equipmentWidget);
when(equipmentWidget.getText()).thenReturn("Ranged strength: " + this.ammoEquipmentStrength);
// Mock Varbits
when(client.getVar(Varbits.EQUIPPED_WEAPON_TYPE)).thenReturn(this.weaponType.ordinal());
when(client.getVar(VarPlayer.ATTACK_STYLE)).thenReturn(this.attackStyleId);
// Mock strength
when(client.getBoostedSkillLevel(Skill.RANGED)).thenReturn(rangeLevel);
// Test
RangeMaxHitCalculator maxHitCalculator = new RangeMaxHitCalculator(client, this.equipedItems);
assertEquals(this.toString(), expectedMaxHit, maxHitCalculator.getMaxHit(), 0);
}
}
}

View File

@@ -1,182 +0,0 @@
/*
* 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.motherlode;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import net.runelite.api.Varbits;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.Notifier;
import net.runelite.client.config.ChatColorConfig;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.config.RuneLiteConfig;
import org.junit.Before;
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.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MotherlodePluginTest
{
@Inject
private MotherlodePlugin motherlodePlugin;
@Mock
@Bind
private Client client;
@Mock
@Bind
MotherlodeSession motherlodeSession;
@Mock
@Bind
private MotherlodeConfig motherlodeConfig;
@Mock
@Bind
private MotherlodeGemOverlay motherlodeGemOverlay;
@Mock
@Bind
private MotherlodeOreOverlay motherlodeOreOverlay;
@Mock
@Bind
private MotherlodeRocksOverlay motherlodeRocksOverlay;
@Mock
@Bind
private MotherlodeSackOverlay motherlodeSackOverlay;
@Mock
@Bind
private ScheduledExecutorService scheduledExecutorService;
@Mock
@Bind
private ChatColorConfig chatColorConfig;
@Mock
@Bind
private RuneLiteConfig runeliteConfig;
@Mock
@Bind
private Notifier notifier;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
when(client.getMapRegions()).thenReturn(new int[]{14679});
}
@Test
public void testOreCounter()
{
// set inMlm
GameStateChanged gameStateChanged = new GameStateChanged();
gameStateChanged.setGameState(GameState.LOADING);
motherlodePlugin.onGameStateChanged(gameStateChanged);
// Initial sack count
when(client.getVar(Varbits.SACK_NUMBER)).thenReturn(42);
motherlodePlugin.onVarbitChanged(new VarbitChanged());
// Create before inventory
ItemContainer inventory = mock(ItemContainer.class);
Item[] items = new Item[]{
item(ItemID.RUNITE_ORE, 1),
item(ItemID.GOLDEN_NUGGET, 4),
item(ItemID.COAL, 1),
item(ItemID.COAL, 1),
item(ItemID.COAL, 1),
item(ItemID.COAL, 1),
};
when(inventory.getItems())
.thenReturn(items);
when(client.getItemContainer(InventoryID.INVENTORY)).thenReturn(inventory);
// Withdraw 20
when(client.getVar(Varbits.SACK_NUMBER)).thenReturn(22);
motherlodePlugin.onVarbitChanged(new VarbitChanged());
inventory = mock(ItemContainer.class);
// +1 rune, +4 nugget, +2 coal, +1 addy
items = new Item[]{
item(ItemID.RUNITE_ORE, 1),
item(ItemID.RUNITE_ORE, 1),
item(ItemID.GOLDEN_NUGGET, 8),
item(ItemID.COAL, 1),
item(ItemID.COAL, 1),
item(ItemID.COAL, 1),
item(ItemID.COAL, 1),
item(ItemID.COAL, 1),
item(ItemID.COAL, 1),
item(ItemID.ADAMANTITE_ORE, 1),
};
when(inventory.getItems())
.thenReturn(items);
when(client.getItemContainer(InventoryID.INVENTORY)).thenReturn(inventory);
// Trigger comparison
motherlodePlugin.onItemContainerChanged(new ItemContainerChanged(InventoryID.INVENTORY.getId(), inventory));
verify(motherlodeSession).updateOreFound(ItemID.RUNITE_ORE, 1);
verify(motherlodeSession).updateOreFound(ItemID.GOLDEN_NUGGET, 4);
verify(motherlodeSession).updateOreFound(ItemID.COAL, 2);
verify(motherlodeSession).updateOreFound(ItemID.ADAMANTITE_ORE, 1);
verifyNoMoreInteractions(motherlodeSession);
}
private static Item item(int itemId, int quantity)
{
return new Item(itemId, quantity);
}
}

View File

@@ -1,88 +0,0 @@
/*
* 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.util.Iterator;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.client.config.OpenOSRSConfig;
import static org.junit.Assert.assertEquals;
import net.runelite.client.Notifier;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
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;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Mock
@Bind
private Notifier notifier;
@Inject
private NpcIndicatorsPlugin npcIndicatorsPlugin;
@Before
public void setUp()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void getHighlights()
{
npcIndicatorsPlugin.setGetNpcToHighlight("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());
}
}

View File

@@ -1,166 +0,0 @@
/*
* Copyright (c) 2018, Lotto <https://github.com/devLotto>
* 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 HOLDER 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.puzzlesolver;
import net.runelite.client.plugins.puzzlesolver.solver.PuzzleSolver;
import net.runelite.client.plugins.puzzlesolver.solver.PuzzleState;
import net.runelite.client.plugins.puzzlesolver.solver.heuristics.ManhattanDistance;
import net.runelite.client.plugins.puzzlesolver.solver.pathfinding.IDAStar;
import net.runelite.client.plugins.puzzlesolver.solver.pathfinding.IDAStarMM;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class PuzzleSolverTest
{
private static final PuzzleState[] START_STATES =
{
new PuzzleState(new int[]{0, 11, 1, 3, 4, 5, 12, 2, 7, 9, 6, 20, 18, 16, 8, 15, 22, 10, 14, 13, 21, -1, 17, 23, 19}),
new PuzzleState(new int[]{0, 2, 7, 3, 4, 10, 5, 12, 1, 9, 6, 17, 8, 14, 19, -1, 16, 21, 11, 13, 15, 20, 22, 18, 23}),
new PuzzleState(new int[]{0, 1, 11, 3, 4, 12, 2, 7, 13, 9, 5, 21, 15, 17, 14, -1, 10, 6, 8, 19, 16, 20, 22, 18, 23}),
new PuzzleState(new int[]{0, 1, 2, 3, 4, 10, 5, 6, 9, 14, 15, -1, 7, 13, 17, 21, 11, 20, 23, 8, 16, 22, 12, 19, 18}),
new PuzzleState(new int[]{0, 1, 2, 3, 4, 5, 6, 8, 22, 18, 10, -1, 7, 17, 9, 20, 11, 12, 21, 14, 16, 15, 23, 13, 19}),
new PuzzleState(new int[]{0, 1, 2, 3, 4, 5, 6, 8, 12, 9, 16, 11, 17, 7, 14, 10, 20, -1, 22, 13, 15, 18, 21, 23, 19}),
new PuzzleState(new int[]{1, 6, 16, 8, 4, 0, 7, 11, 2, 9, 5, 21, 18, 3, 14, 10, 20, -1, 13, 22, 15, 23, 12, 17, 19}),
new PuzzleState(new int[]{0, 1, 2, 4, 8, 6, 16, 11, 7, 3, 5, -1, 12, 14, 9, 15, 10, 17, 13, 18, 20, 21, 22, 23, 19}),
new PuzzleState(new int[]{0, 2, 9, 14, 6, 5, 7, 11, 3, 4, 15, 10, 1, 12, 18, 16, 17, -1, 8, 13, 20, 21, 22, 23, 19}),
new PuzzleState(new int[]{0, 1, 2, 3, 4, 11, 5, 12, 7, 8, 10, 6, 15, 13, 9, 16, 21, -1, 17, 14, 20, 22, 23, 18, 19}),
new PuzzleState(new int[]{5, 0, 1, 2, 4, 10, 6, 3, 8, 9, 12, 13, 7, 14, 19, 15, 11, 16, 17, -1, 20, 21, 22, 18, 23}),
new PuzzleState(new int[]{0, 6, 1, 3, 4, 5, 8, -1, 2, 9, 16, 11, 12, 7, 14, 10, 15, 17, 13, 19, 20, 21, 22, 18, 23}),
new PuzzleState(new int[]{0, 6, 1, 2, 4, 11, 15, 8, 3, 14, 5, 7, 9, 12, 18, 16, 10, 17, 23, 13, 20, 21, 22, -1, 19}),
new PuzzleState(new int[]{0, 1, 7, 2, 4, 5, 3, 12, 8, 9, 15, 6, 18, -1, 13, 11, 10, 22, 17, 23, 16, 21, 20, 19, 14}),
new PuzzleState(new int[]{0, 1, 2, 7, 3, 5, 11, 6, 14, 4, 10, -1, 16, 12, 9, 15, 17, 18, 8, 19, 20, 21, 13, 22, 23}),
new PuzzleState(new int[]{2, 10, 5, 3, 4, -1, 0, 1, 8, 9, 15, 11, 7, 13, 23, 17, 6, 20, 14, 19, 16, 12, 18, 21, 22}),
new PuzzleState(new int[]{0, 1, 2, 8, 9, 5, 6, 7, 3, 4, 10, -1, 14, 23, 18, 21, 11, 16, 12, 19, 15, 20, 17, 13, 22}),
new PuzzleState(new int[]{0, 6, 1, 3, 4, 11, 2, 13, 9, 12, 5, 16, 7, 18, 8, 20, 15, -1, 14, 19, 21, 10, 22, 23, 17}),
new PuzzleState(new int[]{12, 1, 2, 3, 4, 0, 7, 6, 8, 9, 5, 10, 22, 13, 19, 15, 11, 21, 14, 17, 20, 16, 18, -1, 23}),
new PuzzleState(new int[]{0, 2, 11, 3, 4, 5, 1, 6, 8, 9, 15, 10, 13, 14, 19, 7, 12, -1, 17, 18, 20, 21, 16, 22, 23}),
new PuzzleState(new int[]{5, 0, 4, 2, 9, 10, 7, 3, 19, 8, 6, 1, 18, -1, 14, 15, 11, 16, 12, 13, 20, 21, 17, 22, 23}),
new PuzzleState(new int[]{0, 3, 2, 7, 4, 6, 10, 1, 8, 9, 15, 5, 12, 18, 13, -1, 20, 11, 22, 14, 16, 21, 23, 17, 19}),
new PuzzleState(new int[]{1, 2, 4, -1, 9, 0, 5, 7, 3, 14, 10, 6, 8, 13, 19, 15, 11, 18, 12, 22, 20, 16, 21, 23, 17}),
new PuzzleState(new int[]{0, 1, 2, 4, 9, 5, 11, -1, 7, 14, 10, 17, 6, 13, 8, 15, 16, 20, 3, 18, 22, 21, 12, 23, 19}),
new PuzzleState(new int[]{0, 1, 8, 2, 4, 5, 11, 17, 3, 9, 6, 16, 7, 12, 18, 15, 21, -1, 14, 13, 20, 22, 10, 23, 19}),
new PuzzleState(new int[]{5, 0, 2, 3, 4, 1, 8, 6, 7, 9, 11, 12, 16, 13, 14, -1, 22, 20, 17, 19, 21, 10, 15, 18, 23}),
new PuzzleState(new int[]{0, -1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 16, 11, 13, 14, 10, 15, 19, 22, 23, 20, 21, 17, 12, 18}),
new PuzzleState(new int[]{0, 2, 7, -1, 4, 6, 1, 9, 3, 14, 5, 12, 8, 13, 19, 15, 16, 10, 22, 23, 20, 11, 18, 21, 17}),
new PuzzleState(new int[]{7, 5, 13, 1, 12, 0, 2, 4, 3, 9, 10, 6, 8, 17, 14, 15, 11, 16, 18, -1, 20, 21, 22, 23, 19}),
new PuzzleState(new int[]{5, 0, 3, 8, 4, 10, 6, -1, 7, 9, 11, 1, 12, 2, 19, 15, 16, 17, 14, 13, 20, 21, 22, 18, 23}),
new PuzzleState(new int[]{5, 2, 3, 7, 4, 0, 6, 14, 9, 19, 1, 11, 22, 17, 12, 10, 15, -1, 13, 8, 20, 16, 21, 18, 23}),
new PuzzleState(new int[]{0, 1, 3, 4, 9, 5, 6, 2, 7, 14, 10, 13, 17, -1, 8, 15, 11, 16, 12, 18, 20, 21, 22, 23, 19}),
new PuzzleState(new int[]{0, 3, 11, 7, 4, 5, 2, 6, 12, 8, 10, 1, 17, -1, 9, 15, 16, 23, 13, 14, 20, 21, 18, 22, 19}),
new PuzzleState(new int[]{1, 5, 8, 2, 4, -1, 0, 7, 3, 9, 11, 22, 15, 12, 14, 6, 10, 18, 16, 19, 20, 21, 17, 13, 23}),
new PuzzleState(new int[]{7, 12, 11, 4, 9, -1, 0, 8, 10, 2, 6, 1, 16, 3, 14, 5, 15, 17, 13, 19, 20, 21, 22, 18, 23}),
new PuzzleState(new int[]{11, 3, 2, 12, 4, 6, 0, 7, 13, 8, 1, 5, 17, 16, 9, -1, 10, 15, 18, 14, 20, 21, 22, 23, 19}),
new PuzzleState(new int[]{0, 6, 1, 3, 4, 5, 11, 2, 10, 9, 15, 12, 8, 14, 19, 16, 21, -1, 7, 13, 20, 22, 17, 18, 23}),
new PuzzleState(new int[]{0, 1, 2, 3, 4, 6, 10, 7, 8, 9, 5, 16, 11, 14, 17, 20, 13, 18, 12, 22, 21, 15, 23, -1, 19}),
new PuzzleState(new int[]{0, 1, 2, 4, 8, 5, 6, 7, 3, -1, 10, 16, 18, 17, 9, 15, 12, 11, 14, 13, 20, 21, 22, 23, 19}),
new PuzzleState(new int[]{0, 11, 6, 1, 4, 5, 21, 8, 2, 9, 10, 3, 16, -1, 14, 15, 12, 17, 13, 19, 20, 22, 7, 18, 23}),
new PuzzleState(new int[]{0, 6, 1, 2, 4, 11, 10, 3, 13, 9, 5, 7, 8, -1, 23, 15, 16, 22, 18, 14, 20, 21, 12, 17, 19}),
new PuzzleState(new int[]{0, 6, 1, 2, 3, 10, 11, 12, 5, 18, 15, 7, 4, -1, 14, 21, 17, 13, 8, 9, 16, 20, 22, 23, 19}),
new PuzzleState(new int[]{0, 1, 3, 11, 4, 6, 10, 14, 2, 8, 5, -1, 12, 7, 9, 15, 16, 18, 13, 19, 20, 21, 22, 17, 23}),
new PuzzleState(new int[]{1, 5, 2, 3, 4, -1, 0, 7, 14, 8, 11, 6, 13, 9, 23, 10, 12, 15, 19, 17, 20, 21, 16, 22, 18}),
};
private static final PuzzleState[] START_STATES_MM =
{
new PuzzleState(new int[]{0, 5, 1, 3, 4, 15, 2, 8, 10, 9, 22, 16, 11, 6, 14, 7, 21, 23, 12, 18, 20, -1, 17, 13, 19}),
new PuzzleState(new int[]{0, 12, 8, 13, 4, 3, 16, 2, 1, 9, 21, 5, 6, 10, 14, 7, 17, 20, 18, -1, 15, 11, 22, 23, 19}),
new PuzzleState(new int[]{1, 3, 7, 9, 8, 13, 17, 2, 4, 6, 15, 5, 22, 12, 14, 11, 0, 10, 21, -1, 20, 18, 16, 23, 19}),
new PuzzleState(new int[]{5, 2, 16, 14, 4, 3, 0, 8, 9, 11, 15, 6, 17, 19, 7, 1, 10, -1, 23, 18, 20, 12, 21, 13, 22}),
new PuzzleState(new int[]{0, 6, 1, 4, 13, 10, 2, 16, 7, 3, 20, -1, 8, 14, 9, 21, 5, 18, 11, 19, 17, 15, 12, 22, 23}),
new PuzzleState(new int[]{5, 0, 1, 4, 8, 10, 6, 7, 12, 3, 17, 16, 21, 2, 9, 18, 20, 13, 14, 19, 11, -1, 23, 15, 22}),
new PuzzleState(new int[]{1, 9, 2, 13, 17, 5, 7, 8, 3, 22, 6, -1, 16, 12, 4, 15, 18, 0, 23, 14, 10, 21, 11, 20, 19}),
new PuzzleState(new int[]{1, 2, 11, 13, 4, 21, 7, 3, 6, 9, 0, 8, 10, 19, 14, 20, 12, 16, 23, -1, 5, 17, 15, 22, 18}),
new PuzzleState(new int[]{2, 0, 1, 4, 13, 6, 7, 3, 8, 9, 22, 15, 10, 14, 18, 5, 12, -1, 17, 21, 20, 11, 23, 16, 19}),
new PuzzleState(new int[]{0, 1, 2, 8, 3, 6, 12, 22, 9, 7, 11, 21, 13, 4, 14, 5, 10, -1, 18, 19, 20, 15, 16, 23, 17}),
new PuzzleState(new int[]{1, 2, 3, 4, 8, 0, 6, 15, 14, 18, 16, 17, 20, -1, 9, 10, 12, 22, 11, 13, 21, 7, 5, 19, 23}),
new PuzzleState(new int[]{0, 5, 2, 4, 9, 7, 15, 20, 12, 13, 6, -1, 22, 1, 8, 10, 11, 23, 14, 3, 21, 16, 17, 19, 18}),
new PuzzleState(new int[]{0, 1, 9, 6, 13, 5, 18, -1, 4, 2, 15, 12, 3, 17, 7, 16, 10, 8, 23, 14, 20, 21, 19, 11, 22}),
new PuzzleState(new int[]{11, 5, 12, 3, 4, 15, 8, 0, 7, 1, 6, -1, 19, 2, 9, 16, 10, 13, 17, 23, 20, 21, 22, 14, 18}),
new PuzzleState(new int[]{10, 0, 1, 3, 4, 18, 5, 6, 12, 9, 7, 11, 8, -1, 22, 15, 23, 14, 19, 13, 20, 2, 17, 16, 21}),
new PuzzleState(new int[]{19, -1, 6, 2, 4, 0, 21, 10, 3, 9, 1, 15, 17, 8, 14, 11, 13, 22, 7, 18, 16, 12, 5, 23, 20}),
new PuzzleState(new int[]{11, 6, 3, 4, 9, 1, 10, 16, 2, 7, 5, 0, 13, -1, 12, 21, 8, 18, 17, 14, 15, 20, 22, 23, 19}),
new PuzzleState(new int[]{0, 1, 5, 3, 4, -1, 6, 2, 15, 10, 7, 8, 23, 16, 13, 22, 11, 9, 12, 14, 20, 21, 18, 17, 19}),
new PuzzleState(new int[]{10, 0, 1, -1, 2, 6, 5, 4, 13, 9, 16, 17, 12, 8, 19, 20, 15, 7, 21, 11, 22, 18, 14, 23, 3}),
new PuzzleState(new int[]{1, 0, 5, 3, 9, 20, 15, 7, 2, 14, 6, 4, 12, -1, 8, 13, 18, 10, 23, 11, 21, 16, 17, 19, 22}),
new PuzzleState(new int[]{0, 7, 6, 3, 4, 15, 1, 2, 8, 18, 11, 5, 13, -1, 22, 17, 16, 23, 14, 9, 20, 10, 12, 19, 21}),
new PuzzleState(new int[]{5, 7, 0, 2, 9, 10, 1, 11, 3, 4, 16, 22, 8, 14, 17, 15, 20, 12, 13, 6, 21, 23, 19, -1, 18}),
new PuzzleState(new int[]{3, 0, 1, 5, 4, 11, 6, 2, 16, 9, 15, 10, 7, 12, 13, 21, 19, -1, 22, 8, 20, 17, 14, 18, 23}),
new PuzzleState(new int[]{6, 0, 3, 2, 4, 5, 1, 8, 13, 12, 15, 14, 10, 7, 9, -1, 22, 11, 19, 23, 16, 20, 17, 21, 18}),
new PuzzleState(new int[]{11, 5, 6, 8, 9, 0, 21, 16, 4, 3, 17, 18, 2, 7, 1, 15, 10, -1, 22, 14, 20, 19, 13, 12, 23}),
new PuzzleState(new int[]{2, 18, 3, 11, 4, -1, 5, 6, 12, 1, 10, 20, 0, 7, 9, 21, 15, 14, 23, 19, 16, 22, 13, 8, 17}),
new PuzzleState(new int[]{0, 6, 8, 3, 1, 5, 2, 12, 9, 13, 16, 14, 19, 7, 18, 10, 11, -1, 4, 15, 20, 17, 23, 21, 22}),
new PuzzleState(new int[]{1, 16, 10, 4, 3, 0, 15, 2, 9, -1, 8, 5, 23, 12, 6, 21, 18, 14, 13, 11, 20, 22, 7, 19, 17}),
new PuzzleState(new int[]{1, 7, 6, 3, 4, 0, 2, 14, 5, 22, 18, 21, 16, 9, 13, 10, 20, -1, 8, 17, 15, 23, 11, 19, 12}),
new PuzzleState(new int[]{5, 0, 1, 7, 9, 11, 8, 4, 2, 14, 15, 17, 18, -1, 3, 20, 10, 12, 22, 19, 16, 6, 13, 21, 23}),
new PuzzleState(new int[]{5, 0, 6, 14, 7, 13, 15, 1, 3, 10, 20, 9, 17, 4, 2, 11, 12, 8, 19, -1, 21, 16, 22, 18, 23}),
new PuzzleState(new int[]{12, 7, 8, 4, 9, 6, 11, 15, 2, 1, 5, -1, 13, 16, 3, 17, 0, 10, 18, 14, 20, 22, 21, 19, 23}),
new PuzzleState(new int[]{15, 1, 2, 3, 14, -1, 20, 9, 4, 19, 0, 6, 7, 16, 13, 10, 5, 12, 17, 18, 22, 11, 21, 23, 8}),
new PuzzleState(new int[]{0, 1, 17, -1, 14, 6, 4, 2, 3, 16, 10, 18, 13, 19, 9, 7, 5, 8, 21, 22, 11, 20, 15, 12, 23}),
new PuzzleState(new int[]{5, 11, 9, 0, 3, 8, 14, -1, 6, 4, 1, 13, 7, 2, 19, 10, 21, 18, 23, 17, 15, 20, 12, 16, 22}),
new PuzzleState(new int[]{2, 0, 14, -1, 4, 18, 1, 10, 12, 13, 5, 9, 11, 22, 7, 15, 8, 17, 19, 3, 20, 21, 6, 16, 23}),
new PuzzleState(new int[]{0, 1, 13, 9, 2, 6, 8, 22, 3, 4, 12, 16, 10, 7, 19, -1, 5, 11, 14, 17, 15, 20, 21, 18, 23}),
new PuzzleState(new int[]{0, 13, 17, 8, 3, 5, 1, 12, 14, 4, 10, -1, 6, 7, 9, 15, 23, 2, 16, 19, 20, 11, 21, 22, 18}),
new PuzzleState(new int[]{5, 10, 7, 2, 9, 15, 0, -1, 1, 3, 18, 4, 17, 12, 14, 21, 11, 6, 8, 23, 20, 16, 22, 19, 13}),
new PuzzleState(new int[]{0, 3, 1, 2, 4, 10, 5, 7, 8, 9, 11, 6, 21, 13, 12, 20, 17, -1, 14, 19, 22, 18, 15, 16, 23}),
new PuzzleState(new int[]{0, 2, 7, 11, 13, 3, 14, 1, 4, 9, 5, -1, 12, 8, 18, 20, 10, 15, 22, 23, 17, 16, 6, 21, 19}),
new PuzzleState(new int[]{0, 16, 3, 22, 7, 11, 6, -1, 9, 4, 2, 1, 13, 12, 18, 5, 10, 8, 19, 14, 15, 20, 17, 23, 21}),
new PuzzleState(new int[]{0, 13, 5, 12, 3, 2, 10, 4, 6, 8, 1, 21, 19, 14, 9, 17, 23, 22, 16, 11, 15, 7, 20, -1, 18}),
new PuzzleState(new int[]{14, 5, 6, 12, 4, 10, 20, 1, 0, 23, 2, 16, 13, 19, 3, 15, 22, -1, 9, 8, 11, 7, 18, 17, 21}),
new PuzzleState(new int[]{0, 1, 2, 4, 7, 5, 11, -1, 18, 8, 16, 10, 12, 13, 3, 17, 6, 21, 23, 9, 15, 20, 22, 14, 19}),
new PuzzleState(new int[]{1, 6, 7, 3, 4, 5, 17, 0, 22, 12, 10, 15, 8, -1, 14, 11, 13, 16, 18, 19, 20, 2, 21, 9, 23}),
};
private static final int[] FINISHED_STATE = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, -1};
@Test
public void testSolverMM()
{
for (PuzzleState state : START_STATES_MM)
{
PuzzleSolver solver = new PuzzleSolver(new IDAStarMM(new ManhattanDistance()), state);
solver.run();
assertTrue(solver.hasSolution());
assertFalse(solver.hasFailed());
assertTrue(solver.getStep(solver.getStepCount() - 1).hasPieces(FINISHED_STATE));
}
}
@Test
public void testSolver()
{
for (PuzzleState state : START_STATES)
{
PuzzleSolver solver = new PuzzleSolver(new IDAStar(new ManhattanDistance()), state);
solver.run();
assertTrue(solver.hasSolution());
assertFalse(solver.hasFailed());
assertTrue(solver.getStep(solver.getStepCount() - 1).hasPieces(FINISHED_STATE));
}
}
}

View File

@@ -1,144 +0,0 @@
/*
* Copyright (c) 2018, 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.puzzlesolver.lightbox;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class LightboxSolverTest
{
private static final int[] INITIAL = new int[]{
1, 0, 1, 0, 0,
0, 1, 0, 1, 0,
0, 1, 1, 1, 0,
0, 1, 0, 1, 0,
1, 0, 1, 0, 1
};
private static final int[] A = new int[]{
0, 1, 0, 0, 0,
0, 0, 0, 0, 1,
0, 1, 0, 1, 0,
0, 0, 0, 1, 0,
0, 0, 0, 0, 1
};
private static final int[] B = new int[]{
0, 1, 0, 0, 0,
1, 0, 0, 0, 1,
0, 0, 0, 1, 0,
1, 1, 0, 1, 0,
0, 0, 0, 1, 1,
};
private static final int[] C = new int[]{
0, 1, 0, 0, 0,
1, 0, 0, 0, 1,
1, 1, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 0, 0, 1,
};
private static final int[] D = new int[]{
1, 1, 0, 0, 0,
1, 0, 1, 0, 1,
1, 1, 0, 1, 1,
0, 1, 1, 0, 0,
1, 0, 0, 1, 1,
};
private static final int[] E = new int[]{
1, 0, 0, 1, 0,
1, 1, 1, 0, 1,
1, 1, 0, 1, 0,
0, 0, 1, 0, 0,
1, 0, 0, 1, 1,
};
private static final int[] F = new int[]{
1, 0, 0, 1, 0,
1, 0, 0, 0, 1,
1, 0, 1, 1, 0,
0, 0, 1, 0, 0,
1, 0, 0, 0, 0,
};
private static final int[] G = new int[]{
1, 0, 0, 1, 1,
1, 1, 1, 0, 0,
0, 1, 1, 1, 0,
0, 0, 0, 0, 1,
1, 1, 0, 0, 0,
};
private static final int[] H = new int[]{
1, 0, 1, 1, 1,
1, 1, 1, 0, 0,
0, 1, 1, 1, 0,
1, 1, 0, 0, 1,
1, 0, 0, 1, 0
};
private static LightboxState fromArray(int[] array)
{
LightboxState s = new LightboxState();
assert array.length == 25;
for (int i = 0; i < array.length; ++i)
{
s.setState(i / 5, i % 5, array[i] != 0);
}
return s;
}
@Test
public void test()
{
LightboxSolver solver = new LightboxSolver();
solver.setInitial(fromArray(INITIAL));
solver.setSwitchChange(Combination.A, fromArray(A));
solver.setSwitchChange(Combination.B, fromArray(B));
solver.setSwitchChange(Combination.C, fromArray(C));
solver.setSwitchChange(Combination.D, fromArray(D));
solver.setSwitchChange(Combination.E, fromArray(E));
solver.setSwitchChange(Combination.F, fromArray(F));
solver.setSwitchChange(Combination.G, fromArray(G));
solver.setSwitchChange(Combination.H, fromArray(H));
LightboxSolution solution = solver.solve();
LightboxSolution expected = new LightboxSolution();
expected.flip(Combination.A);
expected.flip(Combination.B);
expected.flip(Combination.D);
expected.flip(Combination.E);
expected.flip(Combination.F);
expected.flip(Combination.G);
assertEquals(expected, solution);
}
}

View File

@@ -1,72 +0,0 @@
/*
* Copyright (c) 2018, 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.reorderprayers;
import net.runelite.api.Prayer;
import static net.runelite.api.Prayer.*;
import static org.junit.Assert.assertArrayEquals;
import org.junit.Test;
public class ReorderPrayersPluginTest
{
private static final Prayer[] PRAYER_ORDER = new Prayer[]{
THICK_SKIN,
BURST_OF_STRENGTH,
CLARITY_OF_THOUGHT,
SHARP_EYE,
MYSTIC_WILL,
ROCK_SKIN,
SUPERHUMAN_STRENGTH,
IMPROVED_REFLEXES,
RAPID_RESTORE,
RAPID_HEAL,
PROTECT_ITEM,
HAWK_EYE,
MYSTIC_LORE,
STEEL_SKIN,
ULTIMATE_STRENGTH,
INCREDIBLE_REFLEXES,
PROTECT_FROM_MAGIC,
PROTECT_FROM_MISSILES,
PROTECT_FROM_MELEE,
EAGLE_EYE,
MYSTIC_MIGHT,
RETRIBUTION,
REDEMPTION,
SMITE,
CHIVALRY,
PIETY,
PRESERVE,
RIGOUR,
AUGURY
};
@Test
public void testPrayerOrder()
{
// the reorder prayers plugin depends on the Prayer enum order
assertArrayEquals(Prayer.values(), PRAYER_ORDER);
}
}

View File

@@ -1,255 +0,0 @@
/*
* Copyright (c) 2018, 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.screenshot;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Consumer;
import javax.inject.Inject;
import static net.runelite.api.ChatMessageType.GAMEMESSAGE;
import net.runelite.api.Client;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.Widget;
import static net.runelite.api.widgets.WidgetID.DIALOG_SPRITE_GROUP_ID;
import static net.runelite.api.widgets.WidgetID.LEVEL_UP_GROUP_ID;
import static net.runelite.api.widgets.WidgetInfo.DIALOG_SPRITE_TEXT;
import static net.runelite.api.widgets.WidgetInfo.LEVEL_UP_LEVEL;
import net.runelite.client.Notifier;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.config.RuneLiteConfig;
import net.runelite.client.ui.ClientUI;
import net.runelite.client.ui.DrawManager;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
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 ScreenshotPluginTest
{
private static final String CLUE_SCROLL = "<col=3300ff>You have completed 28 medium Treasure Trails</col>";
private static final String BARROWS_CHEST = "Your Barrows chest count is <col=ff0000>310</col>";
private static final String CHAMBERS_OF_XERIC_CHEST = "Your completed Chambers of Xeric count is: <col=ff0000>489</col>.";
private static final String THEATRE_OF_BLOOD_CHEST = "Your completed Theatre of Blood count is: <col=ff0000>73</col>.";
private static final String VALUABLE_DROP = "<col=ef1020>Valuable drop: 6 x Bronze arrow (42 coins)</col>";
private static final String UNTRADEABLE_DROP = "<col=ef1020>Untradeable drop: Rusty sword";
@Mock
@Bind
private Client client;
@Inject
private ScreenshotPlugin screenshotPlugin;
@Mock
@Bind
private ScreenshotConfig screenshotConfig;
@Mock
@Bind
Notifier notifier;
@Mock
@Bind
ClientUI clientUi;
@Mock
@Bind
DrawManager drawManager;
@Mock
@Bind
RuneLiteConfig config;
@Mock
@Bind
ScheduledExecutorService service;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
screenshotPlugin.setScreenshotRewards(true);
screenshotPlugin.setScreenshotLevels(true);
screenshotPlugin.setScreenshotValuableDrop(true);
screenshotPlugin.setScreenshotUntradeableDrop(true);
}
@Test
public void testClueScroll()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Seth", CLUE_SCROLL, null, 0);
screenshotPlugin.onChatMessage(chatMessageEvent);
assertEquals("medium", screenshotPlugin.getClueType());
assertEquals(28, screenshotPlugin.getClueNumber());
}
@Test
public void testBarrowsChest()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Seth", BARROWS_CHEST, null, 0);
screenshotPlugin.onChatMessage(chatMessageEvent);
assertEquals(310, screenshotPlugin.getBarrowsNumber());
}
@Test
public void testChambersOfXericChest()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Seth", CHAMBERS_OF_XERIC_CHEST, null, 0);
screenshotPlugin.onChatMessage(chatMessageEvent);
assertEquals(489, screenshotPlugin.getChambersOfXericNumber());
}
@Test
public void testTheatreOfBloodChest()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Magic fTail", THEATRE_OF_BLOOD_CHEST, null, 0);
screenshotPlugin.onChatMessage(chatMessageEvent);
assertEquals(73, screenshotPlugin.gettheatreOfBloodNumber());
}
@SuppressWarnings("unchecked")
@Test
public void testValuableDrop()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", VALUABLE_DROP, null, 0);
screenshotPlugin.onChatMessage(chatMessageEvent);
verify(drawManager).requestNextFrameListener(any(Consumer.class));
}
@SuppressWarnings("unchecked")
@Test
public void testUntradeableDrop()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", UNTRADEABLE_DROP, null, 0);
screenshotPlugin.onChatMessage(chatMessageEvent);
verify(drawManager).requestNextFrameListener(any(Consumer.class));
}
@SuppressWarnings("unchecked")
@Test
public void testHitpointsLevel99()
{
Widget levelChild = mock(Widget.class);
when(client.getWidget(eq(LEVEL_UP_LEVEL))).thenReturn(levelChild);
when(levelChild.getText()).thenReturn("Your Hitpoints are now 99.");
assertEquals("Hitpoints(99)", screenshotPlugin.parseLevelUpWidget(client.getWidget(LEVEL_UP_LEVEL)));
WidgetLoaded event = new WidgetLoaded();
event.setGroupId(LEVEL_UP_GROUP_ID);
screenshotPlugin.onWidgetLoaded(event);
GameTick tick = GameTick.INSTANCE;
screenshotPlugin.onGameTick(tick);
verify(drawManager).requestNextFrameListener(any(Consumer.class));
}
@SuppressWarnings("unchecked")
@Test
public void testFiremakingLevel9()
{
Widget levelChild = mock(Widget.class);
when(client.getWidget(eq(LEVEL_UP_LEVEL))).thenReturn(levelChild);
when(levelChild.getText()).thenReturn("Your Firemaking level is now 9.");
assertEquals("Firemaking(9)", screenshotPlugin.parseLevelUpWidget(client.getWidget(LEVEL_UP_LEVEL)));
WidgetLoaded event = new WidgetLoaded();
event.setGroupId(LEVEL_UP_GROUP_ID);
screenshotPlugin.onWidgetLoaded(event);
GameTick tick = GameTick.INSTANCE;
screenshotPlugin.onGameTick(tick);
verify(drawManager).requestNextFrameListener(any(Consumer.class));
}
@SuppressWarnings("unchecked")
@Test
public void testAttackLevel70()
{
Widget levelChild = mock(Widget.class);
when(client.getWidget(eq(LEVEL_UP_LEVEL))).thenReturn(levelChild);
when(levelChild.getText()).thenReturn("Your Attack level is now 70.");
assertEquals("Attack(70)", screenshotPlugin.parseLevelUpWidget(client.getWidget(LEVEL_UP_LEVEL)));
WidgetLoaded event = new WidgetLoaded();
event.setGroupId(LEVEL_UP_GROUP_ID);
screenshotPlugin.onWidgetLoaded(event);
GameTick tick = GameTick.INSTANCE;
screenshotPlugin.onGameTick(tick);
verify(drawManager).requestNextFrameListener(any(Consumer.class));
}
@SuppressWarnings("unchecked")
@Test
public void testHunterLevel2()
{
Widget levelChild = mock(Widget.class);
when(client.getWidget(eq(DIALOG_SPRITE_TEXT))).thenReturn(levelChild);
when(levelChild.getText()).thenReturn("<col=000080>Congratulations, you've just advanced a Hunter level.<col=000000><br><br>Your Hunter level is now 2.");
assertEquals("Hunter(2)", screenshotPlugin.parseLevelUpWidget(client.getWidget(DIALOG_SPRITE_TEXT)));
WidgetLoaded event = new WidgetLoaded();
event.setGroupId(DIALOG_SPRITE_GROUP_ID);
screenshotPlugin.onWidgetLoaded(event);
GameTick tick = GameTick.INSTANCE;
screenshotPlugin.onGameTick(tick);
verify(drawManager).requestNextFrameListener(any(Consumer.class));
}
}

View File

@@ -1,70 +0,0 @@
/*
* Copyright (c) 2019 Abex
* 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.skybox;
import com.google.common.base.Strings;
import com.google.common.io.CharSource;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;
@Slf4j
public class SkyboxTest
{
@Test
public void testLoadSimple() throws IOException
{
Skybox skybox = new Skybox(CharSource.wrap("bounds 0 0 100 100 #00F // R 0 0 100 100\r\nr 99 99").openStream(), "simple");
Assert.assertEquals(0, skybox.getColorForPoint(0, 0, 0, 0, 0, 1, null));
int x = (99 * 64) + 32;
int y = (99 * 64) + 32;
Assert.assertEquals(0x0000FF, skybox.getColorForPoint(x, y, x, y, 0, 1, null));
}
@Test
public void testLoadActual() throws IOException
{
long start = System.nanoTime();
Skybox skybox = new Skybox(SkyboxPlugin.class.getResourceAsStream("skybox.txt"), "skybox.txt");
log.info("Parse took {}ms", (System.nanoTime() - start) / 1_000_000);
String skyboxFile = System.getProperty("skyboxExport");
if (!Strings.isNullOrEmpty(skyboxFile))
{
start = System.nanoTime();
BufferedImage img = skybox.render(1f, 0, 0, null);
long time = System.nanoTime() - start;
log.info("Map render took {}ms", time / 1_000_000);
log.info("Single render takes ~{}ns/frame", time / (img.getWidth() * img.getHeight()));
ImageIO.write(img, "png", new File(skyboxFile));
}
Assert.assertNotEquals(skybox.getColorForPoint(3232, 3232, 3232, 3232, 0, .9, null), 0); // Lumbridge will never be black
}
}

View File

@@ -1,651 +0,0 @@
/*
* Copyright (c) 2017, 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.slayer;
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 javax.inject.Inject;
import net.runelite.api.ChatMessageType;
import static net.runelite.api.ChatMessageType.GAMEMESSAGE;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.MessageNode;
import net.runelite.api.Player;
import net.runelite.api.Skill;
import net.runelite.api.Varbits;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.StatChanged;
import net.runelite.api.events.VarbitChanged;
import net.runelite.api.widgets.Widget;
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.OpenOSRSConfig;
import net.runelite.client.game.ItemManager;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.http.api.chat.ChatClient;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
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.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class SlayerPluginTest
{
private static final String TASK_NEW = "Your new task is to kill 231 Suqahs.";
private static final String TASK_NEW_KONAR = "You are to bring balance to 147 Wyrms in the Karuulm Slayer Dungeon.";
private static final String TASK_NEW_KONAR_2 = "You are to bring balance to 142 Hellhounds in Witchhaven Dungeon.";
private static final String TASK_NEW_KONAR_3 = "You are to bring balance to 135 Trolls south of Mount Quidamortem.";
private static final String TASK_NEW_FIRST = "We'll start you off hunting goblins, you'll need to kill 17 of them.";
private static final String TASK_NEW_FIRST_KONAR = "We'll start you off bringing balance to cows, you'll need to kill 44 of them.";
private static final String TASK_NEW_NPC_CONTACT = "Excellent, you're doing great. Your new task is to kill<br>211 Suqahs.";
private static final String TASK_NEW_FROM_PARTNER = "You have received a new Slayer assignment from breaklulz: Dust Devils (377)";
private static final String TASK_CHECKSLAYERGEM = "You're assigned to kill Suqahs; only 211 more to go.";
private static final String TASK_CHECKSLAYERGEM_WILDERNESS = "You're assigned to kill Suqahs in the Wilderness; only 211 more to go.";
private static final String TASK_CHECKSLAYERGEM_KONAR = "You're assigned to kill Blue dragons in the Ogre Enclave; only 122 more to go.";
private static final String TASK_BOSS_NEW = "Excellent. You're now assigned to kill Vet'ion 3 times.<br>Your reward point tally is 914.";
private static final String TASK_BOSS_NEW_THE = "Excellent. You're now assigned to kill the Chaos <br>Elemental 3 times. Your reward point tally is 914.";
private static final String TASK_EXISTING = "You're still hunting suqahs; you have 222 to go. Come<br>back when you've finished your task.";
private static final String REWARD_POINTS = "Reward points: 17,566";
private static final String TASK_ONE = "You've completed one task; return to a Slayer master.";
private static final String TASK_COMPLETE_NO_POINTS = "<col=ef1020>You've completed 3 tasks; return to a Slayer master.</col>";
private static final String TASK_POINTS = "You've completed 9 tasks and received 0 points, giving you a total of 18,000; return to a Slayer master.";
private static final String TASK_LARGE_STREAK = "You've completed 2,465 tasks and received 15 points, giving you a total of 17,566,000; return to a Slayer master.";
private static final String TASK_COMPLETE = "You need something new to hunt.";
private static final String TASK_CANCELED = "Your task has been cancelled.";
private static final String SUPERIOR_MESSAGE = "A superior foe has appeared...";
@Mock
@Bind
Client client;
@Mock
@Bind
SlayerConfig slayerConfig;
@Mock
@Bind
OverlayManager overlayManager;
@Mock
@Bind
SlayerOverlay overlay;
@Mock
@Bind
InfoBoxManager infoBoxManager;
@Mock
@Bind
ItemManager itemManager;
@Mock
@Bind
Notifier notifier;
@Mock
@Bind
ChatMessageManager chatMessageManager;
@Mock
@Bind
ChatCommandManager chatCommandManager;
@Mock
@Bind
ScheduledExecutorService executor;
@Mock
@Bind
ChatClient chatClient;
@Inject
SlayerPlugin slayerPlugin;
@Mock
@Bind
SlayerTaskPanel panel;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testNewTask()
{
Widget npcDialog = mock(Widget.class);
when(npcDialog.getText()).thenReturn(TASK_NEW);
when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog);
slayerPlugin.onGameTick(GameTick.INSTANCE);
assertEquals("Suqahs", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(231, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testNewKonarTask()
{
Widget npcDialog = mock(Widget.class);
when(npcDialog.getText()).thenReturn(TASK_NEW_KONAR);
when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog);
slayerPlugin.onGameTick(GameTick.INSTANCE);
assertEquals("Wyrms", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(147, slayerPlugin.getCurrentTask().getAmount());
assertEquals("Karuulm Slayer Dungeon", slayerPlugin.getCurrentTask().getTaskLocation());
}
@Test
public void testNewKonarTask2()
{
Widget npcDialog = mock(Widget.class);
when(npcDialog.getText()).thenReturn(TASK_NEW_KONAR_2);
when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog);
slayerPlugin.onGameTick(GameTick.INSTANCE);
assertEquals("Hellhounds", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(142, slayerPlugin.getCurrentTask().getAmount());
assertEquals("Witchhaven Dungeon", slayerPlugin.getCurrentTask().getTaskLocation());
}
@Test
public void testNewKonarTask3()
{
Widget npcDialog = mock(Widget.class);
when(npcDialog.getText()).thenReturn(TASK_NEW_KONAR_3);
when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog);
slayerPlugin.onGameTick(GameTick.INSTANCE);
assertEquals("Trolls", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(135, slayerPlugin.getCurrentTask().getAmount());
assertEquals("Mount Quidamortem", slayerPlugin.getCurrentTask().getTaskLocation());
}
@Test
public void testFirstTask()
{
Widget npcDialog = mock(Widget.class);
when(npcDialog.getText()).thenReturn(TASK_NEW_FIRST);
when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog);
slayerPlugin.onGameTick(GameTick.INSTANCE);
assertEquals("goblins", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(17, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testFirstTaskKonar()
{
Widget npcDialog = mock(Widget.class);
when(npcDialog.getText()).thenReturn(TASK_NEW_FIRST_KONAR);
when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog);
slayerPlugin.onGameTick(GameTick.INSTANCE);
assertEquals("cows", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(44, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testNewNpcContactTask()
{
Widget npcDialog = mock(Widget.class);
when(npcDialog.getText()).thenReturn(TASK_NEW_NPC_CONTACT);
when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog);
slayerPlugin.onGameTick(GameTick.INSTANCE);
assertEquals("Suqahs", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(211, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testBossTask()
{
Widget npcDialog = mock(Widget.class);
when(npcDialog.getText()).thenReturn(TASK_BOSS_NEW);
when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog);
slayerPlugin.onGameTick(GameTick.INSTANCE);
assertEquals("Vet'ion", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(3, slayerPlugin.getCurrentTask().getAmount());
assertEquals(914, slayerPlugin.getPoints());
}
@Test
public void testBossTaskThe()
{
Widget npcDialog = mock(Widget.class);
when(npcDialog.getText()).thenReturn(TASK_BOSS_NEW_THE);
when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog);
slayerPlugin.onGameTick(GameTick.INSTANCE);
assertEquals("Chaos Elemental", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(3, slayerPlugin.getCurrentTask().getAmount());
assertEquals(914, slayerPlugin.getPoints());
}
@Test
public void testPartnerTask()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_NEW_FROM_PARTNER, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
assertEquals("Dust Devils", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(377, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testCheckSlayerGem()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_CHECKSLAYERGEM, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
assertEquals("Suqahs", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(211, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testCheckSlayerGemWildernessTask()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_CHECKSLAYERGEM_WILDERNESS, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
assertEquals("Suqahs", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(211, slayerPlugin.getCurrentTask().getAmount());
assertEquals("Wilderness", slayerPlugin.getCurrentTask().getTaskLocation());
}
@Test
public void testCheckSlayerGemKonarTask()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_CHECKSLAYERGEM_KONAR, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
assertEquals("Blue dragons", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(122, slayerPlugin.getCurrentTask().getAmount());
assertEquals("Ogre Enclave", slayerPlugin.getCurrentTask().getTaskLocation());
}
@Test
public void testExistingTask()
{
Widget npcDialog = mock(Widget.class);
when(npcDialog.getText()).thenReturn(TASK_EXISTING);
when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog);
slayerPlugin.onGameTick(GameTick.INSTANCE);
assertEquals("suqahs", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(222, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testOneTask()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_ONE, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
assertEquals(1, slayerPlugin.getStreak());
assertEquals("", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(0, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testNoPoints()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_COMPLETE_NO_POINTS, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
assertEquals(3, slayerPlugin.getStreak());
assertEquals("", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(0, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testPoints()
{
when(client.getVar(Varbits.SLAYER_REWARD_POINTS)).thenReturn(18_000);
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_POINTS, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
VarbitChanged varbitChanged = new VarbitChanged();
slayerPlugin.onVarbitChanged(varbitChanged);
assertEquals(9, slayerPlugin.getStreak());
assertEquals("", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(0, slayerPlugin.getCurrentTask().getAmount());
assertEquals(18_000, slayerPlugin.getPoints());
}
@Test
public void testLargeStreak()
{
when(client.getVar(Varbits.SLAYER_REWARD_POINTS)).thenReturn(17_566_000);
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_LARGE_STREAK, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
VarbitChanged varbitChanged = new VarbitChanged();
slayerPlugin.onVarbitChanged(varbitChanged);
assertEquals(2465, slayerPlugin.getStreak());
assertEquals("", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(0, slayerPlugin.getCurrentTask().getAmount());
assertEquals(17_566_000, slayerPlugin.getPoints());
}
@Test
public void testComplete()
{
slayerPlugin.getCurrentTask().setTaskName("cows");
slayerPlugin.getCurrentTask().setAmount(42);
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_COMPLETE, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
assertEquals("", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(0, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testCancelled()
{
slayerPlugin.getCurrentTask().setTaskName("cows");
slayerPlugin.getCurrentTask().setAmount(42);
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Perterter", TASK_CANCELED, null, 0);
slayerPlugin.onChatMessage(chatMessageEvent);
assertEquals("", slayerPlugin.getCurrentTask().getTaskName());
assertEquals(0, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testSuperiorNotification()
{
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "Superior", SUPERIOR_MESSAGE, null, 0);
slayerPlugin.setShowSuperiorNotification(true);
slayerPlugin.onChatMessage(chatMessageEvent);
verify(notifier).notify(SUPERIOR_MESSAGE);
slayerPlugin.setShowSuperiorNotification(false);
slayerPlugin.onChatMessage(chatMessageEvent);
verifyNoMoreInteractions(notifier);
}
@Test
public void testTaskLookup() throws IOException
{
net.runelite.http.api.chat.Task task = new net.runelite.http.api.chat.Task();
task.setTask("Abyssal demons");
task.setLocation("Abyss");
task.setAmount(42);
task.setInitialAmount(42);
slayerPlugin.setTaskCommand(true);
when(chatClient.getTask(anyString())).thenReturn(task);
ChatMessage setMessage = new ChatMessage();
setMessage.setType(ChatMessageType.PUBLICCHAT);
setMessage.setName("Adam");
setMessage.setMessageNode(mock(MessageNode.class));
slayerPlugin.taskLookup(setMessage, "!task");
verify(chatMessageManager).update(any(MessageNode.class));
}
@Test
public void testTaskLookupInvalid()
{
net.runelite.http.api.chat.Task task = new net.runelite.http.api.chat.Task();
task.setTask("task<");
task.setLocation("loc");
task.setAmount(42);
task.setInitialAmount(42);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(ChatMessageType.PUBLICCHAT);
chatMessage.setName("Adam");
chatMessage.setMessageNode(mock(MessageNode.class));
slayerPlugin.taskLookup(chatMessage, "!task");
verify(chatMessageManager, never()).update(any(MessageNode.class));
}
@Test
public void testSuperiorsLowercase()
{
for (String name : SlayerPlugin.SUPERIOR_SLAYER_MONSTERS)
{
assertEquals(name, name.toLowerCase());
}
}
@Test
public void testCorrectlyCapturedTaskKill()
{
final Player player = mock(Player.class);
when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0));
when(client.getLocalPlayer()).thenReturn(player);
StatChanged statChanged = new StatChanged(
Skill.SLAYER,
100,
2,
2
);
slayerPlugin.onStatChanged(statChanged);
slayerPlugin.setTask("Dagannoth", 143, 143, true, 0);
statChanged = new StatChanged(
Skill.SLAYER,
110,
2,
2
);
slayerPlugin.onStatChanged(statChanged);
assertEquals(142, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testIncorrectlyCapturedTaskKill()
{
final Player player = mock(Player.class);
when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0));
when(client.getLocalPlayer()).thenReturn(player);
StatChanged statChanged = new StatChanged(
Skill.SLAYER,
100,
2,
2
);
slayerPlugin.onStatChanged(statChanged);
slayerPlugin.setTask("Monster", 98, 98, true, 0);
assert Task.getTask("Monster") == null;
statChanged = new StatChanged(
Skill.SLAYER,
110,
2,
2
);
slayerPlugin.onStatChanged(statChanged);
assertEquals(97, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testJadTaskKill()
{
final Player player = mock(Player.class);
when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0));
when(client.getLocalPlayer()).thenReturn(player);
StatChanged statChanged = new StatChanged(
Skill.SLAYER,
100,
2,
2
);
slayerPlugin.onStatChanged(statChanged);
slayerPlugin.setTask("TzTok-Jad", 1, 1, true, 0);
// One bat kill
statChanged = new StatChanged(
Skill.SLAYER,
110,
2,
2
);
slayerPlugin.onStatChanged(statChanged);
assertEquals(1, slayerPlugin.getCurrentTask().getAmount());
// One Jad kill
statChanged = new StatChanged(
Skill.SLAYER,
25360,
-1,
-1
);
slayerPlugin.onStatChanged(statChanged);
assertEquals(0, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testZukTaskKill()
{
final Player player = mock(Player.class);
when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0));
when(client.getLocalPlayer()).thenReturn(player);
StatChanged statChanged = new StatChanged(
Skill.SLAYER,
110,
2,
2
);
slayerPlugin.onStatChanged(statChanged);
slayerPlugin.setTask("TzKal-Zuk", 1, 1, true, 0);
// One bat kill
statChanged = new StatChanged(
Skill.SLAYER,
125,
2,
2
);
slayerPlugin.onStatChanged(statChanged);
assertEquals(1, slayerPlugin.getCurrentTask().getAmount());
// One Zuk kill
statChanged = new StatChanged(
Skill.SLAYER,
102_015,
-1,
-1
);
slayerPlugin.onStatChanged(statChanged);
assertEquals(0, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testNewAccountSlayerKill()
{
final Player player = mock(Player.class);
when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0));
when(client.getLocalPlayer()).thenReturn(player);
slayerPlugin.setTask("Bears", 35, 35, true, 0);
StatChanged statChanged = new StatChanged(
Skill.SLAYER,
0,
1,
1
);
slayerPlugin.onStatChanged(statChanged);
statChanged = new StatChanged(
Skill.SLAYER,
27,
1,
1
);
slayerPlugin.onStatChanged(statChanged);
assertEquals(34, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void infoboxNotAddedOnLogin()
{
GameStateChanged loggingIn = new GameStateChanged();
loggingIn.setGameState(GameState.LOGGING_IN);
slayerPlugin.onGameStateChanged(loggingIn);
GameStateChanged loggedIn = new GameStateChanged();
loggedIn.setGameState(GameState.LOGGED_IN);
slayerPlugin.onGameStateChanged(loggedIn);
verify(infoBoxManager, never()).addInfoBox(any());
}
}

View File

@@ -1,95 +0,0 @@
/*
* Copyright (c) 2019, Stephen <stepzhu@umich.edu>
* 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.smelting;
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.events.ChatMessage;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.ui.overlay.OverlayManager;
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 org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class SmeltingPluginTest
{
private static final String SMELT_CANNONBALL = "You remove the cannonballs from the mould";
private static final String SMELT_BAR = "You retrieve a bar of steel.";
@Inject
SmeltingPlugin smeltingPlugin;
@Mock
@Bind
SmeltingConfig config;
@Mock
@Bind
SmeltingOverlay smeltingOverlay;
@Mock
@Bind
OverlayManager overlayManager;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testCannonballs()
{
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", SMELT_CANNONBALL, "", 0);
smeltingPlugin.onChatMessage(chatMessage);
SmeltingSession smeltingSession = smeltingPlugin.getSession();
assertNotNull(smeltingSession);
assertEquals(4, smeltingSession.getCannonBallsSmelted());
}
@Test
public void testBars()
{
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", SMELT_BAR, "", 0);
smeltingPlugin.onChatMessage(chatMessage);
SmeltingSession smeltingSession = smeltingPlugin.getSession();
assertNotNull(smeltingSession);
assertEquals(1, smeltingSession.getBarsSmelted());
}
}

View File

@@ -1,144 +0,0 @@
/*
* 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.timers;
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.EnumSet;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.WorldType;
import net.runelite.api.events.ChatMessage;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.SpriteManager;
import net.runelite.client.ui.overlay.infobox.InfoBox;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class TimersPluginTest
{
private static final String DMM_HALF_TELEBLOCK_MESSAGE = "<col=4f006f>A Tele Block spell has been cast on you by Runelite. It will expire in 1 minute, 15 seconds.</col>";
private static final String FULL_TELEBLOCK_MESSAGE = "<col=4f006f>A Tele Block spell has been cast on you by Runelite. It will expire in 5 minutes.</col>";
private static final String HALF_TELEBLOCK_MESSAGE = "<col=4f006f>A Tele Block spell has been cast on you by Runelite. It will expire in 2 minutes, 30 seconds.</col>";
@Inject
private TimersPlugin timersPlugin;
@Mock
@Bind
private TimersConfig timersConfig;
@Mock
@Bind
private Client client;
@Mock
@Bind
private ItemManager itemManager;
@Mock
@Bind
private SpriteManager spriteManager;
@Mock
@Bind
private InfoBoxManager infoBoxManager;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testHalfTeleblock()
{
timersPlugin.setShowTeleblock(true);
when(client.getWorldType()).thenReturn(EnumSet.of(WorldType.MEMBERS));
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", HALF_TELEBLOCK_MESSAGE, "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(captor.capture());
TimerTimer infoBox = (TimerTimer) captor.getValue();
assertEquals(GameTimer.HALFTB, infoBox.getTimer());
}
@Test
public void testFullTeleblock()
{
timersPlugin.setShowTeleblock(true);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", FULL_TELEBLOCK_MESSAGE, "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(captor.capture());
TimerTimer infoBox = (TimerTimer) captor.getValue();
assertEquals(GameTimer.FULLTB, infoBox.getTimer());
}
@Test
public void testDmmHalfTb()
{
timersPlugin.setShowTeleblock(true);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", DMM_HALF_TELEBLOCK_MESSAGE, "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(captor.capture());
TimerTimer infoBox = (TimerTimer) captor.getValue();
assertEquals(GameTimer.DMM_HALFTB, infoBox.getTimer());
}
@Test
public void testDmmFullTb()
{
timersPlugin.setShowTeleblock(true);
when(client.getWorldType()).thenReturn(EnumSet.of(WorldType.DEADMAN));
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", HALF_TELEBLOCK_MESSAGE, "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(captor.capture());
TimerTimer infoBox = (TimerTimer) captor.getValue();
assertEquals(GameTimer.DMM_FULLTB, infoBox.getTimer());
}
}

View File

@@ -1,84 +0,0 @@
/*
* Copyright (c) 2019, Trevor <https://github.com/Trevor159>
* 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.timestamp;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.TimeZone;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.events.ConfigChanged;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class TimestampPluginTest
{
@Mock
@Bind
Client client;
@Mock
@Bind
TimestampConfig config;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Inject
TimestampPlugin plugin;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testGenerateTimestamp()
{
when(config.timestampFormat()).thenReturn("[yyyy:MM:dd:HH:hh:mm:ss]");
ConfigChanged configChanged = new ConfigChanged();
configChanged.setGroup("timestamp");
configChanged.setKey("format");
configChanged.setNewValue("true");
plugin.onConfigChanged(configChanged);
int testInput = 1554667116;
String testOutput = "[2019:04:07:15:03:58:36]";
TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
plugin.getFormatter().setTimeZone(timeZone);
assertEquals(plugin.generateTimestamp(testInput, timeZone.toZoneId()), testOutput);
}
}

View File

@@ -1,102 +0,0 @@
/*
* Copyright (c) 2018, Jamy C <https://github.com/jamyc>
* 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.timetracking.clocks;
import java.time.format.DateTimeParseException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;
public class ClockPanelTest
{
@Test
public void properColonSeparatedTimeStringShouldReturnCorrectSeconds()
{
assertEquals(5, ClockPanel.stringToSeconds("5"));
assertEquals(50, ClockPanel.stringToSeconds("50"));
assertEquals(120, ClockPanel.stringToSeconds("2:00"));
assertEquals(120, ClockPanel.stringToSeconds("0:120"));
assertEquals(120, ClockPanel.stringToSeconds("0:0:120"));
assertEquals(1200, ClockPanel.stringToSeconds("20:00"));
assertEquals(50, ClockPanel.stringToSeconds("00:00:50"));
assertEquals(121, ClockPanel.stringToSeconds("00:02:01"));
assertEquals(3660, ClockPanel.stringToSeconds("01:01:00"));
assertEquals(9000, ClockPanel.stringToSeconds("2:30:00"));
assertEquals(9033, ClockPanel.stringToSeconds("02:30:33"));
assertEquals(82800, ClockPanel.stringToSeconds("23:00:00"));
assertEquals(400271, ClockPanel.stringToSeconds("111:11:11"));
}
@Test
public void properIntuitiveTimeStringShouldReturnCorrectSeconds()
{
assertEquals(5, ClockPanel.stringToSeconds("5s"));
assertEquals(50, ClockPanel.stringToSeconds("50s"));
assertEquals(120, ClockPanel.stringToSeconds("2m"));
assertEquals(120, ClockPanel.stringToSeconds("120s"));
assertEquals(1200, ClockPanel.stringToSeconds("20m"));
assertEquals(121, ClockPanel.stringToSeconds("2m1s"));
assertEquals(121, ClockPanel.stringToSeconds("2m 1s"));
assertEquals(3660, ClockPanel.stringToSeconds("1h 1m"));
assertEquals(3660, ClockPanel.stringToSeconds("61m"));
assertEquals(3660, ClockPanel.stringToSeconds("3660s"));
assertEquals(9000, ClockPanel.stringToSeconds("2h 30m"));
assertEquals(9033, ClockPanel.stringToSeconds("2h 30m 33s"));
assertEquals(82800, ClockPanel.stringToSeconds("23h"));
assertEquals(400271, ClockPanel.stringToSeconds("111h 11m 11s"));
}
@Test
public void incorrectTimeStringShouldThrowException()
{
Class numberEx = NumberFormatException.class;
Class dateTimeEx = DateTimeParseException.class;
tryFail("a", numberEx);
tryFail("abc", numberEx);
tryFail("aa:bb:cc", numberEx);
tryFail("01:12=", numberEx);
tryFail("s", dateTimeEx);
tryFail("1s 1m", dateTimeEx);
tryFail("20m:10s", dateTimeEx);
tryFail("20hh10m10s", dateTimeEx);
}
private void tryFail(String input, Class<?> expectedException)
{
try
{
ClockPanel.stringToSeconds(input);
fail("Should have thrown " + expectedException.getSimpleName());
}
catch (Exception exception)
{
assertEquals(expectedException, exception.getClass());
}
}
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright (c) 2018 Abex
* 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.timetracking.farming;
import org.junit.Test;
public class FarmingWorldTest
{
@Test
public void testInit()
{
new FarmingWorld();
}
}

View File

@@ -1,86 +0,0 @@
/*
* Copyright (c) 2018 Abex
* 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.timetracking.farming;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
public class PatchImplementationTest
{
@Rule
public ErrorCollector collector = new ErrorCollector();
@Test
public void testRange()
{
for (PatchImplementation impl : PatchImplementation.values())
{
Map<Produce, boolean[]> harvestStages = new HashMap<>();
for (int i = 0; i < 256; i++)
{
PatchState s = impl.forVarbitValue(i);
if (s != null)
{
String pfx = impl.name() + "[" + i + "]";
collector.checkThat(pfx + ": cropState", s.getCropState(), notNullValue());
collector.checkThat(pfx + ": produce", s.getProduce(), notNullValue());
collector.checkThat(pfx + ": negative stage", s.getStage(), greaterThanOrEqualTo(0));
int stages = s.getProduce().getStages();
if (s.getCropState() == CropState.HARVESTABLE)
{
stages = s.getProduce().getHarvestStages();
}
collector.checkThat(pfx + ": out of bounds stage", s.getStage(), lessThan(stages));
if (s.getCropState() == CropState.DEAD || s.getCropState() == CropState.DISEASED)
{
collector.checkThat(pfx + ": dead seed", s.getStage(), greaterThan(0));
}
if (s.getCropState() == CropState.GROWING && s.getProduce() != Produce.WEEDS && s.getStage() < stages)
{
harvestStages.computeIfAbsent(s.getProduce(), k -> new boolean[s.getProduce().getStages()])[s.getStage()] = true;
}
}
}
for (Map.Entry<Produce, boolean[]> produce : harvestStages.entrySet())
{
boolean[] states = produce.getValue();
// Alot of time the final stage is not hit, because some plants do not have a "Check-health" stage
for (int i = 0; i < states.length - 1; i++)
{
collector.checkThat(produce.getKey().getName() + " stage " + i + " never found by varbit", states[i], is(true));
}
}
}
}
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright (c) 2018, 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.twitch.irc;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class MessageTest
{
@Test
public void testParse()
{
Message message = Message.parse("@badges=subscriber/0;color=;display-name=kappa_kid_;emotes=;id=6539b42a-e945-4a83-a5b7-018149ca9fa7;mod=0;room-id=27107346;subscriber=1;tmi-sent-ts=1535926830652;turbo=0;user-id=33390095;user-type= :kappa_kid_!kappa_kid_@kappa_kid_.tmi.twitch.tv PRIVMSG #b0aty :how do u add charges to that zeah book?");
Map<String, String> messageTags = message.getTags();
assertEquals("subscriber/0", messageTags.get("badges"));
assertEquals("kappa_kid_!kappa_kid_@kappa_kid_.tmi.twitch.tv", message.getSource());
assertEquals("PRIVMSG", message.getCommand());
assertEquals("#b0aty", message.getArguments()[0]);
assertEquals("how do u add charges to that zeah book?", message.getArguments()[1]);
message = Message.parse("@badges=moderator/1,subscriber/12,bits/10000;color=#008000;display-name=Am_Sephiroth;emotes=;id=7d516b7c-de7a-4c8b-ad23-d8880b55d46b;login=am_sephiroth;mod=1;msg-id=subgift;msg-param-months=8;msg-param-recipient-display-name=IntRS;msg-param-recipient-id=189672346;msg-param-recipient-user-name=intrs;msg-param-sender-count=215;msg-param-sub-plan-name=Sick\\sNerd\\sSubscription\\s;msg-param-sub-plan=1000;room-id=49408183;subscriber=1;system-msg=Am_Sephiroth\\sgifted\\sa\\sTier\\s1\\ssub\\sto\\sIntRS!\\sThey\\shave\\sgiven\\s215\\sGift\\sSubs\\sin\\sthe\\schannel!;tmi-sent-ts=1535980032939;turbo=0;user-id=69539403;user-type=mod :tmi.twitch.tv USERNOTICE #sick_nerd");
messageTags = message.getTags();
assertEquals("Am_Sephiroth gifted a Tier 1 sub to IntRS! They have given 215 Gift Subs in the channel!", messageTags.get("system-msg"));
}
}

View File

@@ -1,160 +0,0 @@
/*
* Copyright (c) 2019, Kusha Gharahi<kusha.me>
* 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.wintertodt;
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.Client;
import net.runelite.api.Varbits;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.Notifier;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.ui.overlay.OverlayManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.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;
@RunWith(MockitoJUnitRunner.class)
public class WintertodtPluginTest
{
@Inject
WintertodtPlugin wintertodtPlugin;
@Mock
@Bind
WintertodtConfig config;
@Mock
@Bind
WintertodtOverlay wintertodtOverlay;
@Mock
@Bind
OverlayManager overlayManager;
@Mock
@Bind
ChatMessageManager chatMessageManager;
@Mock
@Bind
Notifier notifier;
@Mock
@Bind
Client client;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void matchStartingNotification_shouldNotify_when15SecondsOptionSelected()
{
when(config.roundNotification()).thenReturn(15);
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(35);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
//(15 * 50) / 30 = ~25
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(25);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
verify(notifier, times(1)).notify("Wintertodt round is about to start");
}
@Test
public void matchStartingNotification_shouldNotify_when10SecondsOptionSelected()
{
when(config.roundNotification()).thenReturn(10);
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(20);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
//(10 * 50) / 30 = ~16
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(16);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
verify(notifier, times(1)).notify("Wintertodt round is about to start");
}
@Test
public void matchStartingNotification_shouldNotify_when5SecondsOptionSelected()
{
when(config.roundNotification()).thenReturn(5);
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(10);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
//(5 * 50) / 30 = ~8
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(8);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
verify(notifier, times(1)).notify("Wintertodt round is about to start");
}
@Test
public void matchStartingNotification_shouldNotifyOnce()
{
when(config.roundNotification()).thenReturn(5);
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(0);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(10);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(8);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(6);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(5);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(4);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
verify(notifier, times(1)).notify("Wintertodt round is about to start");
}
@Test
public void matchStartingNotification_shouldNotNotify_whenNoneOptionSelected()
{
when(config.roundNotification()).thenReturn(5);
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(25);
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
verify(notifier, times(0)).notify("Wintertodt round is about to start");
}
}

View File

@@ -1,145 +0,0 @@
/*
* Copyright (c) 2019, Jordan Zomerlei <jordan@zomerlei.com>
* 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.woodcutting;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.events.ChatMessage;
import net.runelite.client.Notifier;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.game.ItemManager;
import net.runelite.client.ui.overlay.OverlayManager;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class WoodcuttingPluginTest
{
private static final String BIRDS_NEST_MESSAGE = "A bird's nest falls out of the tree.";
@Inject
WoodcuttingPlugin woodcuttingPlugin;
@Mock
@Bind
WoodcuttingConfig woodcuttingConfig;
@Mock
@Bind
OpenOSRSConfig openOSRSConfig;
@Mock
@Bind
ScheduledExecutorService scheduledExecutorService;
@Mock
@Bind
Notifier notifier;
@Mock
@Bind
Client client;
@Mock
@Bind
WoodcuttingOverlay woodcuttingOverlay;
@Mock
@Bind
WoodcuttingTreesOverlay woodcuttingTreesOverlay;
@Mock
@Bind
OverlayManager overlayManager;
@Mock
@Bind
private ItemManager itemManager;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void testLogs()
{
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You get some logs.", "", 0);
woodcuttingPlugin.onChatMessage(chatMessage);
assertNotNull(woodcuttingPlugin.getSession());
}
@Test
public void testOakLogs()
{
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You get some oak logs.", "", 0);
woodcuttingPlugin.onChatMessage(chatMessage);
assertNotNull(woodcuttingPlugin.getSession());
}
@Test
public void testArcticLogs()
{
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You get an arctic log.", "", 0);
woodcuttingPlugin.onChatMessage(chatMessage);
assertNotNull(woodcuttingPlugin.getSession());
}
@Test
public void testMushrooms()
{
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You get some mushrooms.", "", 0);
woodcuttingPlugin.onChatMessage(chatMessage);
assertNotNull(woodcuttingPlugin.getSession());
}
@Test
public void testBirdsNest()
{
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", BIRDS_NEST_MESSAGE, "", 0);
when(woodcuttingConfig.showNestNotification()).thenReturn(true);
woodcuttingPlugin.onChatMessage(chatMessage);
verify(notifier).notify("A bird nest has spawned!");
when(woodcuttingConfig.showNestNotification()).thenReturn(false);
woodcuttingPlugin.onChatMessage(chatMessage);
verifyNoMoreInteractions(notifier);
}
}

View File

@@ -1,43 +0,0 @@
/*
* Copyright (c) 2018, 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 HOLDER 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.worldmap;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
public class TeleportLocationDataTest
{
@Test
public void testResources()
{
for (TeleportLocationData data : TeleportLocationData.values())
{
String path = data.getIconPath();
assertNotNull(path);
assertNotNull(path, getClass().getResourceAsStream(path));
}
}
}

View File

@@ -1,128 +0,0 @@
/*
* 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.xptracker;
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.Client;
import net.runelite.api.GameState;
import net.runelite.api.Player;
import net.runelite.api.Skill;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.StatChanged;
import net.runelite.client.config.OpenOSRSConfig;
import net.runelite.client.game.NPCManager;
import net.runelite.client.game.SkillIconManager;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.overlay.OverlayManager;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class XpTrackerPluginTest
{
@Inject
private XpTrackerPlugin xpTrackerPlugin;
@Mock
@Bind
private ClientToolbar clientToolbar;
@Mock
@Bind
private Client client;
@Mock
@Bind
private SkillIconManager skillIconManager;
@Mock
@Bind
private XpTrackerConfig xpTrackerConfig;
@Mock
@Bind
private NPCManager npcManager;
@Mock
@Bind
private OverlayManager overlayManager;
@Mock
@Bind
private OpenOSRSConfig openOSRSConfig;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
when(client.getLocalPlayer()).thenReturn(mock(Player.class));
xpTrackerPlugin.setXpPanel(mock(XpPanel.class));
}
@Test
public void testOfflineXp()
{
GameStateChanged gameStateChanged = new GameStateChanged();
gameStateChanged.setGameState(GameState.LOGGING_IN);
// Flag initialization of tracker
xpTrackerPlugin.onGameStateChanged(gameStateChanged);
when(client.getSkillExperience(Skill.ATTACK)).thenReturn(42);
// Initialize tracker
xpTrackerPlugin.onGameTick(GameTick.INSTANCE);
// Gain attack xp
StatChanged statChanged = new StatChanged(
Skill.ATTACK,
100,
2,
2
);
xpTrackerPlugin.onStatChanged(statChanged);
// Offline gain
when(client.getSkillExperience(Skill.ATTACK)).thenReturn(42000);
// Flag initialization of tracker
xpTrackerPlugin.onGameStateChanged(gameStateChanged);
// Initialize tracker
xpTrackerPlugin.onGameTick(GameTick.INSTANCE);
// Start at 42 xp, gain of 58 xp, offline gain of 41900 xp - offset start XP: 42 + 41900
XpStateSingle skillState = xpTrackerPlugin.getSkillState(Skill.ATTACK);
assertEquals(41942, skillState.getStartXp());
}
}