test: Added some more tests

This commit is contained in:
Jakub Žitník 2025-03-02 21:17:11 +01:00
parent fed35d3a02
commit bb4e7423e3
Signed by: jzitnik
GPG Key ID: C577A802A6AF4EF3
12 changed files with 100 additions and 17 deletions

View File

@ -51,6 +51,12 @@
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.18.2</version> <version>2.18.2</version>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -8,7 +8,7 @@ import org.reflections.Reflections;
import java.util.*; import java.util.*;
public class CraftingRecipeList { public class CraftingRecipeList {
private static final List<CraftingRecipe> recipes = new ArrayList<>(); public static final List<CraftingRecipe> recipes = new ArrayList<>();
static { static {
registerRecipes(); registerRecipes();

View File

@ -6,7 +6,7 @@ import cz.jzitnik.game.entities.items.Item;
import cz.jzitnik.game.entities.items.ItemType; import cz.jzitnik.game.entities.items.ItemType;
import cz.jzitnik.game.entities.items.ToolVariant; import cz.jzitnik.game.entities.items.ToolVariant;
@ItemRegistry("wooden_pickaxe") @ItemRegistry("iron_pickaxe")
public class IronPickaxe extends Item { public class IronPickaxe extends Item {
public IronPickaxe() { public IronPickaxe() {
super("iron_pickaxe", "Iron pickaxe", ItemType.PICKAXE, SpriteLoader.SPRITES.IRON_PICKAXE, ToolVariant.IRON, 13.5, 250, false); super("iron_pickaxe", "Iron pickaxe", ItemType.PICKAXE, SpriteLoader.SPRITES.IRON_PICKAXE, ToolVariant.IRON, 13.5, 250, false);

View File

@ -7,7 +7,7 @@ import cz.jzitnik.game.annotations.EntityHurtAnimationHandler;
import org.reflections.Reflections; import org.reflections.Reflections;
public class EntityHurtAnimation { public class EntityHurtAnimation {
private final HashMap<String, EntityHurtAnimationChanger> handlerList = new HashMap<>(); public final HashMap<String, EntityHurtAnimationChanger> handlerList = new HashMap<>();
public EntityHurtAnimation() { public EntityHurtAnimation() {
registerHandlers(); registerHandlers();

View File

@ -7,7 +7,7 @@ import cz.jzitnik.game.annotations.EntityKillHandler;
import org.reflections.Reflections; import org.reflections.Reflections;
public class EntityKill { public class EntityKill {
private final HashMap<String, EntityKillInterface> handlerList = new HashMap<>(); public final HashMap<String, EntityKillInterface> handlerList = new HashMap<>();
public EntityKill() { public EntityKill() {
registerHandlers(); registerHandlers();

View File

@ -14,7 +14,7 @@ import org.reflections.Reflections;
public class EntityLogicProvider { public class EntityLogicProvider {
private static final int CHUNK_SIZE = 20; private static final int CHUNK_SIZE = 20;
private final HashMap<String, EntityLogicInterface> logicList = new HashMap<>(); public final HashMap<String, EntityLogicInterface> logicList = new HashMap<>();
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter

View File

@ -15,15 +15,6 @@ import org.reflections.Reflections;
public class EntitySpawnProvider { public class EntitySpawnProvider {
private final List<EntitySpawnInterface> spawnList = new ArrayList<>(); private final List<EntitySpawnInterface> spawnList = new ArrayList<>();
@AllArgsConstructor
@Getter
public static class EntityLogicMobDTO {
private Game game;
private Block mob;
private int x;
private int y;
}
public void update(Game game, Terminal terminal) { public void update(Game game, Terminal terminal) {
int[] playerLocation = game.getPlayerCords(); int[] playerLocation = game.getPlayerCords();
int playerX = playerLocation[0]; int playerX = playerLocation[0];

View File

@ -0,0 +1,30 @@
package cz.jzitnik.game.crafting;
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;
class CraftingRecipeListTest {
@Test
@DisplayName("Verify that all items in the crafting recipe list are actual items")
void verifyAllItems() {
for (CraftingRecipe craftingRecipe : CraftingRecipeList.recipes) {
if (!craftingRecipe.isUsingRegex()) {
for (String[] arr : craftingRecipe.getRecipe()) {
for (String item : arr) {
if (item == null ) {
continue;
}
assertDoesNotThrow(() -> ItemBlockSupplier.getItem(item), "Item " + item + " does not exist but is present as source in crafting recipe list.");
}
}
}
assertDoesNotThrow(craftingRecipe.getItemSupplier()::get, "Output item does not exist for recipe: " + Arrays.deepToString(craftingRecipe.getRecipe()) + ".");
}
}
}

View File

@ -0,0 +1,18 @@
package cz.jzitnik.game.mobs;
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class EntityHurtAnimationTest {
@Test
@DisplayName("Test that entities exists for all entity spawn handlers")
void allEntitiesExists() {
EntityHurtAnimation entityHurtAnimation = new EntityHurtAnimation();
for (String entity : entityHurtAnimation.handlerList.keySet()) {
assertDoesNotThrow(() -> ItemBlockSupplier.getEntity(entity), "Entity " + entity + " does not exist but has hurt animation implemented.");
}
}
}

View File

@ -0,0 +1,18 @@
package cz.jzitnik.game.mobs;
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class EntityKillTest {
@Test
@DisplayName("Test that entities exists for all entity spawn handlers")
void allEntitiesExists() {
EntityKill entityKill = new EntityKill();
for (String entity : entityKill.handlerList.keySet()) {
assertDoesNotThrow(() -> ItemBlockSupplier.getEntity(entity), "Entity " + entity + " does not exist but has a kill implemented.");
}
}
}

View File

@ -0,0 +1,17 @@
package cz.jzitnik.game.mobs;
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class EntityLogicProviderTest {
@Test
@DisplayName("Test that entities exists for all entity spawn handlers")
void allEntitiesExists() {
EntityLogicProvider entityLogicProvider = new EntityLogicProvider();
for (String entity : entityLogicProvider.logicList.keySet()) {
assertDoesNotThrow(() -> ItemBlockSupplier.getEntity(entity), "Entity " + entity + " does not exist but has a logic implemented.");
}
}
}

View File

@ -4,7 +4,6 @@ import cz.jzitnik.game.entities.items.Item;
import cz.jzitnik.game.entities.items.ItemBlockSupplier; import cz.jzitnik.game.entities.items.ItemBlockSupplier;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -15,11 +14,15 @@ public class SmeltingTest {
@DisplayName("Verity that all items in Smelting are actual items") @DisplayName("Verity that all items in Smelting are actual items")
void testAllItems() { void testAllItems() {
for (String item : Smelting.smeltingList.keySet()) { for (String item : Smelting.smeltingList.keySet()) {
assertDoesNotThrow(() -> ItemBlockSupplier.getItem(item)); assertDoesNotThrow(() -> ItemBlockSupplier.getItem(item), "Item " + item + "does not exist but is present as source in Smelting.");
} }
for (Supplier<Item> supplier: Smelting.smeltingList.values()) { for (Supplier<Item> supplier: Smelting.smeltingList.values()) {
assertDoesNotThrow(supplier::get); assertDoesNotThrow(supplier::get, "Item does not exist but is present as result in Smelting.");
}
for (String fuel : Smelting.fuelList.keySet()) {
assertDoesNotThrow(() -> ItemBlockSupplier.getItem(fuel), "Item " + fuel + "does not exist but is present as fuel in Smelting.");
} }
} }
} }