mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-15 11:51:53 +01:00
Add LazyPacketTest
This commit is contained in:
parent
39a0923326
commit
80baeb6e54
29
src/test/java/network/LazyPacketTest.java
Normal file
29
src/test/java/network/LazyPacketTest.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package network;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.minestom.server.message.ChatPosition;
|
||||||
|
import net.minestom.server.network.packet.server.LazyPacket;
|
||||||
|
import net.minestom.server.network.packet.server.play.ChatMessagePacket;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
public class LazyPacketTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCache() {
|
||||||
|
var packet = new ChatMessagePacket(Component.text("Hello World!"), ChatPosition.CHAT, UUID.randomUUID());
|
||||||
|
AtomicBoolean called = new AtomicBoolean(false);
|
||||||
|
var lazy = new LazyPacket(() -> {
|
||||||
|
if (called.getAndSet(true))
|
||||||
|
fail();
|
||||||
|
return packet;
|
||||||
|
});
|
||||||
|
assertSame(packet, lazy.packet());
|
||||||
|
assertSame(packet, lazy.packet());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user