slayer plugin: fix parsing points and streaks with commas

This commit is contained in:
Adam
2018-07-13 08:33:05 -04:00
parent 70059a9bf1
commit e2b9d0b00a
2 changed files with 35 additions and 5 deletions

View File

@@ -58,9 +58,12 @@ public class SlayerPluginTest
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.";
@@ -158,6 +161,21 @@ public class SlayerPluginTest
assertEquals(222, slayerPlugin.getAmount());
}
@Test
public void testRewardPointsWidget()
{
Widget rewardBar = mock(Widget.class);
Widget rewardBarText = mock(Widget.class);
Widget[] rewardBarChildren = new Widget[]{rewardBarText};
when(rewardBar.getDynamicChildren()).thenReturn(rewardBarChildren);
when(rewardBarText.getText()).thenReturn(REWARD_POINTS);
when(client.getWidget(WidgetInfo.SLAYER_REWARDS_TOPBAR)).thenReturn(rewardBar);
slayerPlugin.onGameTick(new GameTick());
assertEquals(17566, slayerPlugin.getPoints());
}
@Test
public void testOneTask()
{
@@ -192,6 +210,18 @@ public class SlayerPluginTest
assertEquals(18_000, slayerPlugin.getPoints());
}
@Test
public void testLargeStreak()
{
ChatMessage chatMessageEvent = new ChatMessage(SERVER, "Perterter", TASK_LARGE_STREAK, null);
slayerPlugin.onChatMessage(chatMessageEvent);
assertEquals(2465, slayerPlugin.getStreak());
assertEquals("", slayerPlugin.getTaskName());
assertEquals(0, slayerPlugin.getAmount());
assertEquals(17_566_000, slayerPlugin.getPoints());
}
@Test
public void testComplete()
{