From 560a738845115958081cca6ee12d8beaa68c4535 Mon Sep 17 00:00:00 2001 From: JZomerlei Date: Sun, 10 Nov 2019 11:11:07 -0500 Subject: [PATCH] woodcutting plugin: add arctic pine logs --- .../woodcutting/WoodcuttingPlugin.java | 5 +- .../woodcutting/WoodcuttingPluginTest.java | 130 ++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 runelite-client/src/test/java/net/runelite/client/plugins/woodcutting/WoodcuttingPluginTest.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/woodcutting/WoodcuttingPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/woodcutting/WoodcuttingPlugin.java index 04df4a2c11..01ced70693 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/woodcutting/WoodcuttingPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/woodcutting/WoodcuttingPlugin.java @@ -29,6 +29,7 @@ import java.time.Duration; import java.time.Instant; import java.util.HashSet; import java.util.Set; +import java.util.regex.Pattern; import javax.inject.Inject; import lombok.Getter; import net.runelite.api.ChatMessageType; @@ -63,6 +64,8 @@ import net.runelite.client.ui.overlay.OverlayMenuEntry; @PluginDependency(XpTrackerPlugin.class) public class WoodcuttingPlugin extends Plugin { + private static final Pattern WOOD_CUT_PATTERN = Pattern.compile("You get (?:some|an)[\\w ]+(?:logs?|mushrooms)\\."); + @Inject private Notifier notifier; @@ -148,7 +151,7 @@ public class WoodcuttingPlugin extends Plugin { if (event.getType() == ChatMessageType.SPAM || event.getType() == ChatMessageType.GAMEMESSAGE) { - if (event.getMessage().startsWith("You get some") && (event.getMessage().endsWith("logs.") || event.getMessage().endsWith("mushrooms."))) + if (WOOD_CUT_PATTERN.matcher(event.getMessage()).matches()) { if (session == null) { diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/woodcutting/WoodcuttingPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/woodcutting/WoodcuttingPluginTest.java new file mode 100644 index 0000000000..ed9c6a599a --- /dev/null +++ b/runelite-client/src/test/java/net/runelite/client/plugins/woodcutting/WoodcuttingPluginTest.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2019, Jordan Zomerlei + * Copyright (c) 2019, Adam + * 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 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.ui.overlay.OverlayManager; +import static org.junit.Assert.assertNotNull; +import org.junit.Before; +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 + 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 + public void testLogs() + { + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You get some logs.", "", 0); + woodcuttingPlugin.onChatMessage(chatMessage); + assertNotNull(woodcuttingPlugin.getSession()); + } + + @Test + 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 + 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); + } +} \ No newline at end of file