-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemUtilIntegrationTest.java
More file actions
58 lines (43 loc) · 2.12 KB
/
ItemUtilIntegrationTest.java
File metadata and controls
58 lines (43 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package net.theevilreaper.bounce.util;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.minestom.server.component.DataComponents;
import net.minestom.server.entity.Player;
import net.minestom.server.instance.Instance;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import net.minestom.server.item.component.EnchantmentList;
import net.minestom.server.item.enchant.Enchantment;
import net.minestom.testing.Env;
import net.minestom.testing.extension.MicrotusExtension;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(MicrotusExtension.class)
class ItemUtilIntegrationTest {
@Test
void testItemStackSet(@NotNull Env env) {
Instance instance = env.createFlatInstance();
Player player = env.createPlayer(instance);
assertEquals(ItemStack.AIR, player.getInventory().getItemStack(0));
// Test setting an item stack
ItemUtil.setItem(player);
ItemStack itemStack = player.getInventory().getItemStack(0);
// Verify that the item stack is not null and has the expected properties
assertNotEquals(ItemStack.AIR, itemStack);
assertEquals(Material.FEATHER, itemStack.material());
assertTrue(itemStack.has(DataComponents.CUSTOM_NAME));
assertTrue(itemStack.has(DataComponents.ENCHANTMENTS));
Component customName = itemStack.get(DataComponents.CUSTOM_NAME);
assertNotNull(customName);
String displayName = PlainTextComponentSerializer.plainText().serialize(customName);
assertNotNull(displayName);
assertTrue(displayName.contains("Recoil-pushing recoil pusher"));
EnchantmentList enchantmentList = itemStack.get(DataComponents.ENCHANTMENTS);
assertNotNull(enchantmentList);
assertEquals(1, enchantmentList.enchantments().size());
assertTrue(enchantmentList.has(Enchantment.KNOCKBACK));
env.destroyInstance(instance, true);
}
}