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());
}
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));
}
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());
}
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());
}
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")));
}
Aggregations