Facebook
From Sweet Pintail, 4 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 217
  1. /*
  2.  * Copyright (c) 2018, Adam <[email protected]>
  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.itemcharges;
  26.  
  27. import com.google.inject.Guice;
  28. import com.google.inject.Inject;
  29. import com.google.inject.testing.fieldbinder.Bind;
  30. import com.google.inject.testing.fieldbinder.BoundFieldModule;
  31. import java.util.concurrent.ScheduledExecutorService;
  32. import net.runelite.api.ChatMessageType;
  33. import net.runelite.api.Client;
  34. import net.runelite.api.events.ChatMessage;
  35. import net.runelite.client.Notifier;
  36. import net.runelite.client.config.RuneLiteConfig;
  37. import net.runelite.client.ui.overlay.OverlayManager;
  38. import org.junit.Before;
  39. import org.junit.Test;
  40. import org.junit.runner.RunWith;
  41. import static org.mockito.Matchers.eq;
  42. import org.mockito.Mock;
  43. import static org.mockito.Mockito.reset;
  44. import static org.mockito.Mockito.verify;
  45. import org.mockito.runners.MockitoJUnitRunner;
  46.  
  47. @RunWith(MockitoJUnitRunner.class)
  48. public class ItemChargePluginTest
  49. {
  50.         private static final String CHECK = "Your dodgy necklace has 10 charges left.";
  51.         private static final String PROTECT = "Your dodgy necklace protects you. It has 9 charges left.";
  52.         private static final String PROTECT_1 = "Your dodgy necklace protects you. <col=ff0000>It has 1 charge left.</col>";
  53.         private static final String BREAK = "Your dodgy necklace protects you. <col=ff0000>It then crumbles to dust.</col>";
  54.  
  55.         private static final String CHECK_RING_OF_FORGING = "You can smelt 140 more pieces of iron ore before a ring melts.";
  56.         private static final String USED_RING_OF_FORGING = "You retrieve a bar of iron.";
  57.         private static final String BREAK_RING_OF_FORGING = "Your Ring of Forging has melted.";
  58.  
  59.         @Mock
  60.         @Bind
  61.         private Client client;
  62.  
  63.         @Mock
  64.         @Bind
  65.         private ScheduledExecutorService scheduledExecutorService;
  66.  
  67.         @Mock
  68.         @Bind
  69.         private RuneLiteConfig runeLiteConfig;
  70.  
  71.         @Mock
  72.         @Bind
  73.         private OverlayManager overlayManager;
  74.  
  75.         @Mock
  76.         @Bind
  77.         private Notifier notifier;
  78.  
  79.         @Mock
  80.         @Bind
  81.         private ItemChargeConfig config;
  82.  
  83.         @Inject
  84.         private ItemChargePlugin itemChargePlugin;
  85.  
  86.         @Before
  87.         public void before()
  88.         {
  89.                 Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
  90.         }
  91.  
  92.         @Test
  93.         public void testOnChatMessage()
  94.         {
  95.                 ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHECK, "", 0);
  96.                 itemChargePlugin.onChatMessage(chatMessage);
  97.                 verify(config).dodgyNecklace(eq(10));
  98.                 reset(config);
  99.  
  100.                 chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", PROTECT, "", 0);
  101.                 itemChargePlugin.onChatMessage(chatMessage);
  102.                 verify(config).dodgyNecklace(eq(9));
  103.                 reset(config);
  104.  
  105.                 chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", PROTECT_1, "", 0);
  106.                 itemChargePlugin.onChatMessage(chatMessage);
  107.                 verify(config).dodgyNecklace(eq(1));
  108.                 reset(config);
  109.  
  110.                 chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", BREAK, "", 0);
  111.                 itemChargePlugin.onChatMessage(chatMessage);
  112.                 verify(config).dodgyNecklace(eq(10));
  113.                 reset(config);
  114.  
  115.                 chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", CHECK_RING_OF_FORGING, "", 0);
  116.                 itemChargePlugin.onChatMessage(chatMessage);
  117. //              verify(config).ringOfForging(eq(140));
  118.                 reset(config);
  119.  
  120.                 chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", USED_RING_OF_FORGING, "", 0);
  121.                 itemChargePlugin.onChatMessage(chatMessage);
  122.                 verify(config).ringOfForging(eq(-1));
  123.                 reset(config);
  124.  
  125.                 chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", BREAK_RING_OF_FORGING, "", 0);
  126.                 itemChargePlugin.onChatMessage(chatMessage);
  127. //              verify(config).ringOfForging(eq(140));
  128.                 reset(config);
  129.         }
  130. }