code-coverage-Emilia #24
@@ -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 {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,26 +4,37 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
public class ItemStackTest {
|
public class ItemStackTest {
|
||||||
@Test
|
private ItemStack defaultStack() {
|
||||||
void instantiated_with_no_quantity_throws_exception() {
|
return new ItemStack(new BasicItem("id", "name", 5), 5);
|
||||||
assertThrows(IllegalArgumentException.class, () -> new ItemStack(
|
}
|
||||||
new BasicItem("id", "name", 5), 0
|
|
||||||
));
|
private ItemStack stackNoQty() {
|
||||||
|
return new ItemStack(new BasicItem("id", "name", 5), 0);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
void instantiated_with_negative_quantity_throws_exception() {
|
void instantiated_with_no_quantity_throws_exception() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> new ItemStack(
|
assertThrows(IllegalArgumentException.class, this::stackNoQty);
|
||||||
new BasicItem("id", "name", 5), -4
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void can_be_created_with_positive_quantity() {
|
void can_be_created_with_positive_quantity() {
|
||||||
var i = new ItemStack(new BasicItem("id", "name", 5), 5);
|
assertThat(defaultStack(), instanceOf(ItemStack.class));
|
||||||
assertThat(i, 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,4 +42,16 @@ public class LootTableTest {
|
|||||||
assertThat(result, equalTo("Iron"));
|
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()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user