Merge branch 'master' into an-not-taters

This commit is contained in:
Ganom
2019-11-20 16:20:25 -05:00
committed by GitHub
141 changed files with 1064 additions and 608 deletions

View File

@@ -33,6 +33,7 @@ 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.WidgetHiddenChanged;
import net.runelite.client.events.ConfigChanged;
import net.runelite.api.events.VarbitChanged;
import net.runelite.api.widgets.Widget;
@@ -44,8 +45,11 @@ 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;
@@ -174,6 +178,61 @@ public class AttackStylesPluginTest
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)

View File

@@ -0,0 +1,144 @@
/*
* 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.ui.overlay.OverlayManager;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Ignore;
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;
@Before
public void before()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
@Ignore
public void testLogs()
{
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You get some logs.", "", 0);
woodcuttingPlugin.onChatMessage(chatMessage);
assertNotNull(woodcuttingPlugin.getSession());
}
@Test
@Ignore
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
@Ignore
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);
}
}