PageRenderTime 69ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/runelite-client/src/test/java/net/runelite/client/plugins/screenshot/ScreenshotPluginTest.java

https://bitbucket.org/jjpx/runelite
Java | 211 lines | 146 code | 41 blank | 24 comment | 0 complexity | 1b5bace0bc27b52f751b587fb27b32ee MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /*
  2. * Copyright (c) 2018, Adam <Adam@sigterm.info>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. package net.runelite.client.plugins.screenshot;
  26. import com.google.inject.Guice;
  27. import com.google.inject.testing.fieldbinder.Bind;
  28. import com.google.inject.testing.fieldbinder.BoundFieldModule;
  29. import java.util.concurrent.ScheduledExecutorService;
  30. import java.util.function.Consumer;
  31. import javax.inject.Inject;
  32. import static net.runelite.api.ChatMessageType.SERVER;
  33. import net.runelite.api.Client;
  34. import net.runelite.api.events.ChatMessage;
  35. import net.runelite.api.events.WidgetHiddenChanged;
  36. import net.runelite.api.widgets.Widget;
  37. import static net.runelite.api.widgets.WidgetID.DIALOG_SPRITE_GROUP_ID;
  38. import static net.runelite.api.widgets.WidgetID.LEVEL_UP_GROUP_ID;
  39. import static net.runelite.api.widgets.WidgetInfo.DIALOG_SPRITE_TEXT;
  40. import static net.runelite.api.widgets.WidgetInfo.LEVEL_UP_LEVEL;
  41. import static net.runelite.api.widgets.WidgetInfo.PACK;
  42. import net.runelite.client.Notifier;
  43. import net.runelite.client.config.RuneLiteConfig;
  44. import net.runelite.client.ui.ClientUI;
  45. import net.runelite.client.ui.DrawManager;
  46. import static org.junit.Assert.assertEquals;
  47. import org.junit.Before;
  48. import org.junit.Test;
  49. import org.junit.runner.RunWith;
  50. import org.mockito.Matchers;
  51. import org.mockito.Mock;
  52. import static org.mockito.Mockito.mock;
  53. import static org.mockito.Mockito.verify;
  54. import static org.mockito.Mockito.when;
  55. import org.mockito.runners.MockitoJUnitRunner;
  56. @RunWith(MockitoJUnitRunner.class)
  57. public class ScreenshotPluginTest
  58. {
  59. private static final String CLUE_SCROLL = "<col=3300ff>You have completed 28 medium Treasure Trails</col>";
  60. private static final String BARROWS_CHEST = "Your Barrows chest count is <col=ff0000>310</col>";
  61. private static final String RAIDS_CHEST = "Your completed Chambers of Xeric count is: <col=ff0000>489.</col>";
  62. @Mock
  63. @Bind
  64. private Client client;
  65. @Inject
  66. private ScreenshotPlugin screenshotPlugin;
  67. @Mock
  68. @Bind
  69. private ScreenshotConfig screenshotConfig;
  70. @Mock
  71. @Bind
  72. Notifier notifier;
  73. @Mock
  74. @Bind
  75. ClientUI clientUi;
  76. @Mock
  77. @Bind
  78. DrawManager drawManager;
  79. @Mock
  80. @Bind
  81. RuneLiteConfig config;
  82. @Mock
  83. @Bind
  84. ScheduledExecutorService service;
  85. @Before
  86. public void before()
  87. {
  88. Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
  89. when(screenshotConfig.screenshotRewards()).thenReturn(true);
  90. when(screenshotConfig.screenshotLevels()).thenReturn(true);
  91. }
  92. @Test
  93. public void testClueScroll()
  94. {
  95. ChatMessage chatMessageEvent = new ChatMessage(SERVER, "Seth", CLUE_SCROLL, null);
  96. screenshotPlugin.onChatMessage(chatMessageEvent);
  97. assertEquals("medium", screenshotPlugin.getClueType());
  98. assertEquals(28, screenshotPlugin.getClueNumber());
  99. }
  100. @Test
  101. public void testBarrowsChest()
  102. {
  103. ChatMessage chatMessageEvent = new ChatMessage(SERVER, "Seth", BARROWS_CHEST, null);
  104. screenshotPlugin.onChatMessage(chatMessageEvent);
  105. assertEquals(310, screenshotPlugin.getBarrowsNumber());
  106. }
  107. @Test
  108. public void testRaidsChest()
  109. {
  110. ChatMessage chatMessageEvent = new ChatMessage(SERVER, "Seth", RAIDS_CHEST, null);
  111. screenshotPlugin.onChatMessage(chatMessageEvent);
  112. assertEquals(489, screenshotPlugin.getRaidsNumber());
  113. }
  114. @Test
  115. public void testHitpointsLevel99()
  116. {
  117. Widget widget = mock(Widget.class);
  118. when(widget.getId()).thenReturn(PACK(LEVEL_UP_GROUP_ID, 0));
  119. Widget levelChild = mock(Widget.class);
  120. when(client.getWidget(Matchers.eq(LEVEL_UP_LEVEL))).thenReturn(levelChild);
  121. when(levelChild.getText()).thenReturn("Your Hitpoints are now 99.");
  122. assertEquals("Hitpoints(99)", screenshotPlugin.parseLevelUpWidget(LEVEL_UP_LEVEL));
  123. WidgetHiddenChanged event = new WidgetHiddenChanged();
  124. event.setWidget(widget);
  125. screenshotPlugin.hideWidgets(event);
  126. verify(drawManager).requestNextFrameListener(Matchers.any(Consumer.class));
  127. }
  128. @Test
  129. public void testFiremakingLevel9()
  130. {
  131. Widget widget = mock(Widget.class);
  132. when(widget.getId()).thenReturn(PACK(LEVEL_UP_GROUP_ID, 0));
  133. Widget levelChild = mock(Widget.class);
  134. when(client.getWidget(Matchers.eq(LEVEL_UP_LEVEL))).thenReturn(levelChild);
  135. when(levelChild.getText()).thenReturn("Your Firemaking level is now 9.");
  136. assertEquals("Firemaking(9)", screenshotPlugin.parseLevelUpWidget(LEVEL_UP_LEVEL));
  137. WidgetHiddenChanged event = new WidgetHiddenChanged();
  138. event.setWidget(widget);
  139. screenshotPlugin.hideWidgets(event);
  140. verify(drawManager).requestNextFrameListener(Matchers.any(Consumer.class));
  141. }
  142. @Test
  143. public void testAttackLevel70()
  144. {
  145. Widget widget = mock(Widget.class);
  146. when(widget.getId()).thenReturn(PACK(LEVEL_UP_GROUP_ID, 0));
  147. Widget levelChild = mock(Widget.class);
  148. when(client.getWidget(Matchers.eq(LEVEL_UP_LEVEL))).thenReturn(levelChild);
  149. when(levelChild.getText()).thenReturn("Your Attack level is now 70.");
  150. assertEquals("Attack(70)", screenshotPlugin.parseLevelUpWidget(LEVEL_UP_LEVEL));
  151. WidgetHiddenChanged event = new WidgetHiddenChanged();
  152. event.setWidget(widget);
  153. screenshotPlugin.hideWidgets(event);
  154. verify(drawManager).requestNextFrameListener(Matchers.any(Consumer.class));
  155. }
  156. @Test
  157. public void testHunterLevel2()
  158. {
  159. Widget widget = mock(Widget.class);
  160. when(widget.getId()).thenReturn(PACK(DIALOG_SPRITE_GROUP_ID, 0));
  161. Widget levelChild = mock(Widget.class);
  162. when(client.getWidget(Matchers.eq(DIALOG_SPRITE_TEXT))).thenReturn(levelChild);
  163. when(levelChild.getText()).thenReturn("Your Hunter level is now 2.");
  164. assertEquals("Hunter(2)", screenshotPlugin.parseLevelUpWidget(DIALOG_SPRITE_TEXT));
  165. WidgetHiddenChanged event = new WidgetHiddenChanged();
  166. event.setWidget(widget);
  167. screenshotPlugin.hideWidgets(event);
  168. verify(drawManager).requestNextFrameListener(Matchers.any(Consumer.class));
  169. }
  170. }