2022-01-04 07:08:49 +01:00
|
|
|
package net.minestom.server.utils;
|
2021-11-15 19:23:20 +01:00
|
|
|
|
|
|
|
import net.minestom.server.utils.mojang.MojangUtils;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
2024-03-18 04:25:35 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2021-11-15 19:23:20 +01:00
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
|
|
public class TestMojangUtils {
|
2024-03-18 04:25:35 +01:00
|
|
|
private final UUID JEB_UUID = UUID.fromString("853c80ef-3c37-49fd-aa49-938b674adae6");
|
2021-11-15 19:23:20 +01:00
|
|
|
@Test
|
|
|
|
public void testValidNameWorks() {
|
|
|
|
var result = MojangUtils.fromUsername("jeb_");
|
|
|
|
assertNotNull(result);
|
|
|
|
assertEquals("jeb_", result.get("name").getAsString());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testInvalidNameReturnsNull() {
|
|
|
|
var result = MojangUtils.fromUsername("jfdsa84vvcxadubasdfcvn"); // Longer than 16, always invalid
|
2022-02-14 21:04:37 +01:00
|
|
|
assertNull(result);
|
2021-11-15 19:23:20 +01:00
|
|
|
}
|
2023-03-18 01:02:18 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testValidUuidWorks() {
|
2024-03-18 04:25:35 +01:00
|
|
|
var result = MojangUtils.fromUuid(JEB_UUID.toString());
|
2023-03-18 01:02:18 +01:00
|
|
|
assertNotNull(result);
|
|
|
|
assertEquals("jeb_", result.get("name").getAsString());
|
|
|
|
assertEquals("853c80ef3c3749fdaa49938b674adae6", result.get("id").getAsString());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testInvalidUuidReturnsNull() {
|
|
|
|
var result = MojangUtils.fromUuid("853c80ef3c3749fdaa49938b674adae6a"); // Longer than 32, always invalid
|
|
|
|
assertNull(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testNonExistentUuidReturnsNull() {
|
|
|
|
var result = MojangUtils.fromUuid("00000000-0000-0000-0000-000000000000");
|
|
|
|
assertNull(result);
|
|
|
|
}
|
2024-03-18 04:25:35 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testValidUUIDWorks() {
|
|
|
|
var result = MojangUtils.fromUuid(JEB_UUID);
|
|
|
|
assertNotNull(result);
|
|
|
|
assertEquals("jeb_", result.get("name").getAsString());
|
|
|
|
assertEquals("853c80ef3c3749fdaa49938b674adae6", result.get("id").getAsString());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetValidNameWorks() throws IOException {
|
|
|
|
assertEquals(JEB_UUID, MojangUtils.getUUID("jeb_"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetValidUUIDWorks() throws IOException {
|
|
|
|
assertEquals("jeb_", MojangUtils.getUsername(JEB_UUID));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetInvalidNameThrows() {
|
|
|
|
assertThrows(IOException.class, () -> MojangUtils.getUUID("a")); // Too short
|
|
|
|
}
|
2021-11-15 19:23:20 +01:00
|
|
|
}
|