inventory_mock tests #17

Merged
erns6604 merged 16 commits from inventory_mocks into main 2025-10-30 07:52:55 +01:00
5 changed files with 28 additions and 5 deletions
Showing only changes of commit cbae93ee93 - Show all commits

View File

@@ -14,10 +14,6 @@ public record ItemStack(Item item, int quantity) {
return quantity;
}
public boolean isSingleItem() {
return quantity == 1;
}
public int getWeight() {
return item.getWeight() * quantity;
}

View File

@@ -42,6 +42,8 @@ public class LootTable<T> {
}
}
// Unreachable code. entries always have an entry or the class cant be instantiated.
// Cant put system into this state.
// only have a return here due to compiler requiring it.
return null;
}

View File

@@ -0,0 +1,15 @@
import Shared.LootTable;
import Terrain.Biome;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class BiomeTest {
@Test
void instantiates_with_name() {
var biome = Biome.COAST;
assertEquals("Coast", biome.getName());
}
}

View File

@@ -2,6 +2,8 @@ import Item.BasicItem;
import Item.ItemStack;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -19,9 +21,10 @@ public class ItemStackTest {
));
}
@Test
void can_be_created_with_positive_quantity() {
var i = new ItemStack(new BasicItem("id", "name", 5), 5);
assertEquals(5, i.getQuantity());
assertThat(i, instanceOf(ItemStack.class));
}
}

View File

@@ -34,6 +34,13 @@ class PlayerTest {
assertFalse(p.isAlive());
}
@Test
public void is_alive_if_has_health() {
var p = defaultPlayer();
p.setHealth(10);
assertTrue(p.isAlive());
}
@Test
void get_health_returns_health() {
var p = defaultPlayer();