fix(ping): support Purpur NameAndId samples
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package games.dmg.spigotstealth;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ServerListPingListenerTest {
|
||||
@Test
|
||||
void removesOnlyConcealedPlayersFromNativeServerPingSample() {
|
||||
UUID concealedId = UUID.randomUUID();
|
||||
Player visible = player(UUID.randomUUID());
|
||||
Player concealed = player(concealedId);
|
||||
ArrayList<Player> sample = new ArrayList<>(List.of(visible, concealed));
|
||||
ServerListPingEvent event = mock(ServerListPingEvent.class);
|
||||
when(event.iterator()).thenReturn(sample.iterator());
|
||||
ServerListPingListener listener = new ServerListPingListener(() -> Set.of(concealedId));
|
||||
|
||||
listener.onServerListPing(event);
|
||||
|
||||
assertEquals(List.of(visible), sample);
|
||||
}
|
||||
|
||||
private static Player player(UUID playerId) {
|
||||
Player player = mock(Player.class);
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package games.dmg.spigotstealth;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ServerPingCompatibilityGuardTest {
|
||||
@Test
|
||||
void compatibilityFailureLeavesPingHandlingUsableAndWarnsOnlyOnce() {
|
||||
ArrayList<String> warnings = new ArrayList<>();
|
||||
ServerPingCompatibilityGuard guard = new ServerPingCompatibilityGuard(warnings::add);
|
||||
|
||||
assertDoesNotThrow(() -> guard.run(() -> {
|
||||
throw new IllegalArgumentException("unsupported profile representation");
|
||||
}));
|
||||
assertDoesNotThrow(() -> guard.run(() -> {
|
||||
throw new IllegalArgumentException("unsupported profile representation");
|
||||
}));
|
||||
|
||||
assertEquals(1, warnings.size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user