Skip to content

Commit

Permalink
Fixing worlds not cleaning up between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGuardsman committed Jan 2, 2020
1 parent b2fc0f1 commit 5d54c95
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.builtbroken.mc.testing.junit.world.FakeWorldServer;
import net.minecraft.init.Bootstrap;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.DimensionManager;
import org.junit.jupiter.api.Assertions;

/**
Expand Down Expand Up @@ -72,7 +73,8 @@ public void cleanupBetweenTests()

if (world != null)
{
clearCenterChunk();
DimensionManager.setWorld(0, null, getServer());
world = null;
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/test/java/com/builtbroken/tests/example/TestSpawning.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.builtbroken.tests.example;

import com.builtbroken.mc.testing.junit.TestManager;
import net.minecraft.entity.passive.EntityBat;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.world.World;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* Created by Dark(DarkGuardsman, Robert) on 1/2/2020.
*/
public class TestSpawning
{
private static TestManager testManager = new TestManager("spawning");

@AfterEach
void afterEach() {
testManager.cleanupBetweenTests();
}

@Test
void spawnBat() {
final World world = testManager.getWorld();

//Create bat
final EntityBat bat = new EntityBat(world);
bat.forceSpawn = true;
bat.setPosition(100, 10, 100);

//Spawn bat, returns true if spawned
Assertions.assertTrue(world.spawnEntity(bat));

//Check that bat was added to the world
Assertions.assertTrue(world.loadedEntityList.contains(bat));
Assertions.assertEquals(1, world.loadedEntityList.size());
}

@Test
void spawnSheep() {
final World world = testManager.getWorld();

//Create bat
final EntitySheep sheep = new EntitySheep(world);
sheep.forceSpawn = true;
sheep.setPosition(100, 10, 100);

//Spawn bat, returns true if spawned
Assertions.assertTrue(world.spawnEntity(sheep));

//Check that bat was added to the world
Assertions.assertTrue(world.loadedEntityList.contains(sheep));
Assertions.assertEquals(1, world.loadedEntityList.size());
}
}

0 comments on commit 5d54c95

Please sign in to comment.