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

XFEServerManager

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

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

import org.junit.jupiter.api.Test;

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

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

class EconomyAmountsTest {
    @Test
    void convertsDecimalStringsWithoutFloatingPointLoss() {
        assertEquals(12345L, EconomyAmounts.parse("123.45", 2, "amount"));
        assertEquals("123.45", EconomyAmounts.format(12345L, 2));
        assertEquals("1.00", EconomyAmounts.normalize("1", 2, "amount"));
        assertThrows(IllegalArgumentException.class, () -> EconomyAmounts.parse("0.001", 2, "amount"));
    }

    @Test
    void validatesCurrencyBoundsAndPrimaryState() {
        Instant now = Instant.parse("2026-09-04T00:00:00Z");
        CurrencyDefinition currency = new CurrencyDefinition(UUID.randomUUID(), "gems", "宝石", "◆",
                "item:minecraft:diamond", 3, "5", "-10", "100", true,
                true, true, 0, "owner", now, now);
        assertEquals("5.000", currency.initialBalance());
        assertThrows(IllegalArgumentException.class, () -> new CurrencyDefinition(UUID.randomUUID(), "bad", "Bad", "$",
                "item:minecraft:stone", 2, "0", "1", "10", true,
                true, false, 0, "owner", now, now));
        assertThrows(IllegalArgumentException.class, () -> new CurrencyDefinition(UUID.randomUUID(), "bad", "Bad", "$",
                "item:minecraft:stone", 2, "0", "0", "10", true,
                false, true, 0, "owner", now, now));
    }
}