2014-04-14 17:49:04 +02:00
|
|
|
package com.comphenix.protocol.wrappers;
|
|
|
|
|
2022-02-20 12:16:11 +01:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
2014-04-14 17:49:04 +02:00
|
|
|
|
|
|
|
import com.comphenix.protocol.BukkitInitialization;
|
2014-07-30 03:49:37 +02:00
|
|
|
import com.google.common.base.Charsets;
|
2016-01-10 21:52:35 +01:00
|
|
|
import com.google.common.collect.Multimap;
|
|
|
|
import com.mojang.authlib.GameProfile;
|
|
|
|
import com.mojang.authlib.properties.Property;
|
|
|
|
import com.mojang.authlib.properties.PropertyMap;
|
2022-02-20 12:16:11 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
|
|
import org.junit.jupiter.api.Test;
|
2014-04-14 17:49:04 +02:00
|
|
|
|
|
|
|
public class WrappedGameProfileTest {
|
2015-06-24 17:48:07 +02:00
|
|
|
|
2022-02-20 12:16:11 +01:00
|
|
|
@BeforeAll
|
2015-06-24 17:48:07 +02:00
|
|
|
public static void initializeBukkit() {
|
2022-02-20 12:16:11 +01:00
|
|
|
BukkitInitialization.initializeAll();
|
2014-04-14 17:49:04 +02:00
|
|
|
}
|
2016-01-10 21:52:35 +01:00
|
|
|
|
2014-04-14 17:49:04 +02:00
|
|
|
@Test
|
2016-01-10 21:52:35 +01:00
|
|
|
public void testWrapper() {
|
2022-02-20 12:16:11 +01:00
|
|
|
GameProfile profile = new GameProfile(UUID.nameUUIDFromBytes("ProtocolLib".getBytes(Charsets.UTF_8)),
|
|
|
|
"ProtocolLib");
|
2016-01-10 21:52:35 +01:00
|
|
|
WrappedGameProfile wrapper = WrappedGameProfile.fromHandle(profile);
|
|
|
|
|
|
|
|
assertEquals(profile.getId(), wrapper.getUUID());
|
|
|
|
assertEquals(profile.getName(), wrapper.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@SuppressWarnings("deprecation")
|
2014-04-14 17:49:04 +02:00
|
|
|
public void testSkinUpdate() {
|
2014-07-30 03:49:37 +02:00
|
|
|
final UUID uuid = UUID.nameUUIDFromBytes("123".getBytes(Charsets.UTF_8));
|
2022-02-20 12:16:11 +01:00
|
|
|
|
|
|
|
assertNull(new WrappedGameProfile((String) null, "Test").getId());
|
2014-07-30 03:49:37 +02:00
|
|
|
assertEquals(uuid, new WrappedGameProfile("123", "Test").getUUID());
|
2014-04-14 17:49:04 +02:00
|
|
|
}
|
2022-02-20 12:16:11 +01:00
|
|
|
|
2014-07-30 03:49:37 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2022-02-20 12:16:11 +01:00
|
|
|
@Test
|
2014-04-14 17:49:04 +02:00
|
|
|
public void testNullFailure() {
|
2022-02-20 12:16:11 +01:00
|
|
|
assertThrows(RuntimeException.class, () -> new WrappedGameProfile((String) null, null));
|
2014-04-14 17:49:04 +02:00
|
|
|
}
|
2016-01-10 21:52:35 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetProperties() {
|
2022-02-20 12:16:11 +01:00
|
|
|
GameProfile profile = new GameProfile(UUID.nameUUIDFromBytes("ProtocolLib".getBytes(Charsets.UTF_8)),
|
|
|
|
"ProtocolLib");
|
2016-01-10 21:52:35 +01:00
|
|
|
|
|
|
|
String name = "test";
|
|
|
|
String value = "test";
|
|
|
|
String signature = null;
|
|
|
|
|
|
|
|
profile.getProperties().put(name, new Property(name, value, signature));
|
|
|
|
|
|
|
|
WrappedGameProfile wrapper = WrappedGameProfile.fromHandle(profile);
|
|
|
|
Multimap<String, WrappedSignedProperty> properties = wrapper.getProperties();
|
|
|
|
WrappedSignedProperty property = properties.get(name).iterator().next();
|
|
|
|
|
|
|
|
assertEquals(property.getName(), name);
|
|
|
|
assertEquals(property.getValue(), value);
|
|
|
|
assertEquals(property.getSignature(), signature);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAddProperties() {
|
|
|
|
String name = "test";
|
|
|
|
String value = "test";
|
|
|
|
String signature = null;
|
|
|
|
|
2022-02-20 12:16:11 +01:00
|
|
|
WrappedGameProfile wrapper = new WrappedGameProfile(UUID.nameUUIDFromBytes("ProtocolLib".getBytes(Charsets.UTF_8)),
|
|
|
|
"ProtocolLib");
|
2016-01-10 21:52:35 +01:00
|
|
|
wrapper.getProperties().put(name, new WrappedSignedProperty(name, value, signature));
|
|
|
|
|
|
|
|
GameProfile profile = (GameProfile) wrapper.getHandle();
|
|
|
|
PropertyMap properties = profile.getProperties();
|
|
|
|
Property property = properties.get(name).iterator().next();
|
|
|
|
|
|
|
|
assertEquals(property.getName(), name);
|
|
|
|
assertEquals(property.getValue(), value);
|
|
|
|
assertEquals(property.getSignature(), signature);
|
|
|
|
}
|
2016-05-21 23:37:13 +02:00
|
|
|
}
|