From d9e51beebbdd045cfe647ae3a9d69800a303edfc Mon Sep 17 00:00:00 2001 From: themode Date: Thu, 10 Mar 2022 22:43:47 +0100 Subject: [PATCH] Make dedicated snapshot test classes --- .../ChunkSnapshotIntegrationTest.java | 26 +++++++++++ ...ava => EntitySnapshotIntegrationTest.java} | 45 +------------------ .../InstanceSnapshotIntegrationTest.java | 37 +++++++++++++++ 3 files changed, 65 insertions(+), 43 deletions(-) create mode 100644 src/test/java/net/minestom/server/snapshot/ChunkSnapshotIntegrationTest.java rename src/test/java/net/minestom/server/snapshot/{SnapshotIntegrationTest.java => EntitySnapshotIntegrationTest.java} (50%) create mode 100644 src/test/java/net/minestom/server/snapshot/InstanceSnapshotIntegrationTest.java diff --git a/src/test/java/net/minestom/server/snapshot/ChunkSnapshotIntegrationTest.java b/src/test/java/net/minestom/server/snapshot/ChunkSnapshotIntegrationTest.java new file mode 100644 index 000000000..29e1f44fd --- /dev/null +++ b/src/test/java/net/minestom/server/snapshot/ChunkSnapshotIntegrationTest.java @@ -0,0 +1,26 @@ +package net.minestom.server.snapshot; + +import net.minestom.server.api.Env; +import net.minestom.server.api.EnvTest; +import net.minestom.server.instance.block.Block; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@EnvTest +public class ChunkSnapshotIntegrationTest { + + @Test + public void blocks(Env env) { + var instance = env.createFlatInstance(); + instance.setBlock(0, 0, 0, Block.STONE); + var snapshot = ServerSnapshot.update(); + + var inst = snapshot.instances().iterator().next(); + assertEquals(Block.STONE, inst.getBlock(0, 0, 0)); + + assertEquals(1, inst.chunks().size()); + var chunk = inst.chunks().iterator().next(); + assertEquals(Block.STONE, chunk.getBlock(0, 0, 0)); + } +} diff --git a/src/test/java/net/minestom/server/snapshot/SnapshotIntegrationTest.java b/src/test/java/net/minestom/server/snapshot/EntitySnapshotIntegrationTest.java similarity index 50% rename from src/test/java/net/minestom/server/snapshot/SnapshotIntegrationTest.java rename to src/test/java/net/minestom/server/snapshot/EntitySnapshotIntegrationTest.java index 477f56dc3..942214c94 100644 --- a/src/test/java/net/minestom/server/snapshot/SnapshotIntegrationTest.java +++ b/src/test/java/net/minestom/server/snapshot/EntitySnapshotIntegrationTest.java @@ -4,57 +4,16 @@ import net.minestom.server.api.Env; import net.minestom.server.api.EnvTest; import net.minestom.server.entity.Entity; import net.minestom.server.entity.EntityType; -import net.minestom.server.instance.block.Block; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @EnvTest -public class SnapshotIntegrationTest { +public class EntitySnapshotIntegrationTest { @Test - public void instance(Env env) { - env.createFlatInstance(); - var snapshot = ServerSnapshot.update(); - - // Ensure that the collection is immutable - { - var instances = snapshot.instances(); - assertEquals(1, instances.size()); - - env.createFlatInstance(); - instances = snapshot.instances(); - assertEquals(1, instances.size()); - } - - var inst = snapshot.instances().iterator().next(); - - assertEquals(snapshot, inst.server(), "Instance must have access to the server snapshot"); - - assertEquals(0, inst.time()); - assertEquals(0, inst.worldAge()); - - assertEquals(0, inst.chunks().size()); - assertEquals(0, inst.entities().size()); - } - - @Test - public void chunk(Env env) { - var instance = env.createFlatInstance(); - instance.setBlock(0, 0, 0, Block.STONE); - var snapshot = ServerSnapshot.update(); - - var inst = snapshot.instances().iterator().next(); - assertEquals(Block.STONE, inst.getBlock(0, 0, 0)); - - assertEquals(1, inst.chunks().size()); - var chunk = inst.chunks().iterator().next(); - assertEquals(Block.STONE, chunk.getBlock(0, 0, 0)); - } - - @Test - public void entity(Env env) { + public void basic(Env env) { var instance = env.createFlatInstance(); var ent = new Entity(EntityType.ZOMBIE); ent.setInstance(instance).join(); diff --git a/src/test/java/net/minestom/server/snapshot/InstanceSnapshotIntegrationTest.java b/src/test/java/net/minestom/server/snapshot/InstanceSnapshotIntegrationTest.java new file mode 100644 index 000000000..88fbf1fc0 --- /dev/null +++ b/src/test/java/net/minestom/server/snapshot/InstanceSnapshotIntegrationTest.java @@ -0,0 +1,37 @@ +package net.minestom.server.snapshot; + +import net.minestom.server.api.Env; +import net.minestom.server.api.EnvTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@EnvTest +public class InstanceSnapshotIntegrationTest { + + @Test + public void basic(Env env) { + env.createFlatInstance(); + var snapshot = ServerSnapshot.update(); + + // Ensure that the collection is immutable + { + var instances = snapshot.instances(); + assertEquals(1, instances.size()); + + env.createFlatInstance(); + instances = snapshot.instances(); + assertEquals(1, instances.size()); + } + + var inst = snapshot.instances().iterator().next(); + + assertEquals(snapshot, inst.server(), "Instance must have access to the server snapshot"); + + assertEquals(0, inst.time()); + assertEquals(0, inst.worldAge()); + + assertEquals(0, inst.chunks().size()); + assertEquals(0, inst.entities().size()); + } +}