Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 00:00:47 +01:00
Another test for sanity.
Dieser Commit ist enthalten in:
Ursprung
73abc8f9ad
Commit
302df0299e
@ -1,6 +1,7 @@
|
||||
package com.velocitypowered.proxy.protocol;
|
||||
|
||||
import com.velocitypowered.proxy.protocol.packets.Handshake;
|
||||
import com.velocitypowered.proxy.protocol.packets.Ping;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -9,6 +10,8 @@ class PacketRegistryTest {
|
||||
private StateRegistry.PacketRegistry setupRegistry() {
|
||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(ProtocolConstants.Direction.TO_CLIENT, StateRegistry.HANDSHAKE);
|
||||
registry.register(Handshake.class, Handshake::new, new StateRegistry.PacketMapping(0x00, 1));
|
||||
registry.register(Ping.class, Ping::new, new StateRegistry.PacketMapping(0x01, 1),
|
||||
new StateRegistry.PacketMapping(0x02, 5));
|
||||
return registry;
|
||||
}
|
||||
|
||||
@ -44,5 +47,18 @@ class PacketRegistryTest {
|
||||
void failOnNoMappings() {
|
||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(ProtocolConstants.Direction.TO_CLIENT, StateRegistry.HANDSHAKE);
|
||||
assertThrows(IllegalArgumentException.class, () -> registry.register(Handshake.class, Handshake::new));
|
||||
assertThrows(IllegalArgumentException.class, () -> registry.getId(new Handshake(), 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void packetRegistryProvidesCorrectVersionsForMultipleMappings() {
|
||||
StateRegistry.PacketRegistry registry = setupRegistry();
|
||||
assertNotNull(registry.createPacket(1, 1), "Packet was not found in registry despite being being registered with ID 1 and version 1");
|
||||
assertNotNull(registry.createPacket(1, 2), "Packet was not found in registry despite being being registered with ID 1 and version 1 (we are looking up version 2)");
|
||||
assertNotNull(registry.createPacket(2, 5), "Packet was not found in registry despite being being registered with ID 2 and version 5");
|
||||
assertNotNull(registry.createPacket(2, 6), "Packet was not found in registry despite being being registered with ID 2 and version 5 (we are looking up version 6)");
|
||||
|
||||
assertEquals(1, registry.getId(new Ping(), 1), "Wrong ID provided from registry");
|
||||
assertEquals(2, registry.getId(new Ping(), 5), "Wrong ID provided from registry");
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren