Make dedicated snapshot test classes

This commit is contained in:
themode 2022-03-10 22:43:47 +01:00
parent 024ba736ce
commit d9e51beebb
3 changed files with 65 additions and 43 deletions

View File

@ -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));
}
}

View File

@ -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();

View File

@ -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());
}
}