Search in sources :

Example 36 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestEnumSetting method testAllowedValue.

@Test
@DisplayName("Test allowed value")
void testAllowedValue() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MATERIAL_SETTING_TEST_2", new CustomItemStack(Material.DIAMOND, "&cTest"));
    EnumSetting<Material> setting = new EnumSetting<>(item, "test", Material.class, Material.DIAMOND);
    item.addItemSetting(setting);
    item.register(plugin);
    Assertions.assertEquals(Material.DIAMOND.name(), setting.getValue());
    Assertions.assertEquals(Material.DIAMOND, setting.getAsEnumConstant());
    setting.update(Material.EMERALD.name());
    Assertions.assertEquals(Material.EMERALD.name(), setting.getValue());
    Assertions.assertEquals(Material.EMERALD, setting.getAsEnumConstant());
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) Material(org.bukkit.Material) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 37 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestIntRangeSetting method testConstructorValidation.

@Test
@DisplayName("Test Constructor validation")
void testConstructorValidation() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "INT_RANGE_TEST_00", new CustomItemStack(Material.DIAMOND, "&cTest"));
    Assertions.assertThrows(IllegalArgumentException.class, () -> new IntRangeSetting(item, "test", min, -50, max));
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 38 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestItemSettings method testAddItemSetting.

@Test
@DisplayName("Test adding an Item Setting")
void testAddItemSetting() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "ITEM_SETTINGS_TEST_2", new CustomItemStack(Material.DIAMOND, "&cTest"));
    ItemSetting<String> setting = new ItemSetting<>(item, "test", "Hello World");
    Assertions.assertTrue(setting.isType(String.class));
    Assertions.assertFalse(setting.isType(Integer.class));
    item.addItemSetting(setting);
    item.register(plugin);
    Assertions.assertTrue(item.getItemSettings().contains(setting));
    Optional<ItemSetting<String>> optional = item.getItemSetting(setting.getKey(), String.class);
    Assertions.assertTrue(optional.isPresent());
    Assertions.assertEquals(setting, optional.get());
    Assertions.assertEquals("Hello World", setting.getValue());
    Assertions.assertFalse(item.getItemSetting(setting.getKey(), Boolean.class).isPresent());
    Assertions.assertFalse(item.getItemSetting("I do not exist", String.class).isPresent());
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemSetting(io.github.thebusybiscuit.slimefun4.api.items.ItemSetting) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 39 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestItemSettings method testUpdateItemSetting.

@Test
@DisplayName("Test updating an Item Settings value")
void testUpdateItemSetting() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "ITEM_SETTINGS_TEST_3", new CustomItemStack(Material.DIAMOND, "&cTest"));
    ItemSetting<String> setting = new ItemSetting<>(item, "test", "Hello World");
    item.addItemSetting(setting);
    item.register(plugin);
    Assertions.assertEquals("Hello World", setting.getValue());
    setting.update("I am different");
    Assertions.assertEquals("I am different", setting.getValue());
    Assertions.assertThrows(IllegalArgumentException.class, () -> setting.update(null));
    Assertions.assertEquals("I am different", setting.getValue());
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemSetting(io.github.thebusybiscuit.slimefun4.api.items.ItemSetting) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 40 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestItemSettings method testIllegalItemSettings.

@Test
@DisplayName("Test illegal Item Settings arguments")
void testIllegalItemSettings() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "ITEM_SETTINGS_TEST", new CustomItemStack(Material.DIAMOND, "&cTest"));
    item.register(plugin);
    Assertions.assertThrows(IllegalArgumentException.class, () -> item.addItemSetting());
    Assertions.assertThrows(IllegalArgumentException.class, () -> item.addItemSetting((ItemSetting<String>) null));
    Assertions.assertThrows(UnsupportedOperationException.class, () -> item.addItemSetting(new ItemSetting<>(item, "test", "Hello World")));
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemSetting(io.github.thebusybiscuit.slimefun4.api.items.ItemSetting) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)172 Test (org.junit.jupiter.api.Test)100 DisplayName (org.junit.jupiter.api.DisplayName)90 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)83 ItemStack (org.bukkit.inventory.ItemStack)70 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)43 NamespacedKey (org.bukkit.NamespacedKey)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Player (org.bukkit.entity.Player)25 ChestMenu (me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)22 ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)20 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)18 Slimefun (io.github.thebusybiscuit.slimefun4.implementation.Slimefun)12 PlayerProfile (io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile)11 FlexItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup)10 ArrayList (java.util.ArrayList)10 Nonnull (javax.annotation.Nonnull)10 Material (org.bukkit.Material)10 LockedItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup)9 Location (org.bukkit.Location)9