Add tests for manual viewer/viewable update

This commit is contained in:
themode 2022-02-19 02:12:24 +01:00
parent 688ab31d79
commit 7634096bce

View File

@ -6,6 +6,8 @@ import net.minestom.server.coordinate.Pos;
import net.minestom.server.network.packet.server.play.SpawnLivingEntityPacket; import net.minestom.server.network.packet.server.play.SpawnLivingEntityPacket;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -113,6 +115,24 @@ public class EntityViewIntegrationTest {
assertEquals(1, p2.getViewers().size()); assertEquals(1, p2.getViewers().size());
} }
@Test
public void viewableRuleUpdate(Env env) {
var instance = env.createFlatInstance();
var p1 = env.createPlayer(instance, new Pos(0, 42, 0));
AtomicBoolean enabled = new AtomicBoolean(false);
p1.updateViewableRule(player -> enabled.get());
var p2 = env.createPlayer(instance, new Pos(0, 42, 0));
assertEquals(0, p1.getViewers().size());
assertEquals(1, p2.getViewers().size());
enabled.set(true);
p1.updateViewableRule();
assertEquals(1, p1.getViewers().size());
assertEquals(1, p2.getViewers().size());
}
@Test @Test
public void viewerRule(Env env) { public void viewerRule(Env env) {
var instance = env.createFlatInstance(); var instance = env.createFlatInstance();
@ -130,6 +150,23 @@ public class EntityViewIntegrationTest {
assertEquals(0, p2.getViewers().size()); assertEquals(0, p2.getViewers().size());
} }
@Test
public void viewerRuleUpdate(Env env) {
var instance = env.createFlatInstance();
var p1 = env.createPlayer(instance, new Pos(0, 42, 0));
AtomicBoolean enabled = new AtomicBoolean(false);
p1.updateViewerRule(player -> enabled.get());
var p2 = env.createPlayer(instance, new Pos(0, 42, 0));
assertEquals(1, p1.getViewers().size());
assertEquals(0, p2.getViewers().size());
enabled.set(true);
p1.updateViewerRule();
assertEquals(1, p1.getViewers().size());
assertEquals(1, p2.getViewers().size());
}
@Test @Test
public void vehicle(Env env) { public void vehicle(Env env) {
var instance = env.createFlatInstance(); var instance = env.createFlatInstance();