openrune: just about finish rework, gets to login
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* 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.chat;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.awt.Color;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.client.config.ChatColorConfig;
|
||||
import net.runelite.client.config.OpenOSRSConfig;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ChatMessageManagerTest
|
||||
{
|
||||
@Mock
|
||||
@Bind
|
||||
private Client client;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private ChatColorConfig chatColorConfig;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private OpenOSRSConfig openOSRSConfig;
|
||||
|
||||
@Inject
|
||||
private ChatMessageManager chatMessageManager;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
|
||||
|
||||
chatMessageManager.loadColors();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onChatMessage()
|
||||
{
|
||||
when(chatColorConfig.opaquePublicChat()).thenReturn(Color.decode("#b20000"));
|
||||
|
||||
chatMessageManager.loadColors();
|
||||
|
||||
ChatMessage chatMessage = new ChatMessage();
|
||||
chatMessage.setType(ChatMessageType.PUBLICCHAT);
|
||||
|
||||
MessageNode messageNode = mock(MessageNode.class);
|
||||
chatMessage.setMessageNode(messageNode);
|
||||
|
||||
when(messageNode.getValue()).thenReturn("Your dodgy necklace protects you. It has <col=ff0000>1</col> charge left.");
|
||||
chatMessageManager.onChatMessage(chatMessage);
|
||||
|
||||
verify(messageNode).setValue(eq("<col=b20000>Your dodgy necklace protects you. It has <col=ff0000>1<col=b20000> charge left.</col>"));
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.config;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.io.File;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.account.AccountSession;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ConfigManagerTest
|
||||
{
|
||||
@Mock
|
||||
@Bind
|
||||
Client client;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
EventBus eventBus;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
ScheduledExecutorService executor;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
RuneLiteConfig runeliteConfig;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private OpenOSRSConfig openOSRSConfig;
|
||||
|
||||
@Bind
|
||||
@Named("config")
|
||||
private File config = RuneLite.DEFAULT_CONFIG_FILE;
|
||||
|
||||
@Inject
|
||||
ConfigManager manager;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfig()
|
||||
{
|
||||
AccountSession accountSession = new AccountSession(UUID.randomUUID(), Instant.now());
|
||||
accountSession.setUsername("test");
|
||||
|
||||
manager.setConfiguration("test", "key", "moo");
|
||||
|
||||
TestConfig conf = manager.getConfig(TestConfig.class);
|
||||
Assert.assertEquals("moo", conf.key());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfigDefault()
|
||||
{
|
||||
AccountSession accountSession = new AccountSession(UUID.randomUUID(), Instant.now());
|
||||
accountSession.setUsername("test");
|
||||
|
||||
TestConfig conf = manager.getConfig(TestConfig.class);
|
||||
Assert.assertEquals("default", conf.key());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetConfig()
|
||||
{
|
||||
AccountSession accountSession = new AccountSession(UUID.randomUUID(), Instant.now());
|
||||
accountSession.setUsername("test");
|
||||
|
||||
TestConfig conf = manager.getConfig(TestConfig.class);
|
||||
conf.key("new value");
|
||||
|
||||
Assert.assertEquals("new value", conf.key());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfigDescriptor()
|
||||
{
|
||||
AccountSession accountSession = new AccountSession(UUID.randomUUID(), Instant.now());
|
||||
accountSession.setUsername("test");
|
||||
|
||||
TestConfig conf = manager.getConfig(TestConfig.class);
|
||||
ConfigDescriptor descriptor = manager.getConfigDescriptor(conf);
|
||||
Assert.assertEquals(2, descriptor.getItems().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResetNullDefaultConfig()
|
||||
{
|
||||
TestConfig conf = manager.getConfig(TestConfig.class);
|
||||
ConfigDescriptor descriptor = manager.getConfigDescriptor(conf);
|
||||
conf.nullDefaultKey("new value");
|
||||
|
||||
manager.unsetConfiguration(descriptor.getGroup().value(), "nullDefaultKey");
|
||||
manager.setDefaultConfiguration(conf, false);
|
||||
Assert.assertNull(conf.nullDefaultKey());
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.config;
|
||||
|
||||
@ConfigGroup("test")
|
||||
public interface TestConfig extends Config
|
||||
{
|
||||
@ConfigItem(
|
||||
keyName = "key",
|
||||
name = "Key Name",
|
||||
description = "value"
|
||||
)
|
||||
default String key()
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "key",
|
||||
name = "Key Name",
|
||||
description = "value"
|
||||
)
|
||||
void key(String key);
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "nullDefaultKey",
|
||||
name = "Key Name",
|
||||
description = "value"
|
||||
)
|
||||
void nullDefaultKey(String key);
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "nullDefaultKey",
|
||||
name = "Key Name",
|
||||
description = "value"
|
||||
)
|
||||
default String nullDefaultKey()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,348 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Ron Young <https://github.com/raiyni>
|
||||
* 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.game;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import static net.runelite.api.ItemID.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ItemVariationMappingTest
|
||||
{
|
||||
private static final Map<Integer, Integer> ITEMS_MAP = new LinkedHashMap<Integer, Integer>()
|
||||
{{
|
||||
put(_12_ANCHOVY_PIZZA, ANCHOVY_PIZZA);
|
||||
put(_12_MEAT_PIZZA, MEAT_PIZZA);
|
||||
put(_12_PINEAPPLE_PIZZA, PINEAPPLE_PIZZA);
|
||||
put(_12_PLAIN_PIZZA, PLAIN_PIZZA);
|
||||
put(ADAMANT_PLATELEGS_T, ADAMANT_PLATELEGS);
|
||||
put(ADAMANT_PLATESKIRT_T, ADAMANT_PLATESKIRT);
|
||||
put(AGILITY_CAPET, AGILITY_CAPE);
|
||||
put(AGILITY_MIX1, AGILITY_MIX2);
|
||||
put(AGILITY_MIX2, AGILITY_MIX2);
|
||||
put(AHRIMS_ROBETOP_100, AHRIMS_ROBETOP);
|
||||
put(AHRIMS_ROBETOP_25, AHRIMS_ROBETOP);
|
||||
put(AHRIMS_ROBETOP_50, AHRIMS_ROBETOP);
|
||||
put(AHRIMS_ROBETOP_75, AHRIMS_ROBETOP);
|
||||
put(AHRIMS_STAFF_0, AHRIMS_STAFF);
|
||||
put(AMULET_OF_GLORY5, AMULET_OF_GLORY);
|
||||
put(AMULET_OF_GLORY6, AMULET_OF_GLORY);
|
||||
put(AMULET_OF_MAGIC_T, AMULET_OF_MAGIC);
|
||||
put(ANCIENT_PAGE_1, ANCIENT_PAGE);
|
||||
put(ANCIENT_PAGE_2, ANCIENT_PAGE);
|
||||
put(ANTIDOTE2, ANTIDOTE_UNF);
|
||||
put(ANTIDOTE3, ANTIDOTE_UNF);
|
||||
put(ANTIDOTE4, ANTIDOTE_UNF);
|
||||
put(ANTIDOTE1_5958, ANTIDOTE_UNF);
|
||||
put(ANTIDOTE2_5956, ANTIDOTE_UNF);
|
||||
put(APPLES2, APPLES1);
|
||||
put(APPLES3, APPLES1);
|
||||
put(APPLES4, APPLES1);
|
||||
put(APPLES5, APPLES1);
|
||||
put(ARCHERS_RING_I, ARCHERS_RING);
|
||||
put(ASGARNIAN_ALEM4, ASGARNIAN_ALE);
|
||||
put(ATTACK_CAPET, ATTACK_CAPE);
|
||||
put(ATTACK_MIX1, ATTACK_MIX2);
|
||||
put(ATTACK_MIX2, ATTACK_MIX2);
|
||||
put(ATTACK_POTION1, ATTACK_POTION3);
|
||||
put(BANANAS2, BANANAS1);
|
||||
put(BANANAS3, BANANAS1);
|
||||
put(BANANAS4, BANANAS1);
|
||||
put(BANANAS5, BANANAS1);
|
||||
put(BANDOS_PAGE_1, BANDOS_PAGE_1);
|
||||
put(BLACK_KITESHIELD_T, BLACK_KITESHIELD);
|
||||
put(BLACK_MASK_1, BLACK_MASK_10);
|
||||
put(BLACK_MASK_2, BLACK_MASK_10);
|
||||
put(BLACK_MASK_3, BLACK_MASK_10);
|
||||
put(BLACK_MASK_4, BLACK_MASK_10);
|
||||
put(BLUE_SKIRT_T, BLUE_SKIRT);
|
||||
put(BLUE_WIZARD_HAT_T, BLUE_WIZARD_HAT);
|
||||
put(BLUE_WIZARD_ROBE_T, BLUE_WIZARD_ROBE);
|
||||
put(BOOK_PAGE_1, BOOK_PAGE_1);
|
||||
put(BOOK_PAGE_2, BOOK_PAGE_1);
|
||||
put(BROODOO_SHIELD_9, BROODOO_SHIELD_10);
|
||||
put(BROWN_SPICE_1, BROWN_SPICE_4);
|
||||
put(BROWN_SPICE_2, BROWN_SPICE_4);
|
||||
put(BROWN_SPICE_3, BROWN_SPICE_4);
|
||||
put(BROWN_SPICE_4, BROWN_SPICE_4);
|
||||
put(CASKET_ELITE, CASKET);
|
||||
put(CASKET_HARD, CASKET);
|
||||
put(CASKET_MEDIUM, CASKET);
|
||||
put(CASTLE_SKETCH_1, CASTLE_SKETCH_1);
|
||||
put(CASTLE_SKETCH_2, CASTLE_SKETCH_1);
|
||||
put(CHEFS_DELIGHTM2, CHEFS_DELIGHT);
|
||||
put(CHEFS_DELIGHTM3, CHEFS_DELIGHT);
|
||||
put(CHEFS_DELIGHTM4, CHEFS_DELIGHT);
|
||||
put(CIDER1, CIDER);
|
||||
put(CIDER2, CIDER);
|
||||
put(CLUE_NEST_ELITE, CLUE_NEST_EASY);
|
||||
put(CLUE_NEST_HARD, CLUE_NEST_EASY);
|
||||
put(CLUE_NEST_MEDIUM, CLUE_NEST_EASY);
|
||||
put(CLUE_SCROLL_EASY, CLUE_SCROLL);
|
||||
put(CLUE_SCROLL_ELITE, CLUE_SCROLL);
|
||||
put(COMMORB_V2, COMMORB_V2);
|
||||
put(COMPOST_POTION1, COMPOST_POTION4);
|
||||
put(COMPOST_POTION2, COMPOST_POTION4);
|
||||
put(COMPOST_POTION3, COMPOST_POTION4);
|
||||
put(COMPOST_POTION4, COMPOST_POTION4);
|
||||
put(CRYSTAL_BOW_510_I, NEW_CRYSTAL_BOW);
|
||||
put(CRYSTAL_BOW_510, NEW_CRYSTAL_BOW);
|
||||
put(CRYSTAL_BOW_610_I, NEW_CRYSTAL_BOW);
|
||||
put(CRYSTAL_BOW_610, NEW_CRYSTAL_BOW);
|
||||
put(CRYSTAL_BOW_710_I, NEW_CRYSTAL_BOW);
|
||||
put(CRYSTAL_HALBERD_510_I, NEW_CRYSTAL_HALBERD_FULL_I);
|
||||
put(CRYSTAL_HALBERD_510, NEW_CRYSTAL_HALBERD_FULL_I);
|
||||
put(CRYSTAL_HALBERD_610_I, NEW_CRYSTAL_HALBERD_FULL_I);
|
||||
put(CRYSTAL_HALBERD_610, NEW_CRYSTAL_HALBERD_FULL_I);
|
||||
put(CRYSTAL_HALBERD_710_I, NEW_CRYSTAL_HALBERD_FULL_I);
|
||||
put(CRYSTAL_SHIELD_510_I, NEW_CRYSTAL_SHIELD);
|
||||
put(CRYSTAL_SHIELD_510, NEW_CRYSTAL_SHIELD);
|
||||
put(CRYSTAL_SHIELD_610_I, NEW_CRYSTAL_SHIELD);
|
||||
put(CRYSTAL_SHIELD_610, NEW_CRYSTAL_SHIELD);
|
||||
put(CRYSTAL_SHIELD_710_I, NEW_CRYSTAL_SHIELD);
|
||||
put(DEFENCE_POTION2, DEFENCE_POTION3);
|
||||
put(DEFENCE_POTION3, DEFENCE_POTION3);
|
||||
put(DEFENCE_POTION4, DEFENCE_POTION3);
|
||||
put(DESERT_AMULET_1, DESERT_AMULET);
|
||||
put(DESERT_AMULET_2, DESERT_AMULET);
|
||||
put(DHAROKS_PLATEBODY_50, DHAROKS_PLATEBODY);
|
||||
put(DHAROKS_PLATEBODY_75, DHAROKS_PLATEBODY);
|
||||
put(DHAROKS_PLATELEGS_0, DHAROKS_PLATELEGS);
|
||||
put(DHAROKS_PLATELEGS_100, DHAROKS_PLATELEGS);
|
||||
put(DHAROKS_PLATELEGS_25, DHAROKS_PLATELEGS);
|
||||
put(DRAGON_BITTERM3, DRAGON_BITTER);
|
||||
put(DRAGON_BITTERM4, DRAGON_BITTER);
|
||||
put(DRAGON_DEFENDER_T, DRAGON_DEFENDER);
|
||||
put(DRAGONSTONE_BOLTS, DRAGONSTONE_BOLTS_E);
|
||||
put(DRAGONSTONE_DRAGON_BOLTS, DRAGONSTONE_DRAGON_BOLTS_E);
|
||||
put(ENCHANTED_LYRE2, ENCHANTED_LYRE);
|
||||
put(ENCHANTED_LYRE3, ENCHANTED_LYRE);
|
||||
put(ENCHANTED_LYRE4, ENCHANTED_LYRE);
|
||||
put(ENCHANTED_LYRE5, ENCHANTED_LYRE);
|
||||
put(ENERGY_MIX1, ENERGY_MIX2);
|
||||
put(EXTENDED_SUPER_ANTIFIRE_MIX1, EXTENDED_SUPER_ANTIFIRE_MIX2);
|
||||
put(EXTENDED_SUPER_ANTIFIRE_MIX2, EXTENDED_SUPER_ANTIFIRE_MIX2);
|
||||
put(EXTENDED_SUPER_ANTIFIRE1, EXTENDED_SUPER_ANTIFIRE4);
|
||||
put(EXTENDED_SUPER_ANTIFIRE2, EXTENDED_SUPER_ANTIFIRE4);
|
||||
put(EXTENDED_SUPER_ANTIFIRE3, EXTENDED_SUPER_ANTIFIRE4);
|
||||
put(FRAGMENT_1, FRAGMENT_1);
|
||||
put(FRAGMENT_2, FRAGMENT_1);
|
||||
put(FRAGMENT_3, FRAGMENT_1);
|
||||
put(FREMENNIK_SEA_BOOTS_1, FREMENNIK_SEA_BOOTS);
|
||||
put(FREMENNIK_SEA_BOOTS_2, FREMENNIK_SEA_BOOTS);
|
||||
put(GAMES_NECKLACE3, GAMES_NECKLACE8);
|
||||
put(GAMES_NECKLACE4, GAMES_NECKLACE8);
|
||||
put(GAMES_NECKLACE5, GAMES_NECKLACE8);
|
||||
put(GAMES_NECKLACE6, GAMES_NECKLACE8);
|
||||
put(GAMES_NECKLACE7, GAMES_NECKLACE8);
|
||||
put(GREENMANS_ALE4, GREENMANS_ALE);
|
||||
put(GREENMANS_ALEM1, GREENMANS_ALE);
|
||||
put(GREENMANS_ALEM2, GREENMANS_ALE);
|
||||
put(GREENMANS_ALEM3, GREENMANS_ALE);
|
||||
put(GREENMANS_ALEM4, GREENMANS_ALE);
|
||||
put(GUTHANS_PLATEBODY_75, GUTHANS_PLATEBODY);
|
||||
put(GUTHANS_WARSPEAR_0, GUTHANS_WARSPEAR);
|
||||
put(GUTHANS_WARSPEAR_100, GUTHANS_WARSPEAR);
|
||||
put(GUTHANS_WARSPEAR_25, GUTHANS_WARSPEAR);
|
||||
put(GUTHANS_WARSPEAR_50, GUTHANS_WARSPEAR);
|
||||
put(HALF_A_GARDEN_PIE, PART_GARDEN_PIE);
|
||||
put(HALF_A_MEAT_PIE, MEAT_PIE);
|
||||
put(MUSHROOM_PIE, HALF_A_MUSHROOM_PIE);
|
||||
put(HALF_A_REDBERRY_PIE, REDBERRY_PIE);
|
||||
put(HALF_A_ROCK, ROCK);
|
||||
put(HUNTING_MIX1, HUNTING_MIX2);
|
||||
put(HUNTING_MIX2, HUNTING_MIX2);
|
||||
put(IMPINABOX1, IMPINABOX2);
|
||||
put(IMPINABOX2, IMPINABOX2);
|
||||
put(IRON_FULL_HELM_T, IRON_FULL_HELM);
|
||||
put(KARILS_COIF_100, KARILS_COIF);
|
||||
put(KARILS_COIF_25, KARILS_COIF);
|
||||
put(KARILS_COIF_50, KARILS_COIF);
|
||||
put(KARILS_COIF_75, KARILS_COIF);
|
||||
put(KARILS_CROSSBOW_0, KARILS_CROSSBOW);
|
||||
put(KEY_MEDIUM, KEY);
|
||||
put(KODAI_POTION_1, KODAI_POTION_1);
|
||||
put(KODAI_POTION_2, KODAI_POTION_1);
|
||||
put(KODAI_POTION_3, KODAI_POTION_1);
|
||||
put(KODAI_POTION_4, KODAI_POTION_1);
|
||||
put(MAGIC_POTION1, MAGIC_POTION4);
|
||||
put(MAGIC_POTION2, MAGIC_POTION4);
|
||||
put(MAGIC_POTION3, MAGIC_POTION4);
|
||||
put(MAGIC_POTION4, MAGIC_POTION4);
|
||||
put(MAGIC_SHORTBOW_I, MAGIC_SHORTBOW_U);
|
||||
put(MITHRIL_FULL_HELM_T, MITHRIL_FULL_HELM);
|
||||
put(MITHRIL_KITESHIELD_T, MITHRIL_KITESHIELD);
|
||||
put(MITHRIL_PLATEBODY_T, MITHRIL_PLATEBODY);
|
||||
put(MITHRIL_PLATELEGS_T, MITHRIL_PLATELEGS);
|
||||
put(MITHRIL_PLATESKIRT_T, MITHRIL_PLATESKIRT);
|
||||
put(NECKLACE_OF_PASSAGE1, NECKLACE_OF_PASSAGE5);
|
||||
put(NECKLACE_OF_PASSAGE2, NECKLACE_OF_PASSAGE5);
|
||||
put(NECKLACE_OF_PASSAGE3, NECKLACE_OF_PASSAGE5);
|
||||
put(NECKLACE_OF_PASSAGE4, NECKLACE_OF_PASSAGE5);
|
||||
put(NECKLACE_OF_PASSAGE5, NECKLACE_OF_PASSAGE5);
|
||||
put(OLIVE_OIL4, OLIVE_OIL4);
|
||||
put(ONIONS1, ONIONS1);
|
||||
put(ONIONS2, ONIONS1);
|
||||
put(ONIONS3, ONIONS1);
|
||||
put(ONIONS4, ONIONS1);
|
||||
put(ORANGES3, ORANGES1);
|
||||
put(ORANGES4, ORANGES1);
|
||||
put(ORANGES5, ORANGES1);
|
||||
put(OVERLOAD_1, OVERLOAD_4);
|
||||
put(OVERLOAD_2, OVERLOAD_4);
|
||||
put(PHARAOHS_SCEPTRE_3, PHARAOHS_SCEPTRE_3);
|
||||
put(PHARAOHS_SCEPTRE_4, PHARAOHS_SCEPTRE_3);
|
||||
put(PHARAOHS_SCEPTRE_5, PHARAOHS_SCEPTRE_3);
|
||||
put(PHARAOHS_SCEPTRE_6, PHARAOHS_SCEPTRE_3);
|
||||
put(PHARAOHS_SCEPTRE_7, PHARAOHS_SCEPTRE_3);
|
||||
put(PRAEL_BAT_1, PRAEL_BAT_1);
|
||||
put(PRAYER_CAPET, PRAYER_CAPE);
|
||||
put(PRAYER_ENHANCE_1_20965, PRAYER_ENHANCE_1);
|
||||
put(PRAYER_ENHANCE_2_20966, PRAYER_ENHANCE_1);
|
||||
put(PRAYER_ENHANCE_3_20967, PRAYER_ENHANCE_1);
|
||||
put(RANGING_MIX1, RANGING_MIX2);
|
||||
put(RANGING_MIX2, RANGING_MIX2);
|
||||
put(RANGING_POTION1, RANGING_POTION3);
|
||||
put(RANGING_POTION2, RANGING_POTION3);
|
||||
put(RANGING_POTION3, RANGING_POTION3);
|
||||
put(RED_DHIDE_BODY_T, RED_DHIDE_BODY);
|
||||
put(RED_DHIDE_CHAPS_T, RED_DHIDE_CHAPS);
|
||||
put(RED_SLAYER_HELMET_I, SLAYER_HELMET);
|
||||
put(RED_SPICE_1, RED_SPICE_4);
|
||||
put(RED_SPICE_2, RED_SPICE_4);
|
||||
put(RESTORE_MIX1, RESTORE_MIX2);
|
||||
put(RESTORE_MIX2, RESTORE_MIX2);
|
||||
put(RESTORE_POTION1, RESTORE_POTION3);
|
||||
put(RESTORE_POTION2, RESTORE_POTION3);
|
||||
put(RESTORE_POTION3, RESTORE_POTION3);
|
||||
put(RING_OF_DUELING5, RING_OF_DUELING8);
|
||||
put(RING_OF_DUELING6, RING_OF_DUELING8);
|
||||
put(RING_OF_DUELING7, RING_OF_DUELING8);
|
||||
put(RING_OF_DUELING8, RING_OF_DUELING8);
|
||||
put(RING_OF_RETURNING1, RING_OF_RETURNING5);
|
||||
put(ROD_OF_IVANDIS_4, ROD_OF_IVANDIS_10);
|
||||
put(ROD_OF_IVANDIS_5, ROD_OF_IVANDIS_10);
|
||||
put(ROD_OF_IVANDIS_6, ROD_OF_IVANDIS_10);
|
||||
put(ROD_OF_IVANDIS_7, ROD_OF_IVANDIS_10);
|
||||
put(ROD_OF_IVANDIS_8, ROD_OF_IVANDIS_10);
|
||||
put(SACRED_OIL3, SACRED_OIL4);
|
||||
put(SACRED_OIL4, SACRED_OIL4);
|
||||
put(SALVE_AMULET_E, SALVE_AMULET);
|
||||
put(SALVE_AMULETI, SALVE_AMULET);
|
||||
put(SANDSTONE_1KG, SANDSTONE_1KG);
|
||||
put(SARADOMIN_PAGE_4, SARADOMIN_PAGE_1);
|
||||
put(SEERS_RING_I, SEERS_RING);
|
||||
put(SHAYZIEN_BOOTS_1, SHAYZIEN_BOOTS_1);
|
||||
put(SHAYZIEN_BOOTS_2, SHAYZIEN_BOOTS_1);
|
||||
put(SHAYZIEN_BOOTS_3, SHAYZIEN_BOOTS_1);
|
||||
put(SHAYZIEN_HELM_4, SHAYZIEN_HELM_1);
|
||||
put(SHAYZIEN_HELM_5, SHAYZIEN_HELM_1);
|
||||
put(SHAYZIEN_PLATEBODY_1, SHAYZIEN_PLATEBODY_1);
|
||||
put(SHAYZIEN_PLATEBODY_2, SHAYZIEN_PLATEBODY_1);
|
||||
put(SHAYZIEN_PLATEBODY_3, SHAYZIEN_PLATEBODY_1);
|
||||
put(SHAYZIEN_SUPPLY_GREAVES_4, SHAYZIEN_SUPPLY_GREAVES_1);
|
||||
put(SHAYZIEN_SUPPLY_GREAVES_5, SHAYZIEN_SUPPLY_GREAVES_1);
|
||||
put(SHAYZIEN_SUPPLY_HELM_1, SHAYZIEN_SUPPLY_HELM_1);
|
||||
put(SHAYZIEN_SUPPLY_HELM_2, SHAYZIEN_SUPPLY_HELM_1);
|
||||
put(SHAYZIEN_SUPPLY_HELM_3, SHAYZIEN_SUPPLY_HELM_1);
|
||||
put(SHEEP_BONES_4, SHEEP_BONES_1);
|
||||
put(SINHAZA_SHROUD_TIER_1, SINHAZA_SHROUD_TIER_1);
|
||||
put(SINHAZA_SHROUD_TIER_2, SINHAZA_SHROUD_TIER_1);
|
||||
put(SINHAZA_SHROUD_TIER_3, SINHAZA_SHROUD_TIER_1);
|
||||
put(SINHAZA_SHROUD_TIER_4, SINHAZA_SHROUD_TIER_1);
|
||||
put(SLAYER_RING_6, SLAYER_RING_8);
|
||||
put(SLAYER_RING_7, SLAYER_RING_8);
|
||||
put(SLAYER_RING_8, SLAYER_RING_8);
|
||||
put(SLAYER_RING_ETERNAL, SLAYER_RING_8);
|
||||
put(SLAYERS_RESPITE1, SLAYERS_RESPITE);
|
||||
put(STAMINA_POTION4, STAMINA_POTION4);
|
||||
put(STASH_UNITS_EASY, STASH_UNITS_EASY);
|
||||
put(STASH_UNITS_ELITE, STASH_UNITS_EASY);
|
||||
put(STASH_UNITS_HARD, STASH_UNITS_EASY);
|
||||
put(STASH_UNITS_MASTER, STASH_UNITS_EASY);
|
||||
put(STRENGTH_POTION1, STRENGTH_POTION4);
|
||||
put(STRENGTH_POTION2, STRENGTH_POTION4);
|
||||
put(STRENGTH_POTION3, STRENGTH_POTION4);
|
||||
put(STRENGTH_POTION4, STRENGTH_POTION4);
|
||||
put(STUDDED_BODY_T, STUDDED_BODY);
|
||||
put(SUPER_DEF_MIX1, SUPER_DEF_MIX2);
|
||||
put(SUPER_DEF_MIX2, SUPER_DEF_MIX2);
|
||||
put(SUPER_DEFENCE1, SUPER_DEFENCE3);
|
||||
put(SUPER_DEFENCE2, SUPER_DEFENCE3);
|
||||
put(SUPER_DEFENCE3, SUPER_DEFENCE3);
|
||||
put(SUPER_RESTORE_MIX1, SUPER_RESTORE_MIX2);
|
||||
put(SUPER_RESTORE_MIX2, SUPER_RESTORE_MIX2);
|
||||
put(SUPER_RESTORE1, SUPER_RESTORE4);
|
||||
put(SUPER_RESTORE2, SUPER_RESTORE4);
|
||||
put(SUPER_RESTORE3, SUPER_RESTORE4);
|
||||
put(TEAK_SHELVES_2, TEAK_SHELVES_1);
|
||||
put(TELEPORT_CRYSTAL_1, TELEPORT_CRYSTAL_4);
|
||||
put(TELEPORT_CRYSTAL_2, TELEPORT_CRYSTAL_4);
|
||||
put(TELEPORT_CRYSTAL_3, TELEPORT_CRYSTAL_4);
|
||||
put(TELEPORT_CRYSTAL_4, TELEPORT_CRYSTAL_4);
|
||||
put(TOPAZ_BOLTS, TOPAZ_BOLTS_E);
|
||||
put(TOPAZ_DRAGON_BOLTS, TOPAZ_DRAGON_BOLTS_E);
|
||||
put(TORAGS_HAMMERS_0, TORAGS_HAMMERS);
|
||||
put(TORAGS_HAMMERS_100, TORAGS_HAMMERS);
|
||||
put(TORAGS_HAMMERS_25, TORAGS_HAMMERS);
|
||||
put(TORAGS_PLATELEGS_50, TORAGS_PLATELEGS);
|
||||
put(TORAGS_PLATELEGS_75, TORAGS_PLATELEGS);
|
||||
put(TREASONOUS_RING_I, TREASONOUS_RING);
|
||||
put(TRIDENT_OF_THE_SEAS_E, TRIDENT_OF_THE_SEAS_FULL);
|
||||
put(TRIDENT_OF_THE_SWAMP_E, TRIDENT_OF_THE_SWAMP);
|
||||
put(VERACS_BRASSARD_50, VERACS_BRASSARD);
|
||||
put(VERACS_BRASSARD_75, VERACS_BRASSARD);
|
||||
put(VERACS_FLAIL_0, VERACS_FLAIL);
|
||||
put(VERACS_FLAIL_100, VERACS_FLAIL);
|
||||
put(VERACS_FLAIL_25, VERACS_FLAIL);
|
||||
put(VOID_SEAL1, VOID_SEAL8);
|
||||
put(VOID_SEAL2, VOID_SEAL8);
|
||||
put(VOID_SEAL3, VOID_SEAL8);
|
||||
put(VOID_SEAL4, VOID_SEAL8);
|
||||
put(VOID_SEAL5, VOID_SEAL8);
|
||||
put(WATERSKIN3, WATERSKIN4);
|
||||
put(WATERSKIN4, WATERSKIN4);
|
||||
put(WESTERN_BANNER_1, WESTERN_BANNER);
|
||||
put(WESTERN_BANNER_2, WESTERN_BANNER);
|
||||
put(WESTERN_BANNER_3, WESTERN_BANNER);
|
||||
put(YELLOW_SPICE_2, YELLOW_SPICE_4);
|
||||
put(YELLOW_SPICE_3, YELLOW_SPICE_4);
|
||||
put(YELLOW_SPICE_4, YELLOW_SPICE_4);
|
||||
put(ZAMORAK_BREW1, ZAMORAK_BREW3);
|
||||
put(ZAMORAK_BREW2, ZAMORAK_BREW3);
|
||||
}};
|
||||
|
||||
@Test
|
||||
public void testMappedNames()
|
||||
{
|
||||
ITEMS_MAP.forEach((key, value) ->
|
||||
assertEquals(value, (Integer) ItemVariationMapping.map(key)));
|
||||
}
|
||||
}
|
||||
@@ -1,247 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, 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;
|
||||
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import com.google.common.reflect.ClassPath.ClassInfo;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.grapher.graphviz.GraphvizGrapher;
|
||||
import com.google.inject.grapher.graphviz.GraphvizModule;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import com.google.inject.util.Modules;
|
||||
import java.applet.Applet;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.events.Event;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.RuneLiteModule;
|
||||
import net.runelite.client.config.Config;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
import net.runelite.client.eventbus.AccessorGenerator;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.*;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PluginManagerTest
|
||||
{
|
||||
private static final String PLUGIN_PACKAGE = "net.runelite.client.plugins";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
public Applet applet;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
public Client client;
|
||||
|
||||
private ExecutorService executorService;
|
||||
|
||||
private Set<Class> pluginClasses;
|
||||
private Set<Class> configClasses;
|
||||
|
||||
@Before
|
||||
public void before() throws IOException
|
||||
{
|
||||
OkHttpClient okHttpClient = mock(OkHttpClient.class);
|
||||
|
||||
executorService = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
Injector injector = Guice.createInjector(Modules
|
||||
.override(new RuneLiteModule(okHttpClient, () -> null, false, RuneLite.DEFAULT_CONFIG_FILE))
|
||||
.with(BoundFieldModule.of(this)));
|
||||
|
||||
RuneLite.setInjector(injector);
|
||||
|
||||
// Find plugins and configs we expect to have
|
||||
pluginClasses = new HashSet<>();
|
||||
configClasses = new HashSet<>();
|
||||
Set<ClassInfo> classes = ClassPath.from(getClass().getClassLoader()).getTopLevelClassesRecursive(PLUGIN_PACKAGE);
|
||||
for (ClassInfo classInfo : classes)
|
||||
{
|
||||
Class<?> clazz = classInfo.load();
|
||||
PluginDescriptor pluginDescriptor = clazz.getAnnotation(PluginDescriptor.class);
|
||||
if (pluginDescriptor != null)
|
||||
{
|
||||
pluginClasses.add(clazz);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Config.class.isAssignableFrom(clazz))
|
||||
{
|
||||
configClasses.add(clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
executorService.shutdownNow();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadPlugins() throws Exception
|
||||
{
|
||||
PluginManager pluginManager = new PluginManager(false, null, null, executorService, null, null, null, null);
|
||||
pluginManager.setOutdated(true);
|
||||
pluginManager.loadCorePlugins();
|
||||
Collection<Plugin> plugins = pluginManager.getPlugins();
|
||||
long expected = pluginClasses.stream()
|
||||
.map(cl -> (PluginDescriptor) cl.getAnnotation(PluginDescriptor.class))
|
||||
.filter(Objects::nonNull)
|
||||
.filter(PluginDescriptor::loadWhenOutdated)
|
||||
.count();
|
||||
assertEquals(expected, plugins.size());
|
||||
|
||||
pluginManager = new PluginManager(false, null, null, executorService, null, null, null, null);
|
||||
pluginManager.loadCorePlugins();
|
||||
plugins = pluginManager.getPlugins();
|
||||
|
||||
expected = pluginClasses.stream()
|
||||
.map(cl -> (PluginDescriptor) cl.getAnnotation(PluginDescriptor.class))
|
||||
.filter(Objects::nonNull)
|
||||
.count();
|
||||
assertEquals(expected, plugins.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dumpGraph() throws Exception
|
||||
{
|
||||
List<Module> modules = new ArrayList<>();
|
||||
modules.add(new GraphvizModule());
|
||||
modules.add(new RuneLiteModule(mock(OkHttpClient.class), () -> null, false, RuneLite.DEFAULT_CONFIG_FILE));
|
||||
|
||||
PluginManager pluginManager = new PluginManager(false, null, null, executorService, null, null, null, null);
|
||||
pluginManager.loadCorePlugins();
|
||||
modules.addAll(pluginManager.getPlugins());
|
||||
|
||||
File file = folder.newFile();
|
||||
try (PrintWriter out = new PrintWriter(file, StandardCharsets.UTF_8))
|
||||
{
|
||||
Injector injector = Guice.createInjector(modules);
|
||||
GraphvizGrapher grapher = injector.getInstance(GraphvizGrapher.class);
|
||||
grapher.setOut(out);
|
||||
grapher.setRankdir("TB");
|
||||
grapher.graph(injector);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ensureNoDuplicateConfigKeyNames()
|
||||
{
|
||||
for (final Class clazz : configClasses)
|
||||
{
|
||||
final Set<String> configKeyNames = new HashSet<>();
|
||||
|
||||
for (final Method method : clazz.getMethods())
|
||||
{
|
||||
if (!method.isDefault())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final ConfigItem annotation = method.getAnnotation(ConfigItem.class);
|
||||
|
||||
if (annotation == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final String configKeyName = annotation.keyName();
|
||||
|
||||
if (configKeyNames.contains(configKeyName))
|
||||
{
|
||||
throw new IllegalArgumentException("keyName " + configKeyName + " is duplicated in " + clazz);
|
||||
}
|
||||
|
||||
configKeyNames.add(configKeyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEventbusAnnotations() throws Exception
|
||||
{
|
||||
EventBus eventbus = new EventBus();
|
||||
PluginManager pluginManager = new PluginManager(false, eventbus, null, executorService, null, null, null, null)
|
||||
{
|
||||
@Override
|
||||
public boolean isPluginEnabled(Plugin plugin)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class TestEvent implements Event
|
||||
{
|
||||
}
|
||||
class TestPlugin extends Plugin
|
||||
{
|
||||
private boolean thisShouldBeTrue = false;
|
||||
|
||||
@Subscribe
|
||||
private void doSomething(TestEvent event)
|
||||
{
|
||||
thisShouldBeTrue = true;
|
||||
}
|
||||
}
|
||||
|
||||
TestPlugin plugin = new TestPlugin();
|
||||
AccessorGenerator.scanSubscribes(MethodHandles.lookup(), plugin)
|
||||
.forEach(s -> s.subscribe(eventbus, plugin));
|
||||
eventbus.post(TestEvent.class, new TestEvent());
|
||||
assert plugin.thisShouldBeTrue;
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-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.rs;
|
||||
|
||||
import com.google.common.io.CharStreams;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ClientConfigLoaderTest
|
||||
{
|
||||
private final MockWebServer server = new MockWebServer();
|
||||
|
||||
@Before
|
||||
public void before() throws IOException
|
||||
{
|
||||
String response;
|
||||
try (InputStream in = getClass().getResourceAsStream("jav_config.ws"))
|
||||
{
|
||||
response = CharStreams.toString(new InputStreamReader(
|
||||
in, StandardCharsets.UTF_8));
|
||||
}
|
||||
server.enqueue(new MockResponse().setBody(response));
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws IOException
|
||||
{
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetch() throws IOException
|
||||
{
|
||||
final RSConfig config = new ClientConfigLoader(new OkHttpClient()).fetch(server.url("/"));
|
||||
assertEquals("http://oldschool1.runescape.com/", config.getCodeBase());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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.ui;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ContainableFrameTest
|
||||
{
|
||||
@Test
|
||||
public void testJdk8231564()
|
||||
{
|
||||
assertTrue(ContainableFrame.jdk8231564("11.0.8"));
|
||||
assertFalse(ContainableFrame.jdk8231564("11.0.7"));
|
||||
assertFalse(ContainableFrame.jdk8231564("1.8.0_261"));
|
||||
assertFalse(ContainableFrame.jdk8231564("12.0.0"));
|
||||
assertFalse(ContainableFrame.jdk8231564("13.0.0"));
|
||||
assertFalse(ContainableFrame.jdk8231564("14.0.0"));
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Tyler <https://github.com/tylerthardy>
|
||||
* 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.ui;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FontManagerTest
|
||||
{
|
||||
@Test
|
||||
public void getRunescapeFont()
|
||||
{
|
||||
assertNotNull(FontManager.getRunescapeFont());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRunescapeSmallFont()
|
||||
{
|
||||
assertNotNull(FontManager.getRunescapeSmallFont());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, 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.ui.overlay;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OverlayManagerTest
|
||||
{
|
||||
static class TestOverlay extends Overlay
|
||||
{
|
||||
TestOverlay(OverlayPosition position, OverlayPriority priority)
|
||||
{
|
||||
setPosition(position);
|
||||
setPriority(priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
}
|
||||
|
||||
private static class OverlayA extends Overlay
|
||||
{
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class OverlayB extends Overlay
|
||||
{
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality()
|
||||
{
|
||||
Overlay a1 = new OverlayA();
|
||||
Overlay a2 = new OverlayA();
|
||||
Overlay b = new OverlayB();
|
||||
// The same instance of the same overlay should be equal
|
||||
assertEquals(a1, a1);
|
||||
// A different instance of the same overlay should not be equal by default
|
||||
assertNotEquals(a1, a2);
|
||||
// A different instance of a different overlay should not be equal
|
||||
assertNotEquals(a1, b);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSort()
|
||||
{
|
||||
// High priorities overlays render first
|
||||
Overlay tlh = new TestOverlay(OverlayPosition.TOP_LEFT, OverlayPriority.HIGH);
|
||||
Overlay tll = new TestOverlay(OverlayPosition.TOP_LEFT, OverlayPriority.LOW);
|
||||
List<Overlay> overlays = Arrays.asList(tlh, tll);
|
||||
overlays.sort(OverlayManager.OVERLAY_COMPARATOR);
|
||||
assertEquals(tlh, overlays.get(0));
|
||||
assertEquals(tll, overlays.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortDynamic()
|
||||
{
|
||||
// Dynamic overlays render before static overlays
|
||||
Overlay tlh = new TestOverlay(OverlayPosition.TOP_LEFT, OverlayPriority.HIGH);
|
||||
Overlay dyn = new TestOverlay(OverlayPosition.DYNAMIC, OverlayPriority.HIGH);
|
||||
List<Overlay> overlays = Arrays.asList(tlh, dyn);
|
||||
overlays.sort(OverlayManager.OVERLAY_COMPARATOR);
|
||||
assertEquals(dyn, overlays.get(0));
|
||||
assertEquals(tlh, overlays.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTooltips()
|
||||
{
|
||||
// Tooltip overlay renders after everything
|
||||
Overlay t = new TestOverlay(OverlayPosition.TOOLTIP, OverlayPriority.HIGH);
|
||||
Overlay dyn = new TestOverlay(OverlayPosition.DYNAMIC, OverlayPriority.HIGH);
|
||||
Overlay tlh = new TestOverlay(OverlayPosition.TOP_LEFT, OverlayPriority.HIGH);
|
||||
List<Overlay> overlays = Arrays.asList(t, dyn, tlh);
|
||||
overlays.sort(OverlayManager.OVERLAY_COMPARATOR);
|
||||
assertEquals(dyn, overlays.get(0));
|
||||
assertEquals(tlh, overlays.get(1));
|
||||
assertEquals(t, overlays.get(2));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.ui.overlay.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TextComponentTest
|
||||
{
|
||||
private Graphics2D graphics;
|
||||
private BufferedImage dest;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
dest = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
|
||||
graphics = (Graphics2D) dest.getGraphics();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRender()
|
||||
{
|
||||
TextComponent textComponent = new TextComponent();
|
||||
textComponent.setText("test");
|
||||
textComponent.setColor(Color.RED);
|
||||
textComponent.render(graphics);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRender2()
|
||||
{
|
||||
TextComponent textComponent = new TextComponent();
|
||||
textComponent.setText("<col=0000ff>test");
|
||||
textComponent.render(graphics);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRender3()
|
||||
{
|
||||
TextComponent textComponent = new TextComponent();
|
||||
textComponent.setText("<col=0000ff>test<col=00ff00> test");
|
||||
textComponent.render(graphics);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
graphics.dispose();
|
||||
dest.flush();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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.ui.overlay.components;
|
||||
|
||||
import java.awt.FontMetrics;
|
||||
import static net.runelite.client.ui.overlay.components.TooltipComponent.calculateTextWidth;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class TooltipComponentTest
|
||||
{
|
||||
@Test
|
||||
public void testCalculateTextWidth()
|
||||
{
|
||||
FontMetrics fontMetics = mock(FontMetrics.class);
|
||||
when(fontMetics.stringWidth(anyString())).thenAnswer((invocation) -> ((String) invocation.getArguments()[0]).length());
|
||||
|
||||
assertEquals(11, calculateTextWidth(fontMetics, "line1<col=ff0000>>line2"));
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Jordan Atwood <jordan.atwood423@gmail.com>
|
||||
* 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.ui.overlay.components.table;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.List;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
|
||||
|
||||
public class TableComponentTest
|
||||
{
|
||||
@Mock
|
||||
private Graphics2D graphics;
|
||||
|
||||
private BufferedImage dest;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
dest = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
|
||||
graphics = (Graphics2D) dest.getGraphics();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRender()
|
||||
{
|
||||
TableComponent tableComponent = new TableComponent();
|
||||
tableComponent.addRow("test");
|
||||
tableComponent.setDefaultAlignment(TableAlignment.CENTER);
|
||||
tableComponent.setDefaultColor(Color.RED);
|
||||
tableComponent.render(graphics);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColors()
|
||||
{
|
||||
TableComponent tableComponent = new TableComponent();
|
||||
tableComponent.addRow("test", "test", "test", "<col=ffff00>test", "test");
|
||||
tableComponent.setColumns("", "", "");
|
||||
List<TableElement> elements = tableComponent.getColumns();
|
||||
elements.get(0).setColor(Color.RED);
|
||||
elements.get(1).setColor(Color.GREEN);
|
||||
elements.get(2).setColor(Color.BLUE);
|
||||
tableComponent.render(graphics);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
graphics.dispose();
|
||||
dest.flush();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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.ui.overlay.infobox;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.awt.Color;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.config.OpenOSRSConfig;
|
||||
import net.runelite.client.config.RuneLiteConfig;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class InfoBoxManagerTest
|
||||
{
|
||||
@Inject
|
||||
private InfoBoxManager infoBoxManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private RuneLiteConfig runeLiteConfig;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private OpenOSRSConfig openOSRSConfig;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private ConfigManager configManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private Client client;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
|
||||
}
|
||||
|
||||
private static class TestInfobox extends InfoBox
|
||||
{
|
||||
private static final Plugin PLUGIN = mock(Plugin.class);
|
||||
|
||||
static
|
||||
{
|
||||
when(PLUGIN.getName()).thenReturn("");
|
||||
}
|
||||
|
||||
private final String text;
|
||||
|
||||
private TestInfobox(InfoBoxPriority infoBoxPriority)
|
||||
{
|
||||
this(infoBoxPriority, null);
|
||||
}
|
||||
|
||||
private TestInfobox(InfoBoxPriority infoBoxPriority, String text)
|
||||
{
|
||||
super(null, PLUGIN);
|
||||
setPriority(infoBoxPriority);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText()
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getTextColor()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSorting()
|
||||
{
|
||||
infoBoxManager.addInfoBox(new TestInfobox(InfoBoxPriority.LOW));
|
||||
infoBoxManager.addInfoBox(new TestInfobox(InfoBoxPriority.HIGH));
|
||||
infoBoxManager.addInfoBox(new TestInfobox(InfoBoxPriority.MED));
|
||||
|
||||
List<InfoBoxPriority> order = infoBoxManager.getInfoBoxes().stream().map(InfoBox::getPriority).collect(Collectors.toList());
|
||||
assertEquals(Arrays.asList(InfoBoxPriority.HIGH, InfoBoxPriority.MED, InfoBoxPriority.LOW), order);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSamePluginAndPriority()
|
||||
{
|
||||
infoBoxManager.addInfoBox(new TestInfobox(InfoBoxPriority.MED, "one"));
|
||||
infoBoxManager.addInfoBox(new TestInfobox(InfoBoxPriority.MED, "two"));
|
||||
infoBoxManager.addInfoBox(new TestInfobox(InfoBoxPriority.MED, "three"));
|
||||
|
||||
assertEquals(3, infoBoxManager.getInfoBoxes().size());
|
||||
assertEquals("one", infoBoxManager.getInfoBoxes().get(0).getText());
|
||||
assertEquals("two", infoBoxManager.getInfoBoxes().get(1).getText());
|
||||
assertEquals("three", infoBoxManager.getInfoBoxes().get(2).getText());
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Jordan Atwood <jordan.atwood423@gmail.com>
|
||||
* 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.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ColorUtilTest
|
||||
{
|
||||
private static final Map<Color, String> COLOR_HEXSTRING_MAP = new HashMap<Color, String>()
|
||||
{{
|
||||
put(Color.BLACK, "000000");
|
||||
put(new Color(0x1), "000001");
|
||||
put(new Color(0x100000), "100000");
|
||||
put(Color.RED, "ff0000");
|
||||
put(Color.GREEN, "00ff00");
|
||||
put(Color.BLUE, "0000ff");
|
||||
put(new Color(0xA1B2C3), "a1b2c3");
|
||||
put(Color.WHITE, "ffffff");
|
||||
}};
|
||||
|
||||
@Test
|
||||
public void colorTag()
|
||||
{
|
||||
COLOR_HEXSTRING_MAP.forEach((color, hex) ->
|
||||
assertEquals("<col=" + hex + ">", ColorUtil.colorTag(color)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prependColorTag()
|
||||
{
|
||||
COLOR_HEXSTRING_MAP.forEach((color, hex) ->
|
||||
{
|
||||
assertEquals("<col=" + hex + ">test", ColorUtil.prependColorTag("test", color));
|
||||
assertEquals("<col=" + hex + ">", ColorUtil.prependColorTag("", color));
|
||||
});
|
||||
|
||||
assertEquals("<col=ff0000>94<col=ffffff>/99", ColorUtil.prependColorTag("94" + ColorUtil.prependColorTag("/99", Color.WHITE), Color.RED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrapWithColorTag()
|
||||
{
|
||||
COLOR_HEXSTRING_MAP.forEach((color, hex) ->
|
||||
{
|
||||
assertEquals("<col=" + hex + ">test</col>", ColorUtil.wrapWithColorTag("test", color));
|
||||
assertEquals("<col=" + hex + "></col>", ColorUtil.wrapWithColorTag("", color));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toHexColor()
|
||||
{
|
||||
COLOR_HEXSTRING_MAP.forEach((color, hex) ->
|
||||
assertEquals("#" + hex, ColorUtil.toHexColor(color)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void colorLerp()
|
||||
{
|
||||
assertEquals(Color.WHITE, ColorUtil.colorLerp(Color.WHITE, Color.WHITE, 0.9));
|
||||
assertEquals(new Color(128, 128, 128), ColorUtil.colorLerp(Color.BLACK, Color.WHITE, 0.5));
|
||||
assertEquals(Color.BLACK, ColorUtil.colorLerp(Color.BLACK, Color.CYAN, 0));
|
||||
assertEquals(Color.CYAN, ColorUtil.colorLerp(Color.BLACK, Color.CYAN, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void colorToHexCode()
|
||||
{
|
||||
COLOR_HEXSTRING_MAP.forEach((color, hex) ->
|
||||
assertEquals(hex, ColorUtil.colorToHexCode(color)));
|
||||
}
|
||||
}
|
||||
@@ -1,405 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Jordan Atwood <jordan.atwood423@gmail.com>
|
||||
* 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.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import static java.awt.Color.BLACK;
|
||||
import static java.awt.Color.BLUE;
|
||||
import static java.awt.Color.GRAY;
|
||||
import static java.awt.Color.GREEN;
|
||||
import static java.awt.Color.RED;
|
||||
import static java.awt.Color.WHITE;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ImageUtilTest
|
||||
{
|
||||
private static final Color BLACK_HALF_TRANSPARENT = new Color(0, 0, 0, 128);
|
||||
private static final Color BLACK_TRANSPARENT = new Color(0, true);
|
||||
private static final int CORNER_SIZE = 2;
|
||||
private static final int CENTERED_SIZE = 3;
|
||||
|
||||
private static final BufferedImage BLACK_PIXEL_TOP_LEFT;
|
||||
private static final BufferedImage BLACK_PIXEL_TOP_RIGHT;
|
||||
private static final BufferedImage BLACK_PIXEL_BOTTOM_LEFT;
|
||||
private static final BufferedImage BLACK_PIXEL_BOTTOM_RIGHT;
|
||||
|
||||
static
|
||||
{
|
||||
BLACK_PIXEL_TOP_LEFT = new BufferedImage(CORNER_SIZE, CORNER_SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||
BLACK_PIXEL_TOP_LEFT.setRGB(0, 0, BLACK.getRGB());
|
||||
|
||||
BLACK_PIXEL_TOP_RIGHT = new BufferedImage(CORNER_SIZE, CORNER_SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||
BLACK_PIXEL_TOP_RIGHT.setRGB(1, 0, BLACK.getRGB());
|
||||
|
||||
BLACK_PIXEL_BOTTOM_LEFT = new BufferedImage(CORNER_SIZE, CORNER_SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||
BLACK_PIXEL_BOTTOM_LEFT.setRGB(0, 1, BLACK.getRGB());
|
||||
|
||||
BLACK_PIXEL_BOTTOM_RIGHT = new BufferedImage(CORNER_SIZE, CORNER_SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||
BLACK_PIXEL_BOTTOM_RIGHT.setRGB(1, 1, BLACK.getRGB());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bufferedImageFromImage()
|
||||
{
|
||||
final BufferedImage buffered = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
assertEquals(buffered, ImageUtil.bufferedImageFromImage(buffered));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void grayscaleOffset()
|
||||
{
|
||||
// grayscaleOffset(BufferedImage image, int offset)
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.luminanceOffset(oneByOne(BLACK), -255)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(new Color(50, 50, 50)), ImageUtil.luminanceOffset(oneByOne(BLACK), 50)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(GRAY), ImageUtil.luminanceOffset(oneByOne(BLACK), 128)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.luminanceOffset(oneByOne(GRAY), -255)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(WHITE), ImageUtil.luminanceOffset(oneByOne(BLACK), 255)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(new Color(200, 200, 200)), ImageUtil.luminanceOffset(oneByOne(WHITE), -55)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(WHITE), ImageUtil.luminanceOffset(oneByOne(WHITE), 55)));
|
||||
|
||||
// grayscaleOffset(BufferedImage image, float percentage)
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.luminanceScale(oneByOne(BLACK), 0f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.luminanceScale(oneByOne(BLACK), 1f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.luminanceScale(oneByOne(BLACK), 2f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.luminanceScale(oneByOne(GRAY), 0f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(GRAY), ImageUtil.luminanceScale(oneByOne(GRAY), 1f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(WHITE), ImageUtil.luminanceScale(oneByOne(GRAY), 2f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.luminanceScale(oneByOne(WHITE), 0f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(GRAY), ImageUtil.luminanceScale(oneByOne(WHITE), 0.503f))); // grayscaleOffset does Math.floor
|
||||
assertTrue(bufferedImagesEqual(oneByOne(WHITE), ImageUtil.luminanceScale(oneByOne(WHITE), 1f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(WHITE), ImageUtil.luminanceScale(oneByOne(WHITE), 2f)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alphaOffset()
|
||||
{
|
||||
// alphaOffset(BufferedImage image, int offset)
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK_TRANSPARENT), ImageUtil.alphaOffset(oneByOne(BLACK_TRANSPARENT), -255)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(new Color(0, 0, 0, 50)), ImageUtil.alphaOffset(oneByOne(BLACK_TRANSPARENT), 50)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK_HALF_TRANSPARENT), ImageUtil.alphaOffset(oneByOne(BLACK_TRANSPARENT), 128)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK_TRANSPARENT), ImageUtil.alphaOffset(oneByOne(BLACK_HALF_TRANSPARENT), -255)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.alphaOffset(oneByOne(BLACK_TRANSPARENT), 255)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(new Color(0, 0, 0, 200)), ImageUtil.alphaOffset(oneByOne(BLACK), -55)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.alphaOffset(oneByOne(BLACK), 255)));
|
||||
|
||||
// alphaOffset(BufferedImage image, float offset)
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK_TRANSPARENT), ImageUtil.alphaOffset(oneByOne(BLACK_TRANSPARENT), 0f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK_TRANSPARENT), ImageUtil.alphaOffset(oneByOne(BLACK_TRANSPARENT), 1f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK_TRANSPARENT), ImageUtil.alphaOffset(oneByOne(BLACK_TRANSPARENT), 2f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK_TRANSPARENT), ImageUtil.alphaOffset(oneByOne(BLACK_HALF_TRANSPARENT), 0f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK_HALF_TRANSPARENT), ImageUtil.alphaOffset(oneByOne(BLACK_HALF_TRANSPARENT), 1f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.alphaOffset(oneByOne(BLACK_HALF_TRANSPARENT), 2f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK_TRANSPARENT), ImageUtil.alphaOffset(oneByOne(BLACK), 0f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK_HALF_TRANSPARENT), ImageUtil.alphaOffset(oneByOne(BLACK), 0.503f))); // opacityOffset does Math.floor
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.alphaOffset(oneByOne(BLACK), 1f)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.alphaOffset(oneByOne(BLACK), 2f)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void grayscaleImage()
|
||||
{
|
||||
final BufferedImage[] grayscaleColors = new BufferedImage[]{
|
||||
oneByOne(WHITE),
|
||||
oneByOne(GRAY),
|
||||
oneByOne(BLACK),
|
||||
oneByOne(BLACK_HALF_TRANSPARENT),
|
||||
oneByOne(BLACK_TRANSPARENT),
|
||||
};
|
||||
final BufferedImage[] nonGrayscaleColors = new BufferedImage[]{
|
||||
oneByOne(RED),
|
||||
oneByOne(GREEN),
|
||||
oneByOne(BLUE),
|
||||
};
|
||||
|
||||
for (BufferedImage image : grayscaleColors)
|
||||
{
|
||||
assertTrue(isGrayscale(image));
|
||||
}
|
||||
for (BufferedImage image : nonGrayscaleColors)
|
||||
{
|
||||
assertFalse(isGrayscale(image));
|
||||
}
|
||||
for (BufferedImage image : ArrayUtils.addAll(grayscaleColors, nonGrayscaleColors))
|
||||
{
|
||||
assertTrue(isGrayscale(ImageUtil.grayscaleImage(image)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resizeImage()
|
||||
{
|
||||
// TODO: test image contents after changing size
|
||||
|
||||
final BufferedImage larger = ImageUtil.resizeImage(oneByOne(BLACK), 46, 46);
|
||||
final BufferedImage smaller = ImageUtil.resizeImage(centeredPixel(WHITE), 1, 1);
|
||||
final BufferedImage stretched = ImageUtil.resizeImage(solidColor(30, 30, RED), 12, 34);
|
||||
|
||||
assertEquals(46, larger.getWidth());
|
||||
assertEquals(46, larger.getHeight());
|
||||
assertEquals(1, smaller.getWidth());
|
||||
assertEquals(1, smaller.getHeight());
|
||||
assertEquals(12, stretched.getWidth());
|
||||
assertEquals(34, stretched.getHeight());
|
||||
|
||||
final BufferedImage[] assertSameAfterResize = new BufferedImage[]{
|
||||
oneByOne(WHITE),
|
||||
oneByOne(GRAY),
|
||||
oneByOne(BLACK),
|
||||
oneByOne(RED),
|
||||
oneByOne(GREEN),
|
||||
oneByOne(BLUE),
|
||||
oneByOne(BLACK_HALF_TRANSPARENT),
|
||||
oneByOne(BLACK_TRANSPARENT),
|
||||
centeredPixel(WHITE),
|
||||
centeredPixel(GRAY),
|
||||
centeredPixel(BLACK),
|
||||
BLACK_PIXEL_TOP_LEFT,
|
||||
BLACK_PIXEL_TOP_RIGHT,
|
||||
BLACK_PIXEL_BOTTOM_LEFT,
|
||||
BLACK_PIXEL_BOTTOM_RIGHT,
|
||||
};
|
||||
for (BufferedImage image : assertSameAfterResize)
|
||||
{
|
||||
assertTrue(bufferedImagesEqual(image, ImageUtil.resizeImage(image, image.getWidth(), image.getHeight())));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resizeCanvas()
|
||||
{
|
||||
assertTrue(bufferedImagesEqual(centeredPixel(BLACK), ImageUtil.resizeCanvas(oneByOne(BLACK), 3, 3)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.resizeCanvas(oneByOne(BLACK), 1, 1)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK), ImageUtil.resizeCanvas(centeredPixel(BLACK), 1, 1)));
|
||||
|
||||
BufferedImage expected = new BufferedImage(2, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
expected.setRGB(1, 0, BLACK.getRGB());
|
||||
assertTrue(bufferedImagesEqual(expected, ImageUtil.resizeCanvas(oneByOne(BLACK), 2, 1)));
|
||||
|
||||
expected = new BufferedImage(1, 2, BufferedImage.TYPE_INT_ARGB);
|
||||
expected.setRGB(0, 1, BLACK.getRGB());
|
||||
assertTrue(bufferedImagesEqual(expected, ImageUtil.resizeCanvas(oneByOne(BLACK), 1, 2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rotateImage()
|
||||
{
|
||||
// TODO: Test more than 90° rotations
|
||||
|
||||
// Evenly-sized images (2x2)
|
||||
assertTrue(bufferedImagesEqual(BLACK_PIXEL_TOP_RIGHT, ImageUtil.rotateImage(BLACK_PIXEL_TOP_LEFT, Math.PI / 2)));
|
||||
assertTrue(bufferedImagesEqual(BLACK_PIXEL_BOTTOM_RIGHT, ImageUtil.rotateImage(BLACK_PIXEL_TOP_LEFT, Math.PI)));
|
||||
assertTrue(bufferedImagesEqual(BLACK_PIXEL_BOTTOM_LEFT, ImageUtil.rotateImage(BLACK_PIXEL_TOP_LEFT, Math.PI * 3 / 2)));
|
||||
assertTrue(bufferedImagesEqual(BLACK_PIXEL_TOP_LEFT, ImageUtil.rotateImage(BLACK_PIXEL_TOP_LEFT, Math.PI * 2)));
|
||||
|
||||
// Unevenly-sized images (2x1); when rotated 90° become (2x2) images
|
||||
final BufferedImage twoByOneLeft = new BufferedImage(2, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
twoByOneLeft.setRGB(0, 0, BLACK.getRGB());
|
||||
final BufferedImage twoByTwoRight = new BufferedImage(2, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
twoByTwoRight.setRGB(1, 0, BLACK.getRGB());
|
||||
final BufferedImage oneByTwoTop = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB);
|
||||
oneByTwoTop.setRGB(1, 0, new Color(0, 0, 0, 127).getRGB());
|
||||
final BufferedImage oneByTwoBottom = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB);
|
||||
oneByTwoBottom.setRGB(0, 0, new Color(0, 0, 0, 127).getRGB());
|
||||
oneByTwoBottom.setRGB(0, 1, BLACK.getRGB());
|
||||
|
||||
assertTrue(bufferedImagesEqual(oneByTwoTop, ImageUtil.rotateImage(twoByOneLeft, Math.PI / 2)));
|
||||
assertTrue(bufferedImagesEqual(twoByTwoRight, ImageUtil.rotateImage(twoByOneLeft, Math.PI)));
|
||||
assertTrue(bufferedImagesEqual(oneByTwoBottom, ImageUtil.rotateImage(twoByOneLeft, Math.PI * 3 / 2)));
|
||||
assertTrue(bufferedImagesEqual(twoByOneLeft, ImageUtil.rotateImage(twoByOneLeft, Math.PI * 2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flipImage()
|
||||
{
|
||||
assertTrue(bufferedImagesEqual(BLACK_PIXEL_TOP_LEFT, ImageUtil.flipImage(BLACK_PIXEL_TOP_LEFT, false, false)));
|
||||
assertTrue(bufferedImagesEqual(BLACK_PIXEL_TOP_RIGHT, ImageUtil.flipImage(BLACK_PIXEL_TOP_LEFT, true, false)));
|
||||
assertTrue(bufferedImagesEqual(BLACK_PIXEL_BOTTOM_LEFT, ImageUtil.flipImage(BLACK_PIXEL_TOP_LEFT, false, true)));
|
||||
assertTrue(bufferedImagesEqual(BLACK_PIXEL_BOTTOM_RIGHT, ImageUtil.flipImage(BLACK_PIXEL_TOP_LEFT, true, true)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fillImage()
|
||||
{
|
||||
// fillImage(BufferedImage image, Color color)
|
||||
assertTrue(bufferedImagesEqual(centeredPixel(GRAY), ImageUtil.fillImage(centeredPixel(BLACK), GRAY)));
|
||||
assertTrue(bufferedImagesEqual(solidColor(3, 3, GREEN), ImageUtil.fillImage(solidColor(3, 3, BLACK), GREEN)));
|
||||
assertTrue(bufferedImagesEqual(oneByOne(BLACK_TRANSPARENT), ImageUtil.fillImage(oneByOne(BLACK_TRANSPARENT), WHITE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outlineImage()
|
||||
{
|
||||
// outlineImage(BufferedImage image, Color color)
|
||||
BufferedImage expected = new BufferedImage(CENTERED_SIZE, CENTERED_SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||
for (int x = 0; x < expected.getWidth(); x++)
|
||||
{
|
||||
for (int y = 0; y < expected.getHeight(); y++)
|
||||
{
|
||||
if (x != 1 && y != 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
expected.setRGB(x, y, BLACK.getRGB());
|
||||
}
|
||||
}
|
||||
assertTrue(bufferedImagesEqual(expected, ImageUtil.outlineImage(centeredPixel(BLACK), BLACK)));
|
||||
expected.setRGB(1, 1, WHITE.getRGB());
|
||||
assertTrue(bufferedImagesEqual(expected, ImageUtil.outlineImage(centeredPixel(WHITE), BLACK)));
|
||||
expected = solidColor(CORNER_SIZE, CORNER_SIZE, WHITE);
|
||||
expected.setRGB(0, 0, BLACK.getRGB());
|
||||
expected.setRGB(1, 1, new Color(0, true).getRGB());
|
||||
assertTrue(bufferedImagesEqual(expected, ImageUtil.outlineImage(BLACK_PIXEL_TOP_LEFT, WHITE)));
|
||||
|
||||
// outlineImage(BufferedImage image, Color color, Boolean outlineCorners)
|
||||
expected = solidColor(CORNER_SIZE, CORNER_SIZE, WHITE);
|
||||
expected.setRGB(0, 0, BLACK.getRGB());
|
||||
assertTrue(bufferedImagesEqual(expected, ImageUtil.outlineImage(BLACK_PIXEL_TOP_LEFT, WHITE, true)));
|
||||
assertTrue(bufferedImagesEqual(solidColor(3, 3, BLACK), ImageUtil.outlineImage(centeredPixel(BLACK), BLACK, true)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares whether two {@link BufferedImage}s are equal in data.
|
||||
*
|
||||
* @param expected The first {@link BufferedImage} to be compared.
|
||||
* @param actual The second {@link BufferedImage} to be compared.
|
||||
* @return A boolean indicating whether the given {@link BufferedImage}s are of the same image data.
|
||||
*/
|
||||
private boolean bufferedImagesEqual(final @Nonnull BufferedImage expected, final @Nonnull BufferedImage actual)
|
||||
{
|
||||
if (expected.getWidth() != actual.getWidth())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!expected.getColorModel().equals(actual.getColorModel()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final DataBuffer aBuffer = expected.getRaster().getDataBuffer();
|
||||
final DataBuffer bBuffer = actual.getRaster().getDataBuffer();
|
||||
final DataBufferInt aBufferInt = (DataBufferInt) aBuffer;
|
||||
final DataBufferInt bBufferInt = (DataBufferInt) bBuffer;
|
||||
|
||||
if (aBufferInt.getNumBanks() != bBufferInt.getNumBanks())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < aBufferInt.getNumBanks(); i++)
|
||||
{
|
||||
final int[] aDataBank = aBufferInt.getData(i);
|
||||
final int[] bDataBank = bBufferInt.getData(i);
|
||||
if (!Arrays.equals(aDataBank, bDataBank))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a {@link BufferedImage} contains only grayscale pixel data.
|
||||
*
|
||||
* @param image The image to be checked.
|
||||
* @return A boolean indicating whether all of the given image's pixels are grayscale.
|
||||
*/
|
||||
private boolean isGrayscale(final @Nonnull BufferedImage image)
|
||||
{
|
||||
for (int x = 0; x < image.getWidth(); x++)
|
||||
{
|
||||
for (int y = 0; y < image.getHeight(); y++)
|
||||
{
|
||||
final int color = image.getRGB(x, y);
|
||||
final int red = (color & 0xff0000) >> 16;
|
||||
final int green = (color & 0xff00) >> 8;
|
||||
final int blue = color & 0xff;
|
||||
if (red != green
|
||||
|| green != blue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link BufferedImage} of a 1-by-1px image of the given color.
|
||||
*
|
||||
* @param color The color to use for the image's single pixel.
|
||||
* @return A {@link BufferedImage} containing a single pixel of the given color.
|
||||
*/
|
||||
private BufferedImage oneByOne(final @Nonnull Color color)
|
||||
{
|
||||
return solidColor(1, 1, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link BufferedImage} of a single pixel of the given color centered in a 3-by-3px
|
||||
* image.
|
||||
*
|
||||
* @param color The color to use for the centered pixel.
|
||||
* @return A {@link BufferedImage} with completely transparent pixels and one pixel of the
|
||||
* given color in the center.
|
||||
*/
|
||||
private BufferedImage centeredPixel(final @Nonnull Color color)
|
||||
{
|
||||
final BufferedImage out = new BufferedImage(CENTERED_SIZE, CENTERED_SIZE, BufferedImage.TYPE_INT_ARGB);
|
||||
out.setRGB(1, 1, color.getRGB());
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link BufferedImage} of a solid color of given width and height.
|
||||
*
|
||||
* @param width The desired width of the color image.
|
||||
* @param height The desired height of the color image.
|
||||
* @param color The desired color of the image.
|
||||
* @return A {@link BufferedImage} of given dimensions filled with the given color.
|
||||
*/
|
||||
private BufferedImage solidColor(final int width, final int height, final @Nonnull Color color)
|
||||
{
|
||||
final BufferedImage out = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
out.setRGB(x, y, color.getRGB());
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, TheStonedTurtle <https://github.com/TheStonedTurtle>
|
||||
* 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.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.runelite.api.Item;
|
||||
import net.runelite.api.ItemID;
|
||||
import net.runelite.http.api.loottracker.GameItem;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ItemUtilTest
|
||||
{
|
||||
private static final Set<Integer> SOME_IDS = Set.of(ItemID.MITHRIL_BAR, ItemID.DRAGON_BONES);
|
||||
private static final Set<Integer> WRONG_IDS = Set.of(ItemID.SCYTHE_OF_VITUR, ItemID.TWISTED_BOW);
|
||||
private static final Set<Integer> MIX_IDS = Set.of(
|
||||
ItemID.MITHRIL_BAR, ItemID.DRAGON_BONES,
|
||||
ItemID.SCYTHE_OF_VITUR, ItemID.TWISTED_BOW
|
||||
);
|
||||
|
||||
private static final Map<Integer, GameItem> SOME_MAP = new HashMap<>();
|
||||
private static final Map<Integer, GameItem> ALL_MAP = new HashMap<>();
|
||||
|
||||
private static final Item[] items = new Item[6];
|
||||
|
||||
static
|
||||
{
|
||||
SOME_MAP.put(ItemID.MITHRIL_BAR, new GameItem(ItemID.MITHRIL_BAR, 6));
|
||||
SOME_MAP.put(ItemID.DRAGON_BONES, new GameItem(ItemID.DRAGON_BONES, 2));
|
||||
|
||||
ALL_MAP.putAll(SOME_MAP);
|
||||
ALL_MAP.put(ItemID.COINS_995, new GameItem(ItemID.COINS_995, 1000));
|
||||
ALL_MAP.put(ItemID.CHEWED_BONES, new GameItem(ItemID.CHEWED_BONES, 1));
|
||||
|
||||
items[0] = createItem(ItemID.MITHRIL_BAR, 3);
|
||||
items[1] = createItem(ItemID.DRAGON_BONES, 1);
|
||||
items[2] = createItem(ItemID.COINS_995, 1000);
|
||||
|
||||
items[3] = createItem(ItemID.MITHRIL_BAR, 3);
|
||||
items[4] = createItem(ItemID.DRAGON_BONES, 1);
|
||||
items[5] = createItem(ItemID.CHEWED_BONES, 1);
|
||||
}
|
||||
|
||||
private static Item createItem(int id, int qty)
|
||||
{
|
||||
Item i = mock(Item.class);
|
||||
when(i.getId())
|
||||
.thenReturn(id);
|
||||
when(i.getQuantity())
|
||||
.thenReturn(qty);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toGameItemMap()
|
||||
{
|
||||
Map<Integer, GameItem> itemMap = ItemUtil.toGameItemMap(items, SOME_IDS);
|
||||
assertEquals(SOME_MAP, itemMap);
|
||||
assertNotEquals(ALL_MAP, itemMap);
|
||||
|
||||
Map<Integer, GameItem> itemMap2 = ItemUtil.toGameItemMap(items);
|
||||
assertNotEquals(SOME_MAP, itemMap2);
|
||||
assertEquals(ALL_MAP, itemMap2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsAllItemIds()
|
||||
{
|
||||
assertTrue(ItemUtil.containsAllItemIds(items, SOME_IDS));
|
||||
assertFalse(ItemUtil.containsAllItemIds(items, WRONG_IDS));
|
||||
assertFalse(ItemUtil.containsAllItemIds(items, MIX_IDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsAnyItemId()
|
||||
{
|
||||
assertTrue(ItemUtil.containsAnyItemId(items, SOME_IDS));
|
||||
assertFalse(ItemUtil.containsAnyItemId(items, WRONG_IDS));
|
||||
assertTrue(ItemUtil.containsAnyItemId(items, MIX_IDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsItemId()
|
||||
{
|
||||
assertTrue(ItemUtil.containsItemId(items, ItemID.COINS_995));
|
||||
assertFalse(ItemUtil.containsItemId(items, ItemID.TWISTED_BOW));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsAllGameItems()
|
||||
{
|
||||
assertTrue(ItemUtil.containsAllGameItems(items, SOME_MAP.values()));
|
||||
assertTrue(ItemUtil.containsAllGameItems(items, ALL_MAP.values()));
|
||||
|
||||
Collection<GameItem> wrongItems = new ArrayList<>(SOME_MAP.values());
|
||||
wrongItems.add(new GameItem(ItemID.TWISTED_BOW, 1));
|
||||
assertFalse(ItemUtil.containsAllGameItems(items, wrongItems));
|
||||
|
||||
assertFalse(ItemUtil.containsAllGameItems(items, new GameItem(ItemID.MITHRIL_BAR, 7)));
|
||||
assertTrue(ItemUtil.containsAllGameItems(items, new GameItem(ItemID.MITHRIL_BAR, 6)));
|
||||
assertTrue(ItemUtil.containsAllGameItems(items, new GameItem(ItemID.MITHRIL_BAR, 5)));
|
||||
assertFalse(ItemUtil.containsAllGameItems(items, new GameItem(ItemID.MITHRIL_BAR, 5), new GameItem(ItemID.TWISTED_BOW, 1)));
|
||||
}
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, arlyon <https://github.com/arlyon>
|
||||
* 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.util;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class QuantityFormatterTest
|
||||
{
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
Locale.setDefault(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quantityToRSDecimalStackSize()
|
||||
{
|
||||
assertEquals("0", QuantityFormatter.quantityToRSDecimalStack(0));
|
||||
assertEquals("8500", QuantityFormatter.quantityToRSDecimalStack(8_500));
|
||||
assertEquals("10K", QuantityFormatter.quantityToRSDecimalStack(10_000));
|
||||
assertEquals("21.7K", QuantityFormatter.quantityToRSDecimalStack(21_700));
|
||||
assertEquals("100K", QuantityFormatter.quantityToRSDecimalStack(100_000));
|
||||
assertEquals("100.3K", QuantityFormatter.quantityToRSDecimalStack(100_300));
|
||||
assertEquals("1M", QuantityFormatter.quantityToRSDecimalStack(1_000_000));
|
||||
assertEquals("8.4M", QuantityFormatter.quantityToRSDecimalStack(8_450_000));
|
||||
assertEquals("10M", QuantityFormatter.quantityToRSDecimalStack(10_000_000));
|
||||
assertEquals("12.8M", QuantityFormatter.quantityToRSDecimalStack(12_800_000));
|
||||
assertEquals("100M", QuantityFormatter.quantityToRSDecimalStack(100_000_000));
|
||||
assertEquals("250.1M", QuantityFormatter.quantityToRSDecimalStack(250_100_000));
|
||||
assertEquals("1B", QuantityFormatter.quantityToRSDecimalStack(1_000_000_000));
|
||||
assertEquals("1.5B", QuantityFormatter.quantityToRSDecimalStack(1500_000_000));
|
||||
assertEquals("2.1B", QuantityFormatter.quantityToRSDecimalStack(Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quantityToStackSize()
|
||||
{
|
||||
assertEquals("0", QuantityFormatter.quantityToStackSize(0));
|
||||
assertEquals("999", QuantityFormatter.quantityToStackSize(999));
|
||||
assertEquals("1,000", QuantityFormatter.quantityToStackSize(1000));
|
||||
assertEquals("9,450", QuantityFormatter.quantityToStackSize(9450));
|
||||
assertEquals("14.5K", QuantityFormatter.quantityToStackSize(14_500));
|
||||
assertEquals("99.9K", QuantityFormatter.quantityToStackSize(99_920));
|
||||
assertEquals("100K", QuantityFormatter.quantityToStackSize(100_000));
|
||||
assertEquals("10M", QuantityFormatter.quantityToStackSize(10_000_000));
|
||||
assertEquals("2.14B", QuantityFormatter.quantityToStackSize(Integer.MAX_VALUE));
|
||||
assertEquals("100B", QuantityFormatter.quantityToStackSize(100_000_000_000L));
|
||||
|
||||
assertEquals("0", QuantityFormatter.quantityToStackSize(-0));
|
||||
assertEquals("-400", QuantityFormatter.quantityToStackSize(-400));
|
||||
assertEquals("-400K", QuantityFormatter.quantityToStackSize(-400_000));
|
||||
assertEquals("-40M", QuantityFormatter.quantityToStackSize(-40_000_000));
|
||||
assertEquals("-2.14B", QuantityFormatter.quantityToStackSize(Integer.MIN_VALUE));
|
||||
assertEquals("-400B", QuantityFormatter.quantityToStackSize(-400_000_000_000L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quantityToPreciseStackSize()
|
||||
{
|
||||
assertEquals("0", QuantityFormatter.quantityToRSDecimalStack(0));
|
||||
assertEquals("8500", QuantityFormatter.quantityToRSDecimalStack(8_500, true));
|
||||
assertEquals("10K", QuantityFormatter.quantityToRSDecimalStack(10_000, true));
|
||||
assertEquals("21.7K", QuantityFormatter.quantityToRSDecimalStack(21_710, true));
|
||||
assertEquals("100K", QuantityFormatter.quantityToRSDecimalStack(100_000, true));
|
||||
assertEquals("100.3K", QuantityFormatter.quantityToRSDecimalStack(100_310, true));
|
||||
assertEquals("1M", QuantityFormatter.quantityToRSDecimalStack(1_000_000, true));
|
||||
assertEquals("8.45M", QuantityFormatter.quantityToRSDecimalStack(8_450_000, true));
|
||||
assertEquals("8.451M", QuantityFormatter.quantityToRSDecimalStack(8_451_000, true));
|
||||
assertEquals("10M", QuantityFormatter.quantityToRSDecimalStack(10_000_000, true));
|
||||
assertEquals("12.8M", QuantityFormatter.quantityToRSDecimalStack(12_800_000, true));
|
||||
assertEquals("12.85M", QuantityFormatter.quantityToRSDecimalStack(12_850_000, true));
|
||||
assertEquals("12.851M", QuantityFormatter.quantityToRSDecimalStack(12_851_000, true));
|
||||
assertEquals("100M", QuantityFormatter.quantityToRSDecimalStack(100_000_000, true));
|
||||
assertEquals("250.1M", QuantityFormatter.quantityToRSDecimalStack(250_100_000, true));
|
||||
assertEquals("250.151M", QuantityFormatter.quantityToRSDecimalStack(250_151_000, true));
|
||||
assertEquals("1B", QuantityFormatter.quantityToRSDecimalStack(1_000_000_000, true));
|
||||
assertEquals("1.5B", QuantityFormatter.quantityToRSDecimalStack(1500_000_000, true));
|
||||
assertEquals("1.55B", QuantityFormatter.quantityToRSDecimalStack(1550_000_000, true));
|
||||
assertEquals("2.147B", QuantityFormatter.quantityToRSDecimalStack(Integer.MAX_VALUE, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stackSizeToQuantity() throws ParseException
|
||||
{
|
||||
assertEquals(0, QuantityFormatter.parseQuantity("0"));
|
||||
assertEquals(907, QuantityFormatter.parseQuantity("907"));
|
||||
assertEquals(1200, QuantityFormatter.parseQuantity("1200"));
|
||||
assertEquals(10_500, QuantityFormatter.parseQuantity("10,500"));
|
||||
assertEquals(10_500, QuantityFormatter.parseQuantity("10.5K"));
|
||||
assertEquals(33_560_000, QuantityFormatter.parseQuantity("33.56M"));
|
||||
assertEquals(2_000_000_000, QuantityFormatter.parseQuantity("2B"));
|
||||
|
||||
assertEquals(0, QuantityFormatter.parseQuantity("-0"));
|
||||
assertEquals(-400, QuantityFormatter.parseQuantity("-400"));
|
||||
assertEquals(-400_000, QuantityFormatter.parseQuantity("-400k"));
|
||||
assertEquals(-40_543_000, QuantityFormatter.parseQuantity("-40.543M"));
|
||||
|
||||
try
|
||||
{
|
||||
QuantityFormatter.parseQuantity("0L");
|
||||
fail("Should have thrown an exception for invalid suffix.");
|
||||
}
|
||||
catch (ParseException ignore)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
QuantityFormatter.parseQuantity("badstack");
|
||||
fail("Should have thrown an exception for improperly formatted stack.");
|
||||
}
|
||||
catch (ParseException ignore)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.util;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static net.runelite.client.util.WildcardMatcher.matches;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import org.junit.Test;
|
||||
|
||||
public class WildcardMatcherTest
|
||||
{
|
||||
@Test
|
||||
public void testMatches()
|
||||
{
|
||||
assertTrue(matches("rune*", "rune pouch"));
|
||||
assertTrue(matches("rune*", "Rune pouch"));
|
||||
assertFalse(matches("Abyssal whip", "Adamant dagger"));
|
||||
assertTrue(matches("rune*", "Runeite Ore"));
|
||||
assertTrue(matches("Abyssal whip", "Abyssal whip"));
|
||||
assertTrue(matches("string $ with special character", "string $ with special character"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user