Merge remote-tracking branch 'runelite/master'
This commit is contained in:
@@ -71,6 +71,7 @@ public class HiscoreClientTest
|
||||
+ "254,92\n"
|
||||
+ "-1,-1\n" // lms
|
||||
+ "1,241\n" // soul wars
|
||||
+ "1,2739\n" // gotr
|
||||
+ "24870,37\n"
|
||||
+ "15020,388\n"
|
||||
+ "50463,147\n"
|
||||
@@ -148,6 +149,7 @@ public class HiscoreClientTest
|
||||
assertEquals(254, result.getClueScrollMaster().getRank());
|
||||
assertEquals(-1, result.getLastManStanding().getLevel());
|
||||
assertEquals(241, result.getSoulWarsZeal().getLevel());
|
||||
assertEquals(2739, result.getRiftsClosed().getLevel());
|
||||
assertEquals(2460, result.getLeaguePoints().getLevel());
|
||||
assertEquals(37, result.getAbyssalSire().getLevel());
|
||||
assertEquals(92357, result.getCallisto().getRank());
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* 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.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
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.Mock;
|
||||
import static org.mockito.Mockito.mock;
|
||||
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;
|
||||
|
||||
@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.getVarbitValue(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));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ import net.runelite.api.Client;
|
||||
import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.ScriptID;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.ScriptPostFired;
|
||||
@@ -164,6 +165,9 @@ public class ChatCommandsPluginTest
|
||||
@Test
|
||||
public void testTheatreOfBlood()
|
||||
{
|
||||
when(client.getVarbitValue(Varbits.THEATRE_OF_BLOOD_ORB1)).thenReturn(1);
|
||||
when(client.getVarbitValue(Varbits.THEATRE_OF_BLOOD_ORB2)).thenReturn(15);
|
||||
|
||||
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "",
|
||||
"Wave 'The Final Challenge' (Normal Mode) complete!<br>" +
|
||||
"Duration: <col=ff0000>2:42.0</col><br>" +
|
||||
@@ -178,11 +182,14 @@ public class ChatCommandsPluginTest
|
||||
|
||||
verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood", 73);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood", 17 * 60 + .2);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood 2 players", 17 * 60 + .2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTheatreOfBloodNoPb()
|
||||
{
|
||||
when(client.getVarbitValue(Varbits.THEATRE_OF_BLOOD_ORB1)).thenReturn(1);
|
||||
|
||||
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "",
|
||||
"Wave 'The Final Challenge' (Normal Mode) complete!<br>" +
|
||||
"Duration: <col=ff0000>2:42</col><br>" +
|
||||
@@ -197,11 +204,14 @@ public class ChatCommandsPluginTest
|
||||
|
||||
verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood", 73);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood", 13 * 60 + 52.8);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood solo", 13 * 60 + 52.8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTheatreOfBloodEntryMode()
|
||||
{
|
||||
when(client.getVarbitValue(Varbits.THEATRE_OF_BLOOD_ORB1)).thenReturn(1);
|
||||
|
||||
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "",
|
||||
"Wave 'The Final Challenge' (Entry Mode) complete!<br>" +
|
||||
"Duration: <col=ff0000>2:42</col><br>" +
|
||||
@@ -216,6 +226,7 @@ public class ChatCommandsPluginTest
|
||||
|
||||
verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood entry mode", 73);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood entry mode", 17 * 60.);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood entry mode solo", 17 * 60.);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -556,45 +567,45 @@ public class ChatCommandsPluginTest
|
||||
@Test
|
||||
public void testCoXKill()
|
||||
{
|
||||
ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>24+ players</col> Duration:</col> <col=ff0000>37:04</col> (new personal best)</col>>", null, 0);
|
||||
ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>24+ players</col> Duration:</col> <col=ff0000>37:04.20</col> (new personal best)</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).setRSProfileConfiguration("killcount", "chambers of xeric", 51);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 37 * 60 + 4.0);
|
||||
|
||||
// Precise times
|
||||
chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>24+ players</col> Duration:</col> <col=ff0000>37:04.20</col> (new personal best)</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).setRSProfileConfiguration("personalbest", "chambers of xeric", 37 * 60 + 4.2);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric 24+ players", 37 * 60 + 4.2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoXKillNoPb()
|
||||
{
|
||||
ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>11-15 players</col> Duration:</col> <col=ff0000>23:25</col> Personal best: </col><col=ff0000>20:19</col>", null, 0);
|
||||
ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>11-15 players</col> Duration:</col> <col=ff0000>23:25.40</col> Personal best: </col><col=ff0000>20:19.20</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).setRSProfileConfiguration("killcount", "chambers of xeric", 52);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 20 * 60 + 19.0);
|
||||
|
||||
// Precise times
|
||||
chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>11-15 players</col> Duration:</col> <col=ff0000>23:25.40</col> Personal best: </col><col=ff0000>20:19.20</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).setRSProfileConfiguration("personalbest", "chambers of xeric", 20 * 60 + 19.2);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric 11-15 players", 20 * 60 + 19.2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoxCmNoPb()
|
||||
{
|
||||
ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "",
|
||||
"<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>3 players</col> Duration:</col> <col=ff0000>41:10</col> Personal best: </col><col=ff0000>40:03</col>", null, 0);
|
||||
chatCommandsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
chatMessage = new ChatMessage(null, GAMEMESSAGE, "",
|
||||
"Your completed Chambers of Xeric Challenge Mode count is: <col=ff0000>13</col>.", null, 0);
|
||||
chatCommandsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
verify(configManager).setRSProfileConfiguration("killcount", "chambers of xeric challenge mode", 13);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric challenge mode", 40 * 60 + 3.);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric challenge mode 3 players", 40 * 60 + 3.);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -216,10 +216,10 @@ public class ClueScrollPluginTest
|
||||
when(container.getItems()).thenReturn(inventory);
|
||||
when(container.contains(ItemID.RUNE_POUCH)).thenReturn(true);
|
||||
|
||||
when(client.getVar(Varbits.RUNE_POUCH_RUNE1)).thenReturn(9); // Cosmic Rune
|
||||
when(client.getVar(Varbits.RUNE_POUCH_AMOUNT1)).thenReturn(20);
|
||||
when(client.getVar(Varbits.RUNE_POUCH_RUNE3)).thenReturn(4); // Fire Rune
|
||||
when(client.getVar(Varbits.RUNE_POUCH_AMOUNT3)).thenReturn(4000);
|
||||
when(client.getVarbitValue(Varbits.RUNE_POUCH_RUNE1)).thenReturn(9); // Cosmic Rune
|
||||
when(client.getVarbitValue(Varbits.RUNE_POUCH_AMOUNT1)).thenReturn(20);
|
||||
when(client.getVarbitValue(Varbits.RUNE_POUCH_RUNE3)).thenReturn(4); // Fire Rune
|
||||
when(client.getVarbitValue(Varbits.RUNE_POUCH_AMOUNT3)).thenReturn(4000);
|
||||
|
||||
plugin.onItemContainerChanged(event);
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ import net.runelite.api.GameState;
|
||||
import net.runelite.api.KeyCode;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.NPCComposition;
|
||||
import net.runelite.api.ObjectComposition;
|
||||
import net.runelite.api.events.ClientTick;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
@@ -95,6 +97,11 @@ public class MenuEntrySwapperPluginTest
|
||||
when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
|
||||
when(client.getObjectDefinition(anyInt())).thenReturn(mock(ObjectComposition.class));
|
||||
|
||||
NPC npc = mock(NPC.class);
|
||||
NPCComposition composition = mock(NPCComposition.class);
|
||||
when(npc.getTransformedComposition()).thenReturn(composition);
|
||||
when(client.getCachedNPCs()).thenReturn(new NPC[] { npc });
|
||||
|
||||
when(client.getMenuEntries()).thenAnswer((Answer<MenuEntry[]>) invocationOnMock ->
|
||||
{
|
||||
// The menu implementation returns a copy of the array, which causes swap() to not
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* 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.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.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 MotherlodeSceneOverlay motherlodeSceneOverlay;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private MotherlodeSackOverlay motherlodeSackOverlay;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private ScheduledExecutorService scheduledExecutorService;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@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.getVarbitValue(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.getVarbitValue(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);
|
||||
}
|
||||
}
|
||||
@@ -427,13 +427,13 @@ public class ScreenshotPluginTest
|
||||
{
|
||||
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", COLLECTION_LOG_CHAT, null, 0);
|
||||
|
||||
when(client.getVar(Varbits.COLLECTION_LOG_NOTIFICATION)).thenReturn(1);
|
||||
when(client.getVarbitValue(Varbits.COLLECTION_LOG_NOTIFICATION)).thenReturn(1);
|
||||
screenshotPlugin.onChatMessage(chatMessageEvent);
|
||||
|
||||
verify(screenshotPlugin).takeScreenshot("Collection log (Chompy bird hat)", "Collection Log");
|
||||
reset(screenshotPlugin);
|
||||
|
||||
when(client.getVar(Varbits.COLLECTION_LOG_NOTIFICATION)).thenReturn(3);
|
||||
when(client.getVarbitValue(Varbits.COLLECTION_LOG_NOTIFICATION)).thenReturn(3);
|
||||
screenshotPlugin.onChatMessage(chatMessageEvent);
|
||||
|
||||
verify(screenshotPlugin, never()).takeScreenshot(anyString(), anyString());
|
||||
@@ -490,7 +490,7 @@ public class ScreenshotPluginTest
|
||||
{
|
||||
when(screenshotConfig.screenshotCombatAchievements()).thenReturn(true);
|
||||
|
||||
when(client.getVar(Varbits.COMBAT_ACHIEVEMENTS_POPUP)).thenReturn(1);
|
||||
when(client.getVarbitValue(Varbits.COMBAT_ACHIEVEMENTS_POPUP)).thenReturn(1);
|
||||
|
||||
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "",
|
||||
"Congratulations, you've completed an easy combat task: <col=06600c>Handyman</col>.", null, 0);
|
||||
|
||||
@@ -454,8 +454,7 @@ public class TimersPluginTest
|
||||
public void testCorruptionCooldown()
|
||||
{
|
||||
when(timersConfig.showArceuusCooldown()).thenReturn(true);
|
||||
when(client.getVar(any(Varbits.class))).thenReturn(0);
|
||||
when(client.getVar(Varbits.CORRUPTION_COOLDOWN)).thenReturn(1);
|
||||
when(client.getVarbitValue(Varbits.CORRUPTION_COOLDOWN)).thenReturn(1);
|
||||
timersPlugin.onVarbitChanged(new VarbitChanged());
|
||||
|
||||
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
|
||||
@@ -540,7 +539,7 @@ public class TimersPluginTest
|
||||
public void testImbuedHeartStart()
|
||||
{
|
||||
when(timersConfig.showImbuedHeart()).thenReturn(true);
|
||||
when(client.getVar(Varbits.IMBUED_HEART_COOLDOWN)).thenReturn(70);
|
||||
when(client.getVarbitValue(Varbits.IMBUED_HEART_COOLDOWN)).thenReturn(70);
|
||||
timersPlugin.onVarbitChanged(new VarbitChanged());
|
||||
|
||||
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
|
||||
@@ -555,7 +554,7 @@ public class TimersPluginTest
|
||||
{
|
||||
when(timersConfig.showImbuedHeart()).thenReturn(true);
|
||||
|
||||
when(client.getVar(Varbits.IMBUED_HEART_COOLDOWN)).thenReturn(70);
|
||||
when(client.getVarbitValue(Varbits.IMBUED_HEART_COOLDOWN)).thenReturn(70);
|
||||
timersPlugin.onVarbitChanged(new VarbitChanged()); // Calls removeIf once (on createGameTimer)
|
||||
|
||||
ArgumentCaptor<Predicate<InfoBox>> prcaptor = ArgumentCaptor.forClass(Predicate.class);
|
||||
@@ -565,7 +564,7 @@ public class TimersPluginTest
|
||||
Predicate<InfoBox> pred = prcaptor.getValue();
|
||||
assertTrue(pred.test(imbuedHeartInfoBox));
|
||||
|
||||
when(client.getVar(Varbits.IMBUED_HEART_COOLDOWN)).thenReturn(0);
|
||||
when(client.getVarbitValue(Varbits.IMBUED_HEART_COOLDOWN)).thenReturn(0);
|
||||
timersPlugin.onVarbitChanged(new VarbitChanged()); // Calls removeIf once
|
||||
|
||||
verify(infoBoxManager, times(1)).addInfoBox(any());
|
||||
|
||||
@@ -0,0 +1,577 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Cyborger1
|
||||
* 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 com.google.inject.Guice;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.client.Notifier;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.plugins.timetracking.SummaryState;
|
||||
import net.runelite.client.plugins.timetracking.TimeTrackingConfig;
|
||||
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.when;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class FarmingContractManagerTest
|
||||
{
|
||||
private Map<Integer, FarmingPatch> farmingGuildPatches = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
private FarmingContractManager farmingContractManager;
|
||||
|
||||
@Inject
|
||||
private FarmingWorld farmingWorld;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private TimeTrackingConfig config;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private Client client;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private FarmingTracker farmingTracker;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private ConfigManager configManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private Notifier notifier;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private ItemManager itemManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private InfoBoxManager infoBoxManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private ScheduledExecutorService executor;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
|
||||
|
||||
for (FarmingPatch p : farmingWorld.getFarmingGuildRegion().getPatches())
|
||||
{
|
||||
farmingGuildPatches.put(p.getVarbit(), p);
|
||||
}
|
||||
|
||||
// Consider all patches to be empty by default
|
||||
when(farmingTracker.predictPatch(any(FarmingPatch.class)))
|
||||
.thenReturn(new PatchPrediction(null, null, 0, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractOnionHarvestableAndCabbageHarvestable()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch1 = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
final FarmingPatch patch2 = farmingGuildPatches.get(Varbits.FARMING_4774);
|
||||
|
||||
assertNotNull(patch1);
|
||||
assertNotNull(patch2);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch1))
|
||||
.thenReturn(new PatchPrediction(Produce.ONION, CropState.HARVESTABLE, unixNow, 3, 3));
|
||||
when(farmingTracker.predictPatch(patch2))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.HARVESTABLE, unixNow, 3, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.COMPLETED, farmingContractManager.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractOnionHarvestableAndPotatoHarvestable()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch1 = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
final FarmingPatch patch2 = farmingGuildPatches.get(Varbits.FARMING_4774);
|
||||
|
||||
assertNotNull(patch1);
|
||||
assertNotNull(patch2);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch1))
|
||||
.thenReturn(new PatchPrediction(Produce.ONION, CropState.HARVESTABLE, unixNow, 3, 3));
|
||||
when(farmingTracker.predictPatch(patch2))
|
||||
.thenReturn(new PatchPrediction(Produce.POTATO, CropState.HARVESTABLE, unixNow, 3, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.OCCUPIED, farmingContractManager.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractOnionHarvestableAndEmptyPatch()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
|
||||
assertNotNull(patch);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch))
|
||||
.thenReturn(new PatchPrediction(Produce.ONION, CropState.HARVESTABLE, unixNow, 3, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.EMPTY, farmingContractManager.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractOnionHarvestableAndCabbageGrowing()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
final long expectedTime = unixNow + 60;
|
||||
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch1 = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
final FarmingPatch patch2 = farmingGuildPatches.get(Varbits.FARMING_4774);
|
||||
|
||||
assertNotNull(patch1);
|
||||
assertNotNull(patch2);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch1))
|
||||
.thenReturn(new PatchPrediction(Produce.ONION, CropState.HARVESTABLE, unixNow, 3, 3));
|
||||
when(farmingTracker.predictPatch(patch2))
|
||||
.thenReturn(new PatchPrediction(
|
||||
Produce.CABBAGE, CropState.GROWING, expectedTime, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
assertEquals(CropState.GROWING, farmingContractManager.getContractCropState());
|
||||
assertEquals(expectedTime, farmingContractManager.getCompletionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractOnionHarvestableAndCabbageDiseased()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch1 = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
final FarmingPatch patch2 = farmingGuildPatches.get(Varbits.FARMING_4774);
|
||||
|
||||
assertNotNull(patch1);
|
||||
assertNotNull(patch2);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch1))
|
||||
.thenReturn(new PatchPrediction(Produce.ONION, CropState.HARVESTABLE, unixNow, 3, 3));
|
||||
when(farmingTracker.predictPatch(patch2))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.DISEASED, 0, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
assertEquals(CropState.DISEASED, farmingContractManager.getContractCropState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractOnionHarvestableAndCabbageDead()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch1 = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
final FarmingPatch patch2 = farmingGuildPatches.get(Varbits.FARMING_4774);
|
||||
|
||||
assertNotNull(patch1);
|
||||
assertNotNull(patch2);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch1))
|
||||
.thenReturn(new PatchPrediction(Produce.ONION, CropState.HARVESTABLE, unixNow, 3, 3));
|
||||
when(farmingTracker.predictPatch(patch2))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.DEAD, 0, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
assertEquals(CropState.DEAD, farmingContractManager.getContractCropState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractCabbageGrowingAndCabbageDead()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
final long expected = unixNow + 60;
|
||||
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch1 = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
final FarmingPatch patch2 = farmingGuildPatches.get(Varbits.FARMING_4774);
|
||||
|
||||
assertNotNull(patch1);
|
||||
assertNotNull(patch2);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch1))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.GROWING, expected, 2, 3));
|
||||
when(farmingTracker.predictPatch(patch2))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.DEAD, 0, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractCabbageHarvestableAndCabbageDead()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch1 = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
final FarmingPatch patch2 = farmingGuildPatches.get(Varbits.FARMING_4774);
|
||||
|
||||
assertNotNull(patch1);
|
||||
assertNotNull(patch2);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch1))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.DEAD, 0, 2, 3));
|
||||
when(farmingTracker.predictPatch(patch2))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.HARVESTABLE, unixNow, 3, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.COMPLETED, farmingContractManager.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractTwoCabbagesGrowing()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
final long expected1 = unixNow + 60;
|
||||
final long expected2 = unixNow + 120;
|
||||
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch1 = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
final FarmingPatch patch2 = farmingGuildPatches.get(Varbits.FARMING_4774);
|
||||
|
||||
assertNotNull(patch1);
|
||||
assertNotNull(patch2);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch1))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.GROWING, expected1, 2, 3));
|
||||
when(farmingTracker.predictPatch(patch2))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.GROWING, expected2, 1, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
assertEquals(CropState.GROWING, farmingContractManager.getContractCropState());
|
||||
// Prefer closest estimated time
|
||||
assertEquals(expected1, farmingContractManager.getCompletionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractCabbageGrowingAndCabbageDiseased()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
final long expectedTime = unixNow + 60;
|
||||
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch1 = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
final FarmingPatch patch2 = farmingGuildPatches.get(Varbits.FARMING_4774);
|
||||
|
||||
assertNotNull(patch1);
|
||||
assertNotNull(patch2);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch1))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.DISEASED, 0, 2, 3));
|
||||
when(farmingTracker.predictPatch(patch2))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.GROWING, expectedTime, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
// Prefer healthy cabbages
|
||||
assertEquals(CropState.GROWING, farmingContractManager.getContractCropState());
|
||||
assertEquals(expectedTime, farmingContractManager.getCompletionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractCabbageDiseasedAndCabbageGrowing()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
final long expectedTime = unixNow + 60;
|
||||
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch1 = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
final FarmingPatch patch2 = farmingGuildPatches.get(Varbits.FARMING_4774);
|
||||
|
||||
assertNotNull(patch1);
|
||||
assertNotNull(patch2);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch1))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.GROWING, expectedTime, 2, 3));
|
||||
when(farmingTracker.predictPatch(patch2))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.DISEASED, 0, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
// Prefer healthy cabbages
|
||||
assertEquals(CropState.GROWING, farmingContractManager.getContractCropState());
|
||||
assertEquals(expectedTime, farmingContractManager.getCompletionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractCabbageDeadAndCabbageDiseased()
|
||||
{
|
||||
// Get the two allotment patches
|
||||
final FarmingPatch patch1 = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
final FarmingPatch patch2 = farmingGuildPatches.get(Varbits.FARMING_4774);
|
||||
|
||||
assertNotNull(patch1);
|
||||
assertNotNull(patch2);
|
||||
|
||||
// Specify the two allotment patches
|
||||
when(farmingTracker.predictPatch(patch1))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.DISEASED, 0, 2, 3));
|
||||
when(farmingTracker.predictPatch(patch2))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.DEAD, 0, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
// Prefer diseased cabbages
|
||||
assertEquals(CropState.DISEASED, farmingContractManager.getContractCropState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractCabbageHarvestableAndEmptyPatch()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
|
||||
final FarmingPatch patch = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
|
||||
assertNotNull(patch);
|
||||
|
||||
when(farmingTracker.predictPatch(patch))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.HARVESTABLE, unixNow, 3, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.COMPLETED, farmingContractManager.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractCabbageDiseasedAndEmptyPatch()
|
||||
{
|
||||
final FarmingPatch patch = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
|
||||
assertNotNull(patch);
|
||||
|
||||
when(farmingTracker.predictPatch(patch))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.DISEASED, 0, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
assertEquals(CropState.DISEASED, farmingContractManager.getContractCropState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cabbageContractCabbageDeadAndEmptyPatch()
|
||||
{
|
||||
final FarmingPatch patch = farmingGuildPatches.get(Varbits.FARMING_4773);
|
||||
|
||||
assertNotNull(patch);
|
||||
|
||||
when(farmingTracker.predictPatch(patch))
|
||||
.thenReturn(new PatchPrediction(Produce.CABBAGE, CropState.DEAD, 0, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.CABBAGE);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
assertEquals(CropState.DEAD, farmingContractManager.getContractCropState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redberriesContractRedberriesHarvestable()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
|
||||
// Get the bush patch
|
||||
final FarmingPatch patch = farmingGuildPatches.get(Varbits.FARMING_4772);
|
||||
|
||||
assertNotNull(patch);
|
||||
|
||||
// For berries, Harvestable means already checked
|
||||
when(farmingTracker.predictPatch(patch))
|
||||
.thenReturn(new PatchPrediction(Produce.REDBERRIES, CropState.HARVESTABLE, unixNow, 3, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.REDBERRIES);
|
||||
|
||||
assertEquals(SummaryState.OCCUPIED, farmingContractManager.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redberriesContractRedberriesGrown()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
|
||||
// Get the bush patch
|
||||
final FarmingPatch patch = farmingGuildPatches.get(Varbits.FARMING_4772);
|
||||
|
||||
assertNotNull(patch);
|
||||
|
||||
// For berries, Growing on the last stage is ready to be checked
|
||||
when(farmingTracker.predictPatch(patch))
|
||||
.thenReturn(new PatchPrediction(Produce.REDBERRIES, CropState.GROWING, unixNow, 3, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.REDBERRIES);
|
||||
|
||||
assertEquals(SummaryState.COMPLETED, farmingContractManager.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redberriesContractRedberriesGrowing()
|
||||
{
|
||||
final long unixNow = Instant.now().getEpochSecond();
|
||||
final long expectedCompletion = unixNow + 60;
|
||||
|
||||
// Get the bush patch
|
||||
final FarmingPatch patch = farmingGuildPatches.get(Varbits.FARMING_4772);
|
||||
|
||||
assertNotNull(patch);
|
||||
|
||||
// Not ready to check
|
||||
when(farmingTracker.predictPatch(patch))
|
||||
.thenReturn(new PatchPrediction(Produce.REDBERRIES, CropState.GROWING, expectedCompletion, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.REDBERRIES);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
assertEquals(CropState.GROWING, farmingContractManager.getContractCropState());
|
||||
assertEquals(expectedCompletion, farmingContractManager.getCompletionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redberriesContractRedberriesDiseased()
|
||||
{
|
||||
// Get the bush patch
|
||||
final FarmingPatch patch = farmingGuildPatches.get(Varbits.FARMING_4772);
|
||||
|
||||
assertNotNull(patch);
|
||||
|
||||
when(farmingTracker.predictPatch(patch))
|
||||
.thenReturn(new PatchPrediction(Produce.REDBERRIES, CropState.DISEASED, 0, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.REDBERRIES);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
assertEquals(CropState.DISEASED, farmingContractManager.getContractCropState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redberriesContractRedberriesDead()
|
||||
{
|
||||
// Get the bush patch
|
||||
final FarmingPatch patch = farmingGuildPatches.get(Varbits.FARMING_4772);
|
||||
|
||||
assertNotNull(patch);
|
||||
|
||||
when(farmingTracker.predictPatch(patch))
|
||||
.thenReturn(new PatchPrediction(Produce.REDBERRIES, CropState.DEAD, 0, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.REDBERRIES);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
assertEquals(CropState.DEAD, farmingContractManager.getContractCropState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redberriesContractCadavaDead()
|
||||
{
|
||||
// Get the bush patch
|
||||
final FarmingPatch patch = farmingGuildPatches.get(Varbits.FARMING_4772);
|
||||
|
||||
assertNotNull(patch);
|
||||
|
||||
when(farmingTracker.predictPatch(patch))
|
||||
.thenReturn(new PatchPrediction(Produce.CADAVABERRIES, CropState.DEAD, 0, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.REDBERRIES);
|
||||
assertEquals(SummaryState.OCCUPIED, farmingContractManager.getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void guamContractGuamDead()
|
||||
{
|
||||
// Get the bush patch
|
||||
final FarmingPatch patch = farmingGuildPatches.get(Varbits.FARMING_4775);
|
||||
|
||||
assertNotNull(patch);
|
||||
|
||||
when(farmingTracker.predictPatch(patch))
|
||||
.thenReturn(new PatchPrediction(Produce.GUAM, CropState.DEAD, 0, 2, 3));
|
||||
|
||||
farmingContractManager.setContract(Produce.GUAM);
|
||||
|
||||
assertEquals(SummaryState.IN_PROGRESS, farmingContractManager.getSummary());
|
||||
assertEquals(CropState.DEAD, farmingContractManager.getContractCropState());
|
||||
}
|
||||
}
|
||||
@@ -80,10 +80,10 @@ public class WintertodtPluginTest
|
||||
{
|
||||
when(config.roundNotification()).thenReturn(15);
|
||||
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(35);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(35);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
//(15 * 50) / 30 = ~25
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(25);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(25);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
|
||||
verify(notifier, times(1)).notify("Wintertodt round is about to start");
|
||||
@@ -94,10 +94,10 @@ public class WintertodtPluginTest
|
||||
{
|
||||
when(config.roundNotification()).thenReturn(10);
|
||||
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(20);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(20);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
//(10 * 50) / 30 = ~16
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(16);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(16);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
|
||||
verify(notifier, times(1)).notify("Wintertodt round is about to start");
|
||||
@@ -108,10 +108,10 @@ public class WintertodtPluginTest
|
||||
{
|
||||
when(config.roundNotification()).thenReturn(5);
|
||||
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(10);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(10);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
//(5 * 50) / 30 = ~8
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(8);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(8);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
|
||||
verify(notifier, times(1)).notify("Wintertodt round is about to start");
|
||||
@@ -122,17 +122,17 @@ public class WintertodtPluginTest
|
||||
{
|
||||
when(config.roundNotification()).thenReturn(5);
|
||||
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(0);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(0);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(10);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(10);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(8);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(8);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(6);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(6);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(5);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(5);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(4);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(4);
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
|
||||
verify(notifier, times(1)).notify("Wintertodt round is about to start");
|
||||
@@ -142,7 +142,7 @@ public class WintertodtPluginTest
|
||||
public void matchStartingNotification_shouldNotNotify_whenNoneOptionSelected()
|
||||
{
|
||||
when(config.roundNotification()).thenReturn(5);
|
||||
when(client.getVar(Varbits.WINTERTODT_TIMER)).thenReturn(25);
|
||||
when(client.getVarbitValue(Varbits.WINTERTODT_TIMER)).thenReturn(25);
|
||||
|
||||
wintertodtPlugin.onVarbitChanged(new VarbitChanged());
|
||||
verify(notifier, times(0)).notify("Wintertodt round is about to start");
|
||||
|
||||
Reference in New Issue
Block a user