From 5802179206d8d80c8b5d6b0e66e5cf7e8f1e61cb Mon Sep 17 00:00:00 2001 From: themode Date: Sat, 19 Feb 2022 03:08:09 +0100 Subject: [PATCH] More view engine rule tests --- .../entity/EntityViewIntegrationTest.java | 71 --------- .../EntityViewerRuleIntegrationTest.java | 147 ++++++++++++++++++ 2 files changed, 147 insertions(+), 71 deletions(-) create mode 100644 src/test/java/net/minestom/server/entity/EntityViewerRuleIntegrationTest.java diff --git a/src/test/java/net/minestom/server/entity/EntityViewIntegrationTest.java b/src/test/java/net/minestom/server/entity/EntityViewIntegrationTest.java index 0371783ca..ebcd6e6c0 100644 --- a/src/test/java/net/minestom/server/entity/EntityViewIntegrationTest.java +++ b/src/test/java/net/minestom/server/entity/EntityViewIntegrationTest.java @@ -6,8 +6,6 @@ import net.minestom.server.coordinate.Pos; import net.minestom.server.network.packet.server.play.SpawnLivingEntityPacket; 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.assertTrue; @@ -98,75 +96,6 @@ public class EntityViewIntegrationTest { assertEquals(1, p2.getViewers().size()); } - @Test - public void viewableRule(Env env) { - var instance = env.createFlatInstance(); - var p1 = env.createPlayer(instance, new Pos(0, 42, 0)); - p1.updateViewableRule(player -> player.getEntityId() == p1.getEntityId() + 1); - - var p2 = env.createPlayer(instance, new Pos(0, 42, 0)); - - assertEquals(1, p1.getViewers().size()); - assertEquals(1, p2.getViewers().size()); - - p1.updateViewableRule(player -> false); - - assertEquals(0, p1.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 - public void viewerRule(Env env) { - var instance = env.createFlatInstance(); - var p1 = env.createPlayer(instance, new Pos(0, 42, 0)); - p1.updateViewerRule(player -> player.getEntityId() == p1.getEntityId() + 1); - - var p2 = env.createPlayer(instance, new Pos(0, 42, 0)); - - assertEquals(1, p1.getViewers().size()); - assertEquals(1, p2.getViewers().size()); - - p1.updateViewerRule(player -> false); - - assertEquals(1, p1.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 public void vehicle(Env env) { var instance = env.createFlatInstance(); diff --git a/src/test/java/net/minestom/server/entity/EntityViewerRuleIntegrationTest.java b/src/test/java/net/minestom/server/entity/EntityViewerRuleIntegrationTest.java new file mode 100644 index 000000000..f967fbc00 --- /dev/null +++ b/src/test/java/net/minestom/server/entity/EntityViewerRuleIntegrationTest.java @@ -0,0 +1,147 @@ +package net.minestom.server.entity; + +import net.minestom.server.api.Env; +import net.minestom.server.api.EnvTest; +import net.minestom.server.coordinate.Pos; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@EnvTest +public class EntityViewerRuleIntegrationTest { + + @Test + public void viewableRule(Env env) { + var instance = env.createFlatInstance(); + var p1 = env.createPlayer(instance, new Pos(0, 42, 0)); + p1.updateViewableRule(p -> p.getEntityId() == p1.getEntityId() + 1); + + var p2 = env.createPlayer(instance, new Pos(0, 42, 0)); + + assertEquals(1, p1.getViewers().size()); + assertEquals(1, p2.getViewers().size()); + + p1.updateViewableRule(player -> false); + + assertEquals(0, p1.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(p -> 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 + public void viewableRuleDouble(Env env) { + var instance = env.createFlatInstance(); + var p1 = env.createPlayer(instance, new Pos(0, 42, 0)); + var p2 = env.createPlayer(instance, new Pos(0, 42, 0)); + assertEquals(1, p1.getViewers().size()); + assertEquals(1, p2.getViewers().size()); + + AtomicBoolean enabled1 = new AtomicBoolean(false); + AtomicBoolean enabled2 = new AtomicBoolean(false); + + p1.updateViewableRule(p -> enabled1.get()); + p2.updateViewableRule(p -> enabled2.get()); + assertEquals(0, p1.getViewers().size()); + assertEquals(0, p2.getViewers().size()); + + enabled1.set(true); + p1.updateViewableRule(); + assertEquals(1, p1.getViewers().size()); + assertEquals(0, p2.getViewers().size()); + + enabled2.set(true); + p2.updateViewableRule(); + assertEquals(1, p1.getViewers().size()); + assertEquals(1, p2.getViewers().size()); + + enabled1.set(false); + p1.updateViewableRule(); + assertEquals(0, p1.getViewers().size()); + assertEquals(1, p2.getViewers().size()); + } + + @Test + public void viewerRule(Env env) { + var instance = env.createFlatInstance(); + var p1 = env.createPlayer(instance, new Pos(0, 42, 0)); + p1.updateViewerRule(e -> e.getEntityId() == p1.getEntityId() + 1); + + var p2 = env.createPlayer(instance, new Pos(0, 42, 0)); + + assertEquals(1, p1.getViewers().size()); + assertEquals(1, p2.getViewers().size()); + + p1.updateViewerRule(player -> false); + + assertEquals(1, p1.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(e -> 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 + public void viewerRuleDouble(Env env) { + var instance = env.createFlatInstance(); + var p1 = env.createPlayer(instance, new Pos(0, 42, 0)); + var p2 = env.createPlayer(instance, new Pos(0, 42, 0)); + assertEquals(1, p1.getViewers().size()); + assertEquals(1, p2.getViewers().size()); + + AtomicBoolean enabled1 = new AtomicBoolean(false); + AtomicBoolean enabled2 = new AtomicBoolean(false); + + p1.updateViewerRule(e -> enabled1.get()); + p2.updateViewerRule(e -> enabled2.get()); + assertEquals(0, p1.getViewers().size()); + assertEquals(0, p2.getViewers().size()); + + enabled1.set(true); + p1.updateViewerRule(); + assertEquals(0, p1.getViewers().size()); + assertEquals(1, p2.getViewers().size()); + + enabled2.set(true); + p2.updateViewerRule(); + assertEquals(1, p1.getViewers().size()); + assertEquals(1, p2.getViewers().size()); + + enabled1.set(false); + p1.updateViewerRule(); + assertEquals(1, p1.getViewers().size()); + assertEquals(0, p2.getViewers().size()); + } +}