package com.example.tests;
import com.frotty27.hrtk.api.annotation.HytaleSuite;
import com.frotty27.hrtk.api.annotation.HytaleTest;
import com.frotty27.hrtk.api.annotation.Tag;
import com.frotty27.hrtk.api.annotation.DisplayName;
import com.frotty27.hrtk.api.annotation.Order;
import com.frotty27.hrtk.api.assert_.HytaleAssert;
import com.frotty27.hrtk.api.assert_.ItemAssert;
import com.frotty27.hrtk.api.context.HytaleTestContext;
import com.frotty27.hrtk.api.lifecycle.IsolationStrategy;
@HytaleSuite(value = "Item Surface Tests", isolation = IsolationStrategy.NONE)
@Tag("items")
public class ItemSurfaceTests {
@HytaleTest
@Order(1)
@DisplayName("Create an item stack and verify its ID and size")
void createAndVerifyStack(HytaleTestContext ctx) {
// createStack builds a standalone item stack.
// The first argument is the item's asset name, the second is the count.
Object stack = ctx.createStack("Weapon_Sword_Iron", 1);
ItemAssert.assertItemId(stack, "Weapon_Sword_Iron");
ItemAssert.assertStackSize(stack, 1);
}
@HytaleTest
@Order(2)
@DisplayName("Fresh tool has full durability and is not broken")
void freshToolHasFullDurability(HytaleTestContext ctx) {
Object stack = ctx.createStack("Iron_Pickaxe", 1);
// assertNotBroken verifies durability > 0.
// A freshly created tool should always pass this check.
ItemAssert.assertNotBroken(stack);
// You can also check the exact durability value if you know the expected max.
int durability = ctx.getDurability(stack);
int maxDurability = ctx.getMaxDurability(stack);
HytaleAssert.assertTrue(
"Durability should equal max for a new tool",
durability == maxDurability
);
}
@HytaleTest
@Order(3)
@DisplayName("Verify a broken tool is detected")
void brokenToolIsDetected(HytaleTestContext ctx) {
// Create a tool and simulate it being fully depleted.
Object stack = ctx.createStack("Weapon_Sword_Iron", 1);
ctx.setDurability(stack, 0);
ItemAssert.assertBroken(stack);
ItemAssert.assertDurability(stack, 0);
}
@HytaleTest
@Order(4)
@DisplayName("Stackable materials can stack, weapons cannot")
void stackabilityRules(HytaleTestContext ctx) {
// Materials like ingots should be stackable.
Object ingots = ctx.createStack("Iron_Ingot", 32);
ItemAssert.assertStackable(ingots);
// Weapons should not be stackable - each one is a unique item with durability.
Object sword = ctx.createStack("Weapon_Sword_Iron", 1);
ItemAssert.assertNotStackable(sword);
}
@HytaleTest
@Order(5)
@DisplayName("Custom metadata is preserved on item stacks")
void metadataIsPreserved(HytaleTestContext ctx) {
Object stack = ctx.createStack("Weapon_Sword_Iron", 1);
// setMetadata writes a key-value pair to the stack's metadata map.
// This is how mods attach custom data to items (enchantments, custom names, etc.).
ctx.setMetadata(stack, "enchantment", "fire_aspect");
ItemAssert.assertHasMetadata(stack, "enchantment");
Object value = ctx.getMetadata(stack, "enchantment");
HytaleAssert.assertEquals("fire_aspect", value);
}
@HytaleTest
@Order(6)
@DisplayName("Durability assertion catches wrong values")
void durabilityAssertionWorksCorrectly(HytaleTestContext ctx) {
Object stack = ctx.createStack("Iron_Pickaxe", 1);
int maxDurability = ctx.getMaxDurability(stack);
ItemAssert.assertMaxDurability(stack, maxDurability);
ItemAssert.assertDurability(stack, maxDurability);
}
}