XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEServerManager

【Java】我的世界XFE服务器管理器

公开
关注 0 Fork 0 Star 0
UTF-8
package com.xfestudio.xfeservermanager.core.menu;

import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class MenuDefinitionTest {
    @Test
    void acceptsACompleteControlCatalogAndNormalizesValues() {
        List<MenuDefinition.Control> controls = MenuDefinition.CONTROL_TYPES.stream().sorted()
                .map(type -> new MenuDefinition.Control(type, type, 0, 0, 16, 16, 0, "{player.name}",
                        Map.of("label", "Hello {player.name}"), List.of()))
                .toList();

        MenuDefinition menu = menu(controls);

        assertEquals(MenuDefinition.CONTROL_TYPES.size(), menu.controls().size());
        assertEquals("center", menu.popupPosition());
    }

    @Test
    void rejectsOutOfBoundsDuplicateAndReservedControls() {
        MenuDefinition.Control outside = new MenuDefinition.Control("outside", "button", 190, 0,
                20, 20, 0, "", Map.of(), List.of());
        assertThrows(IllegalArgumentException.class, () -> menu(List.of(outside)));

        MenuDefinition.Control duplicate = new MenuDefinition.Control("same", "button", 0, 0,
                20, 20, 0, "", Map.of(), List.of());
        assertThrows(IllegalArgumentException.class, () -> menu(List.of(duplicate, duplicate)));
        assertThrows(IllegalArgumentException.class, () -> new MenuDefinition.Control("__xfesm_root__", "button",
                0, 0, 20, 20, 0, "", Map.of(), List.of()));
    }

    @Test
    void requiresEveryEventToHaveAnAction() {
        assertThrows(IllegalArgumentException.class,
                () -> new MenuDefinition.EventBinding("click", "", "", false));
        MenuDefinition.EventBinding binding = new MenuDefinition.EventBinding(
                "click", "", UUID.randomUUID().toString(), false);
        assertEquals("click", binding.event());
    }

    private static MenuDefinition menu(List<MenuDefinition.Control> controls) {
        Instant now = Instant.parse("2026-09-04T00:00:00Z");
        return new MenuDefinition(UUID.randomUUID(), "Menu", "", 200, 120, "CENTER",
                0, 0, false, "#101713e8", controls, 0, "owner", now, now);
    }
}