code-coverage-Emilia #24

Merged
erns6604 merged 14 commits from code-coverage-Emilia into main 2025-10-31 16:29:43 +01:00
3 changed files with 34 additions and 24 deletions
Showing only changes of commit bc48e37d7b - Show all commits

View File

@ -1,13 +0,0 @@
package Item;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.*;
class EquipmentTypeTest {
}

View File

@ -4,26 +4,37 @@ 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;
public class ItemStackTest {
@Test
void instantiated_with_no_quantity_throws_exception() {
assertThrows(IllegalArgumentException.class, () -> new ItemStack(
new BasicItem("id", "name", 5), 0
));
private ItemStack defaultStack() {
return new ItemStack(new BasicItem("id", "name", 5), 5);
}
private ItemStack stackNoQty() {
return new ItemStack(new BasicItem("id", "name", 5), 0);
}
@Test
void instantiated_with_negative_quantity_throws_exception() {
assertThrows(IllegalArgumentException.class, () -> new ItemStack(
new BasicItem("id", "name", 5), -4
));
void instantiated_with_no_quantity_throws_exception() {
assertThrows(IllegalArgumentException.class, this::stackNoQty);
}
@Test
void can_be_created_with_positive_quantity() {
var i = new ItemStack(new BasicItem("id", "name", 5), 5);
assertThat(i, instanceOf(ItemStack.class));
assertThat(defaultStack(), instanceOf(ItemStack.class));
}
@Test
void has_default_record_method_for_item() {
var i = defaultStack();
assertThat(i.item(), instanceOf(BasicItem.class));
}
@Test
void has_default_record_method_for_quantity() {
var i = defaultStack();
assertEquals(5, i.quantity());
}
}

View File

@ -42,4 +42,16 @@ public class LootTableTest {
assertThat(result, equalTo("Iron"));
}
@Test
void returns_null_if_broken_roll() {
LootTable<String> loot = new LootTable<>();
var mockRandomProvider = mock(RandomProvider.class);
when(mockRandomProvider.nextInt(anyInt())).thenReturn(Integer.MAX_VALUE);
loot.addEntry("Stone", 90);
loot.addEntry("Iron", 10);
loot.setRandomProvider(mockRandomProvider);
String result = loot.roll();
assertThat(result, is(nullValue()));
}
}