Skip to content

Commit

Permalink
extract test setup to util function
Browse files Browse the repository at this point in the history
  • Loading branch information
CursedFlames committed Jan 21, 2024
1 parent c9a10d9 commit e9343b9
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.opencubicchunks.cubicchunks.test.misc;

import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.lang.reflect.Method;
Expand All @@ -12,9 +13,7 @@
import io.github.opencubicchunks.cubicchunks.world.level.chunklike.ImposterProtoClo;
import io.github.opencubicchunks.cubicchunks.world.level.chunklike.LevelClo;
import io.github.opencubicchunks.cubicchunks.world.level.chunklike.ProtoClo;
import net.minecraft.SharedConstants;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.Bootstrap;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ImposterProtoChunk;
Expand All @@ -29,9 +28,7 @@
public class TestInterfacesMatchVanillaClasses {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}

private static String stringifyMethod(Method method) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.opencubicchunks.cubicchunks.test.server;

import net.minecraft.SharedConstants;
import net.minecraft.server.Bootstrap;
import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
Expand All @@ -10,9 +10,7 @@
public class TestMinecraftServer {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}

@Test public void testSetInitialSpawnVanilla() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.opencubicchunks.cubicchunks.test.server.level;

import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -15,8 +16,6 @@
import io.github.opencubicchunks.cubicchunks.world.level.chunklike.CloPos;
import it.unimi.dsi.fastutil.longs.Long2ByteMap;
import it.unimi.dsi.fastutil.longs.Long2ByteOpenHashMap;
import net.minecraft.SharedConstants;
import net.minecraft.server.Bootstrap;
import net.minecraft.server.level.ChunkTracker;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -29,9 +28,7 @@
public class TestCubicChunkTracker {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}

static class TestCubicTracker extends ChunkTracker {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.opencubicchunks.cubicchunks.test.server.level;

import net.minecraft.SharedConstants;
import net.minecraft.server.Bootstrap;
import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;

Expand All @@ -13,8 +13,6 @@
public class TestCubicClientLevel {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.opencubicchunks.cubicchunks.test.server.level;

import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
Expand All @@ -16,10 +17,8 @@
import io.github.opencubicchunks.cubicchunks.server.level.CubicDistanceManager;
import io.github.opencubicchunks.cubicchunks.server.level.CubicTicketType;
import io.github.opencubicchunks.cubicchunks.world.level.chunklike.CloPos;
import net.minecraft.SharedConstants;
import net.minecraft.Util;
import net.minecraft.core.SectionPos;
import net.minecraft.server.Bootstrap;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.DistanceManager;
Expand All @@ -39,9 +38,7 @@
public class TestCubicDistanceManager {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}

static class TestDistanceManager extends DistanceManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@


import static io.github.opencubicchunks.cubicchunks.testutils.Misc.setupServerLevel;
import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.withSettings;

import io.github.opencubicchunks.cubicchunks.testutils.CloseableReference;
import net.minecraft.SharedConstants;
import net.minecraft.core.BlockPos;
import net.minecraft.server.Bootstrap;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.LevelChunk;
Expand All @@ -27,9 +26,7 @@
public class TestCubicServerLevel {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}

private void unregisterMocks() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.opencubicchunks.cubicchunks.test.server.level;

import net.minecraft.SharedConstants;
import net.minecraft.server.Bootstrap;
import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
Expand All @@ -14,9 +14,7 @@
public class TestCubicTaskPriorityQueueSorter {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}

@Disabled("This test is empty, since it is a mixin that is only affecting a debug method. We could test in the future if needed.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.github.opencubicchunks.cubicchunks.test.server.level;

import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;
import static org.junit.jupiter.api.Assertions.assertEquals;

import io.github.opencubicchunks.cubicchunks.MarkableAsCubic;
import io.github.opencubicchunks.cubicchunks.server.level.CubicTicketType;
import io.github.opencubicchunks.cubicchunks.server.level.CubicTickingTracker;
import io.github.opencubicchunks.cubicchunks.world.level.chunklike.CloPos;
import net.minecraft.SharedConstants;
import net.minecraft.server.Bootstrap;
import net.minecraft.server.level.TickingTracker;
import net.minecraft.world.level.ChunkPos;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -23,9 +22,7 @@
public class TestCubicTickingTracker {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}

private TickingTracker setupTracker() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.opencubicchunks.cubicchunks.test.server.level;

import net.minecraft.SharedConstants;
import net.minecraft.server.Bootstrap;
import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;

Expand All @@ -12,9 +12,7 @@
public class TestPlayerRespawnLogic {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}

// TODO: There are no tests here because the only way to test this is with integration tests.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.github.opencubicchunks.cubicchunks.test.server.level;

import static io.github.opencubicchunks.cubicchunks.testutils.Misc.setupServerLevel;
import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

import io.github.opencubicchunks.cubicchunks.testutils.CloseableReference;
import net.minecraft.SharedConstants;
import net.minecraft.server.Bootstrap;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -22,9 +21,7 @@
public class TestServerPlayer {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}

private ServerPlayer setupServerPlayer(ServerLevel serverLevel) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package io.github.opencubicchunks.cubicchunks.test.world.level;

import net.minecraft.SharedConstants;
import net.minecraft.server.Bootstrap;
import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class TestCubicLevel {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.opencubicchunks.cubicchunks.test.world.level.cube;

import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

Expand All @@ -11,10 +12,8 @@
import io.github.opencubicchunks.cc_core.utils.Coords;
import io.github.opencubicchunks.cubicchunks.world.level.chunklike.CloPos;
import io.github.opencubicchunks.cubicchunks.world.level.cube.CubeAccess;
import net.minecraft.SharedConstants;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.server.Bootstrap;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.LevelHeightAccessor;
import net.minecraft.world.level.biome.Biome;
Expand All @@ -40,9 +39,7 @@
public class TestCubeAccess {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}

static class CubeAccessTestImpl extends CubeAccess {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.opencubicchunks.cubicchunks.test.world.level.cube;

import static io.github.opencubicchunks.cubicchunks.testutils.Setup.setupTests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -18,9 +19,7 @@
import io.github.opencubicchunks.cc_core.api.CubicConstants;
import io.github.opencubicchunks.cubicchunks.world.level.chunklike.CloPos;
import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube;
import net.minecraft.SharedConstants;
import net.minecraft.core.BlockPos;
import net.minecraft.server.Bootstrap;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
Expand All @@ -34,9 +33,7 @@
public class TestLevelCube {
@BeforeAll
public static void setup() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
setupTests();
}

// TODO replaceWithPacketData - probably needs to be an integration test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.opencubicchunks.cubicchunks.testutils;

import net.minecraft.SharedConstants;
import net.minecraft.server.Bootstrap;

public class Setup {
public static void setupTests() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
SharedConstants.IS_RUNNING_IN_IDE = true;
}
}

0 comments on commit e9343b9

Please sign in to comment.